[llvm] [BasicAA] Add Vscale GEP decomposition on variable index (PR #69152)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 07:13:32 PST 2024


================
@@ -663,22 +664,56 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL,
       unsigned Width = Index->getType()->getIntegerBitWidth();
       unsigned SExtBits = IndexSize > Width ? IndexSize - Width : 0;
       unsigned TruncBits = IndexSize < Width ? Width - IndexSize : 0;
-      LinearExpression LE = GetLinearExpression(
-          CastedValue(Index, 0, SExtBits, TruncBits), DL, 0, AC, DT);
+      // Scalable GEP decomposition
+      // Allow Scalable GEP to be decomposed in the case of
+      //    1. getelementptr <4 x vscale x i32> with 1st index as a constant
+      //    2. Index which have a leaf of @llvm.vscale
+      // In both cases, essentially CastedValue of VariableGEPIndex is Vscale,
+      // however in the 1st case, CastedValue is of type constant, hence another
+      // flag in VariableGEPIndex is created in this case, IsVScale If GEP is
+      // Scalable type, e.g. <4 x vscale x i32>, the first index will have
+      // vscale as a variable index, create a LE in this case.
----------------
nikic wrote:

So it sounds like you are interested in modelling `vscale * scale` offsets, but not `vscale * scale * var`. If IsVScale is set, then the variable is just ignored, is that correct?

If so, then an alternative way to model this is to use some kind of sentinel value (say `reinterpret_cast<Value*>(-1)`) as the variable, which will get interpreted as vscale. Then, we should be able to reuse the existing code, with some adjustments to e.g. make the range calculation for the value use the vscale range, etc.

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


More information about the llvm-commits mailing list