Fold 'icmp eq (icmp), true' into an xor(icmp).
[oota-llvm.git] / lib / VMCore / ConstantFold.cpp
index e14dd7e9cff97809d90886ea2b23fbca88d329d5..d9ef2c95e764fa5c910145d0e55164ce8b2fcecd 100644 (file)
@@ -1428,6 +1428,20 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
       }
   }
 
+  // If the comparison is a comparison between two i1's, simplify it.
+  if (C1->getType() == Type::getInt1Ty(Context)) {
+    switch(pred) {
+    case ICmpInst::ICMP_EQ:
+      if (isa<ConstantInt>(C2))
+        return ConstantExpr::getXor(C1, ConstantExpr::getNot(C2));
+      return ConstantExpr::getXor(ConstantExpr::getNot(C1), C2);
+    case ICmpInst::ICMP_NE:
+      return ConstantExpr::getXor(C1, C2);
+    default:
+      break;
+    }
+  }
+
   if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
     APInt V1 = cast<ConstantInt>(C1)->getValue();
     APInt V2 = cast<ConstantInt>(C2)->getValue();