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

Vedant Paranjape via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 16 12:48:55 PST 2026


================
@@ -5964,7 +5953,32 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
     // Unreachable blocks may have zero-operand PHI nodes.
     if (P->getNumIncomingValues() == 0)
       break;
-
+    // 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() && R == L) {
----------------
VedantParanjape wrote:

```suggestion
          if (KnownStart.cannotBeOrderedLessThanZero() && L == R) {
```

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


More information about the llvm-commits mailing list