[llvm] [LAA] Compute pointer bounds for pattern with urem operation (PR #106574)

Sergey Kachkov via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 06:53:31 PDT 2024


================
@@ -190,6 +190,32 @@ RuntimeCheckingPtrGroup::RuntimeCheckingPtrGroup(
   Members.push_back(Index);
 }
 
+// Match expression in form of: PtrBase + (Dividend urem Divisor) * ConstStride,
+// where PtrBase and Divisor are loop-invariant and ConstStride is non-negative.
+// In this case Start = PtrBase, End = PtrBase + (Divisor - 1) * ConstStride.
+static std::optional<std::pair<const SCEV *, const SCEV *>>
+getStartAndEndForURemAccess(ScalarEvolution &SE, const SCEV *PtrScev,
+                            const Loop *L) {
+  const SCEV *PtrBase = SE.getPointerBase(PtrScev);
+  if (!SE.isLoopInvariant(PtrBase, L))
+    return std::nullopt;
+  const SCEV *PtrAddend = SE.removePointerBase(PtrScev);
+  auto ConstStride = SE.getConstantMultiple(PtrAddend);
+  if (ConstStride.isNegative())
----------------
skachkov-sc wrote:

Sure, I'll fix it (zero stride should be handled as loop-invariant case)

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


More information about the llvm-commits mailing list