diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2019-08-20 17:03:22 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2019-08-20 17:03:22 +0000 |
| commit | 2e68e4d60e9f190c83653d5df5071262febca2ef (patch) | |
| tree | f1e84cb9c83eee7ba192027c0a2c03885cfe960b | |
| parent | 22ac9f396fcadcea546eaff38954932c1818e4f1 (diff) | |
| download | bcm5719-llvm-2e68e4d60e9f190c83653d5df5071262febca2ef.tar.gz bcm5719-llvm-2e68e4d60e9f190c83653d5df5071262febca2ef.zip | |
[InstCombine] make fold for icmp with sext more efficient; NFC
We were creating 2 instructions and relying on a subsequent fold
to invert a not(icmp). Create the final icmp directly instead.
llvm-svn: 369411
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 06c2469dfd8..dc6dcc36061 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -4128,27 +4128,21 @@ Instruction *InstCombiner::foldICmpWithCastOp(ICmpInst &ICmp) { // The re-extended constant changed, partly changed (in the case of a vector), // or could not be determined to be equal (in the case of a constant // expression), so the constant cannot be represented in the shorter type. - // Consequently, we cannot emit a simple comparison. // All the cases that fold to true or false will have already been handled // by SimplifyICmpInst, so only deal with the tricky case. - if (isSignedCmp || !isSignedExt || !isa<ConstantInt>(C)) return nullptr; - // Evaluate the comparison for LT (we invert for GT below). LE and GE cases - // should have been folded away previously and not enter in here. - - // We're performing an unsigned comp with a sign extended value. - // This is true if the input is >= 0. [aka >s -1] - Constant *NegOne = Constant::getAllOnesValue(SrcTy); - Value *Result = Builder.CreateICmpSGT(Op0Src, NegOne, ICmp.getName()); - - // Finally, return the value computed. + // Is source op positive? + // icmp ult (sext X), C --> icmp sgt X, -1 if (ICmp.getPredicate() == ICmpInst::ICMP_ULT) - return replaceInstUsesWith(ICmp, Result); + return new ICmpInst(CmpInst::ICMP_SGT, Op0Src, + Constant::getAllOnesValue(SrcTy)); + // Is source op negative? + // icmp ugt (sext X), C --> icmp slt X, 0 assert(ICmp.getPredicate() == ICmpInst::ICMP_UGT && "ICmp should be folded!"); - return BinaryOperator::CreateNot(Result); + return new ICmpInst(CmpInst::ICMP_SLT, Op0Src, Constant::getNullValue(SrcTy)); } static bool isNeutralValue(Instruction::BinaryOps BinaryOp, Value *RHS) { |

