[llvm] Reapply "[ValueTracking] Propagate sign information out of loop" (PR #182512)
Kshitij Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 21 02:21:27 PST 2026
================
@@ -5924,6 +5924,41 @@ 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)
+ break;
+ for (unsigned I = 0; I < 2; I++) {
+ Value *RecurValue = P->getIncomingValue(1 - I);
+ IntrinsicInst *II = dyn_cast<IntrinsicInst>(RecurValue);
+ if (!II)
+ continue;
+ Value *R, *L, *Init;
+ PHINode *PN;
+ const Function *F = II->getFunction();
+ const auto &FltSem = II->getType()->getScalarType()->getFltSemantics();
+ DenormalMode Mode =
+ F ? F->getDenormalMode(FltSem) : DenormalMode::getDynamic();
+ if (matchSimpleTernaryIntrinsicRecurrence(II, PN, Init, L, R)) {
+ switch (II->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, Mode);
----------------
kshitijvp wrote:
Done
https://github.com/llvm/llvm-project/pull/182512
More information about the llvm-commits
mailing list