[llvm] [CorrelatedValuePropagation] Fold calls to UCMP/SCMP when we know that ranges of operands do not overlap (PR #97235)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 00:50:09 PDT 2024
================
@@ -548,6 +548,27 @@ static bool processAbsIntrinsic(IntrinsicInst *II, LazyValueInfo *LVI) {
return false;
}
+static bool processCmpIntrinsic(IntrinsicInst *II, LazyValueInfo *LVI) {
+ bool IsSigned = II->getIntrinsicID() == Intrinsic::scmp;
+ ConstantRange LHS_CR = LVI->getConstantRangeAtUse(II->getOperandUse(0),
+ /*UndefAllowed*/ false);
+ ConstantRange RHS_CR = LVI->getConstantRangeAtUse(II->getOperandUse(1),
+ /*UndefAllowed*/ false);
+
+ if (LHS_CR.icmp(IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT, RHS_CR)) {
+ II->replaceAllUsesWith(ConstantInt::get(II->getType(), 1));
+ II->eraseFromParent();
+ return true;
+ }
+ if (LHS_CR.icmp(IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, RHS_CR)) {
+ II->replaceAllUsesWith(ConstantInt::getSigned(II->getType(), -1));
+ II->eraseFromParent();
+ return true;
+ }
----------------
nikic wrote:
Should probably also handle the EQ case for completeness? This would mostly get handled by other case already, but it might come up if the range folds to a constant through some complex pathway, and doesn't really cost us anything to handle here.
https://github.com/llvm/llvm-project/pull/97235
More information about the llvm-commits
mailing list