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

Vedant Paranjape via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 14 09:30:35 PST 2026


================
@@ -5956,7 +5953,25 @@ 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 propogate sign information out of such loops.
+    if (P->getNumIncomingValues() == 2) {
+      Value *Start = P->getIncomingValue(0);
+      Value *RecurValue = P->getIncomingValue(1);
+      Value *X;
+      if (match(RecurValue, m_Intrinsic<Intrinsic::fmuladd>(
+                                m_Value(X), m_Value(X), m_Specific(P)))) {
----------------
VedantParanjape wrote:

> However it too says / / Binary intrinsics only supported for now.

Yes, it won't work with fma/fmuladd. Can you extend `matchSimpleBinaryIntrinsicRecurrence` for ternary operators?

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


More information about the llvm-commits mailing list