- Exposed SetCondInst::getInverseCondition & ::getSwappedCondition better


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3562 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/VMCore/iOperators.cpp b/lib/VMCore/iOperators.cpp
index ba5aca1..c7d757e 100644
--- a/lib/VMCore/iOperators.cpp
+++ b/lib/VMCore/iOperators.cpp
@@ -87,18 +87,17 @@
 // order dependant (SetLT f.e.) the opcode is changed.
 //
 bool BinaryOperator::swapOperands() {
+  if (SetCondInst *SCI = dyn_cast<SetCondInst>(this)) {
+    iType = SCI->getSwappedCondition();
+    std::swap(Operands[0], Operands[1]);
+    return false;
+  }
+
   switch (getOpcode()) {
     // Instructions that don't need opcode modification
   case Add: case Mul:
   case And: case Xor:
   case Or:
-  case SetEQ: case SetNE:
-    break;
-    // Instructions that need opcode modification
-  case SetGT: iType = SetLT; break;
-  case SetLT: iType = SetGT; break;
-  case SetGE: iType = SetLE; break;
-  case SetLE: iType = SetGE; break;
     // Error on the side of caution
   default:
     return true;
@@ -126,8 +125,8 @@
 // getInverseCondition - Return the inverse of the current condition opcode.
 // For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
 //
-Instruction::BinaryOps SetCondInst::getInverseCondition() const {
-  switch (getOpcode()) {
+Instruction::BinaryOps SetCondInst::getInverseCondition(BinaryOps Opcode) {
+  switch (Opcode) {
   default:
     assert(0 && "Unknown setcc opcode!");
   case SetEQ: return SetNE;
@@ -138,3 +137,18 @@
   case SetLE: return SetGT;
   }
 }
+
+// getSwappedCondition - Return the condition opcode that would be the result
+// of exchanging the two operands of the setcc instruction without changing
+// the result produced.  Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
+//
+Instruction::BinaryOps SetCondInst::getSwappedCondition(BinaryOps Opcode) {
+  switch (Opcode) {
+  default: assert(0 && "Unknown setcc instruction!");
+  case SetEQ: case SetNE: return Opcode;
+  case SetGT: return SetLT;
+  case SetLT: return SetGT;
+  case SetGE: return SetLE;
+  case SetLE: return SetGE;
+  }
+}