From 5cbc7c4ae9d6849fd5e72af78ed62c06252ddaf0 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 20 Sep 2009 06:24:51 +0000 Subject: [PATCH] Teach the constant folder how to not a cmpinst. llvm-svn: 82378 --- lib/VMCore/ConstantFold.cpp | 14 ++++++++++++++ .../ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll | 6 ++++++ 2 files changed, 20 insertions(+) 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