Don't swap the operands if they're the same. Fixes the issue reported at https://reviews.llvm.org/D152541#4427017.