From: Sanjay Patel Date: Tue, 20 Aug 2019 17:03:22 +0000 (+0000) Subject: [InstCombine] make fold for icmp with sext more efficient; NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f066c9f7311d8d0b0579c13adc657f8945042f4e;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369411 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 06c2469dfd8..dc6dcc36061 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/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(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) {