diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-09-20 07:31:25 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-09-20 07:31:25 +0000 |
commit | 149cbc2a2418e506c71abe7759c9c81eea68976b (patch) | |
tree | 345b1810b674b10357557c479b166a520f62c28c /lib/VMCore | |
parent | b3c8547cb881edd84c2a052938dfb9d5d300a7ac (diff) | |
download | external_llvm-149cbc2a2418e506c71abe7759c9c81eea68976b.zip external_llvm-149cbc2a2418e506c71abe7759c9c81eea68976b.tar.gz external_llvm-149cbc2a2418e506c71abe7759c9c81eea68976b.tar.bz2 |
Peer through zext and sext to eliminate them when it is safe to do so.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82389 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index d9ef2c9..5411549 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -1665,6 +1665,22 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, } } + // If the left hand side is an extension, try eliminating it. + if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) { + if (CE1->getOpcode() == Instruction::SExt || + CE1->getOpcode() == Instruction::ZExt) { + Constant *CE1Op0 = CE1->getOperand(0); + Constant *CE1Inverse = ConstantExpr::getTrunc(CE1, CE1Op0->getType()); + if (CE1Inverse == CE1Op0) { + // Check whether we can safely truncate the right hand side. + Constant *C2Inverse = ConstantExpr::getTrunc(C2, CE1Op0->getType()); + if (ConstantExpr::getZExt(C2Inverse, C2->getType()) == C2) { + return ConstantExpr::getICmp(pred, CE1Inverse, C2Inverse); + } + } + } + } + if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) { // If C2 is a constant expr and C1 isn't, flip them around and fold the // other way if possible. |