From: Nick Lewycky Date: Sun, 20 Sep 2009 06:24:51 +0000 (+0000) Subject: Teach the constant folder how to not a cmpinst. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3105ebfaf7105ffe20530a70194fa8d85d07fb7c;p=oota-llvm.git Teach the constant folder how to not a cmpinst. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82378 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 3f5c7efbb9a..1cf7b290c1e 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -704,6 +704,20 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, break; case Instruction::Xor: if (CI2->equalsInt(0)) return C1; // X ^ 0 == X + + if (ConstantExpr *CE1 = dyn_cast(C1)) { + switch (CE1->getOpcode()) { + default: break; + case Instruction::ICmp: + case Instruction::FCmp: + // icmp pred ^ true -> icmp !pred + assert(CI2->equalsInt(1)); + CmpInst::Predicate pred = (CmpInst::Predicate)CE1->getPredicate(); + pred = CmpInst::getInversePredicate(pred); + return ConstantExpr::getCompare(pred, CE1->getOperand(0), + CE1->getOperand(1)); + } + } break; case Instruction::AShr: // ashr (zext C to Ty), C2 -> lshr (zext C, CSA), C2 diff --git a/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll b/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll index 0a40c0ce2c4..66a3a85b3ce 100644 --- a/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll +++ b/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll @@ -28,3 +28,9 @@ global i1 icmp ule (i32* bitcast (i8* @X to i32*), i32* bitcast (i8* @Y to i32*) ; CHECK-NOT: bitcast ; CHECK: icmp +global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 false) +; CHECK-NOT: false +; CHECK: icmp +global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 true) +; CHECK-NOT: true +; CHECK: icmp