[llvm] [LSR] Recognize vscale-relative immediates (PR #88124)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 09:08:39 PDT 2024


================
@@ -3931,21 +4082,26 @@ void LSRInstance::GenerateConstantOffsetsImpl(
         int64_t Step = StepInt.isNegative() ?
           StepInt.getSExtValue() : StepInt.getZExtValue();
 
-        for (int64_t Offset : Worklist) {
-          Offset -= Step;
-          GenerateOffset(G, Offset);
+        for (Immediate Offset : Worklist) {
+          if (!Offset.isScalable()) {
+            Offset = Immediate::getFixed(Offset.getFixedValue() - Step);
+            GenerateOffset(G, Offset);
+          }
         }
       }
     }
   }
-  for (int64_t Offset : Worklist)
+  for (Immediate Offset : Worklist)
     GenerateOffset(G, Offset);
 
-  int64_t Imm = ExtractImmediate(G, SE);
-  if (G->isZero() || Imm == 0)
+  Immediate Imm = ExtractImmediate(G, SE);
+  if (G->isZero() || Imm.isZero() ||
+      Base.BaseOffset.isScalable() != Imm.isScalable())
     return;
   Formula F = Base;
-  F.BaseOffset = (uint64_t)F.BaseOffset + Imm;
+  F.BaseOffset = Immediate::get((uint64_t)F.BaseOffset.getKnownMinValue() +
+                                    Imm.getKnownMinValue(),
+                                Imm.isScalable());
----------------
paulwalker-arm wrote:

Assuming the cast is important, what about implementing something like `Immediate::AddToUnsigned(Immediate&)`?  I'd sooner something explicit that works for both fixed and scalable rather than continually pulling apart the `Immediate` type.

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


More information about the llvm-commits mailing list