diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-09-20 07:21:39 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-09-20 07:21:39 +0000 |
commit | 85958b059dcc4c1e91bb892d6cfe5987109a60ac (patch) | |
tree | 35cb5e98629e40e58154f7e53a9163d49d435add | |
parent | e895c6151589c1b7f6ac9ca992b76106fa197a37 (diff) | |
download | external_llvm-85958b059dcc4c1e91bb892d6cfe5987109a60ac.zip external_llvm-85958b059dcc4c1e91bb892d6cfe5987109a60ac.tar.gz external_llvm-85958b059dcc4c1e91bb892d6cfe5987109a60ac.tar.bz2 |
Fold 'icmp eq (icmp), true' into an xor(icmp).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82386 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 14 | ||||
-rw-r--r-- | test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll | 9 |
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index e14dd7e..d9ef2c9 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -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(); 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 2dab293..4cf1320 100644 --- a/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll +++ b/test/Transforms/ConstProp/2009-09-19-ConstFold-i1-ConstExpr.ll @@ -27,3 +27,12 @@ ; CHECK: @I = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0] @J = global i1 xor (i1 icmp ult (i8* @X, i8* @Y), i1 true) ; CHECK: @J = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0] + +@K = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 false) +; CHECK: @K = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0] +@L = global i1 icmp eq (i1 icmp ult (i8* @X, i8* @Y), i1 true) +; CHECK: @L = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0] +@M = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 true) +; CHECK: @M = global i1 icmp uge (i8* @X, i8* @Y) ; <i1*> [#uses=0] +@N = global i1 icmp ne (i1 icmp ult (i8* @X, i8* @Y), i1 false) +; CHECK: @N = global i1 icmp ult (i8* @X, i8* @Y) ; <i1*> [#uses=0] |