[llvm] [LSR] Remove unnecessary WidestFixupType (NFC) (PR #185013)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 06:47:23 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: John Brawn (john-brawn-arm)

<details>
<summary>Changes</summary>

The purpose of WidestFixupType is to prevent FindUseWithSimilarFormula from matching a formula with different widest fixup type, but this never happens:
 * FindUseWithSimilarFormula is only called by NarrowSearchSpaceByCollapsingUnrolledCode
 * That function only considers Address and ICmpZero kinds, as they're the only ones that allow a nonzero BaseOffset
 * In an Address use all fixups have pointer type
 * FindUseWithSimilarFormula already excludes ICmpZero uses

---
Full diff: https://github.com/llvm/llvm-project/pull/185013.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp (+9-19) 


``````````diff
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 839942fac6716..4d65b2e7f8c0a 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1326,12 +1326,6 @@ class LSRUse {
   /// changing the formula.
   bool RigidFormula = false;
 
-  /// This records the widest use type for any fixup using this
-  /// LSRUse. FindUseWithSimilarFormula can't consider uses with different max
-  /// fixup widths to be equivalent, because the narrower one may be relying on
-  /// the implicit truncation to truncate away bogus bits.
-  Type *WidestFixupType = nullptr;
-
   /// A list of ways to build a value that can satisfy this user.  After the
   /// list is populated, one of these is selected heuristically and used to
   /// formulate a replacement for OperandValToReplace in UserInst.
@@ -1792,9 +1786,6 @@ void LSRUse::print(raw_ostream &OS) const {
 
   if (AllFixupsUnconditional)
     OS << ", all-fixups-unconditional";
-
-  if (WidestFixupType)
-    OS << ", widest fixup type: " << *WidestFixupType;
 }
 
 LLVM_DUMP_METHOD void LSRUse::dump() const {
@@ -2872,7 +2863,6 @@ LSRInstance::FindUseWithSimilarFormula(const Formula &OrigF,
     if (&LU != &OrigLU &&
         LU.Kind != LSRUse::ICmpZero &&
         LU.Kind == OrigLU.Kind && OrigLU.AccessTy == LU.AccessTy &&
-        LU.WidestFixupType == OrigLU.WidestFixupType &&
         LU.HasFormulaWithSameRegs(OrigF)) {
       // Scan through this use's formulae.
       for (const Formula &F : LU.Formulae) {
@@ -3638,11 +3628,6 @@ void LSRInstance::CollectFixupsAndInitialFormulae() {
       VisitedLSRUse.insert(LUIdx);
     }
 
-    if (!LU.WidestFixupType ||
-        SE.getTypeSizeInBits(LU.WidestFixupType) <
-        SE.getTypeSizeInBits(LF.OperandValToReplace->getType()))
-      LU.WidestFixupType = LF.OperandValToReplace->getType();
-
     // If this is the first use of this LSRUse, give it a formula.
     if (LU.Formulae.empty()) {
       InsertInitialFormula(S, LU, LUIdx);
@@ -3833,10 +3818,6 @@ LSRInstance::CollectLoopInvariantFixupsAndFormulae() {
         LF.Offset = Offset;
         LU.AllFixupsOutsideLoop &= LF.isUseFullyOutsideLoop(L);
         LU.AllFixupsUnconditional &= IsFixupExecutedEachIncrement(LF);
-        if (!LU.WidestFixupType ||
-            SE.getTypeSizeInBits(LU.WidestFixupType) <
-            SE.getTypeSizeInBits(LF.OperandValToReplace->getType()))
-          LU.WidestFixupType = LF.OperandValToReplace->getType();
         InsertSupplementalFormula(US, LU, LUIdx);
         CountRegisters(LU.Formulae.back(), Uses.size() - 1);
         break;
@@ -4958,6 +4939,8 @@ void LSRInstance::NarrowSearchSpaceByCollapsingUnrolledCode() {
     for (const Formula &F : LU.Formulae) {
       if (F.BaseOffset.isZero() || (F.Scale != 0 && F.Scale != 1))
         continue;
+      assert((LU.Kind == LSRUse::Address || LU.Kind == LSRUse::ICmpZero) &&
+             "Only address and cmp uses expected to have nonzero BaseOffset");
 
       LSRUse *LUThatHas = FindUseWithSimilarFormula(F, LU);
       if (!LUThatHas)
@@ -4979,6 +4962,13 @@ void LSRInstance::NarrowSearchSpaceByCollapsingUnrolledCode() {
         LLVM_DEBUG(dbgs() << "New fixup has offset " << Fixup.Offset << '\n');
       }
 
+#ifndef NDEBUG
+      Type *FixupType = LUThatHas->Fixups[0].OperandValToReplace->getType();
+      for (LSRFixup &Fixup : LUThatHas->Fixups)
+        assert(Fixup.OperandValToReplace->getType() == FixupType &&
+               "Expected all fixups to have the same type");
+#endif
+
       // Delete formulae from the new use which are no longer legal.
       bool Any = false;
       for (size_t i = 0, e = LUThatHas->Formulae.size(); i != e; ++i) {

``````````

</details>


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


More information about the llvm-commits mailing list