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

Kshitij Paranjape via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 31 01:53:16 PST 2026


================
@@ -5954,6 +5954,37 @@ 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::fma:
+        case Intrinsic::fmuladd: {
+          KnownFPClass KnownStart, KnownL;
+          computeKnownFPClass(Init, DemandedElts, InterestedClasses, KnownStart,
+                              Q, Depth + 1);
+          if (KnownStart.isUnknown())
+            break;
+          computeKnownFPClass(L, DemandedElts, InterestedClasses, KnownL, Q,
+                              Depth + 1);
+          if (L == R &&
+              isGuaranteedNotToBeUndef(L, Q.AC, Q.CxtI, Q.DT, Depth + 1))
+            Known = KnownFPClass::fma_square(KnownL, KnownStart,
+                                             DenormalMode::getDynamic());
+          break;
----------------
kshitijvp wrote:

Done

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


More information about the llvm-commits mailing list