[llvm] [ValueTracking] Propagate sign information out of loop (PR #175590)

Kshitij Paranjape via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 27 09:47:04 PST 2026


================
@@ -6004,6 +5993,32 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
       }
     }
 
+    // Look for the case of a for loop which has a positive
+    // initial value and is incremented by a squared value.
+    // This will propagate sign information out of such loops.
+    if (P->getNumIncomingValues() == 2) {
+      Value *RecurValue = P->getIncomingValue(1);
+      IntrinsicInst *I = dyn_cast<IntrinsicInst>(RecurValue);
+      if (!I)
+        break;
+      Value *R, *L;
+      Value *Init;
+      PHINode *PN;
+      if (matchSimpleTernaryIntrinsicRecurrence(I, PN, Init, L, R)) {
+        switch (I->getIntrinsicID()) {
+        case Intrinsic::fmuladd: {
+          KnownFPClass KnownStart;
+          computeKnownFPClass(Init, DemandedElts,
+                              KnownFPClass::OrderedGreaterThanZeroMask,
+                              KnownStart, Q, Depth + 1);
+          if (KnownStart.cannotBeOrderedLessThanZero() && L == R &&
+              isGuaranteedNotToBeUndef(L, Q.AC, Q.CxtI, Q.DT, Depth + 1))
----------------
kshitijvp wrote:

@arsenm 

https://github.com/llvm/llvm-project/pull/175590


More information about the llvm-commits mailing list