[llvm] [ValueTracking] Compute known bits for `umin` and `umax` recurrences (PR #222890)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 05:49:55 PDT 2026
=?utf-8?q?Ömer_Sinan_Ağacan?= <omer at osa1.net>,
=?utf-8?q?Ömer_Sinan_Ağacan?= <omer at osa1.net>,
=?utf-8?q?Ömer_Sinan_Ağacan?= <omer at osa1.net>,
=?utf-8?q?Ömer_Sinan_Ağacan?= <omer at osa1.net>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/222890 at github.com>
================
@@ -1971,6 +1975,43 @@ static void computeKnownBitsFromOperator(const Operator *I,
default:
break;
}
+ } else {
+ IntrinsicInst *II = nullptr;
+ if (matchTwoInputRecurrence<IntrinsicInst>(P, II, Start, Step)) {
+ // %iv = [<Start>, %entry], [%iv.next, %backedge]
+ //
+ // %iv.next = <II>(%iv, <Step>)
+ // or
+ // %iv.next = <II>(<Step>, %iv)
+ Intrinsic::ID IntrinsicID = II->getIntrinsicID();
+ if (IntrinsicID == Intrinsic::umin || IntrinsicID == Intrinsic::umax) {
+ SimplifyQuery RecQ = Q.getWithoutCondContext();
+
+ unsigned OpNum = P->getOperand(0) == Start ? 0 : 1;
+ Instruction *StartInst = P->getIncomingBlock(OpNum)->getTerminator();
+ Instruction *StepInst =
+ P->getIncomingBlock(1 - OpNum)->getTerminator();
+
+ KnownBits KnownStart(BitWidth);
+ RecQ.CxtI = StartInst;
+ computeKnownBits(Start, DemandedElts, KnownStart, RecQ, Depth + 1);
+
+ KnownBits KnownStep(BitWidth);
+ RecQ.CxtI = StepInst;
+ computeKnownBits(Step, DemandedElts, KnownStep, RecQ, Depth + 1);
----------------
nikic wrote:
Might make sense to extract a common helper for this? https://github.com/osa1/llvm-project/blob/fdfb76285e8385bdaca6f802511b3e56f2b01950/llvm/lib/Analysis/ValueTracking.cpp#L1909-L1924 Or we can wait for the third copy...
https://github.com/llvm/llvm-project/pull/222890
More information about the llvm-commits
mailing list