[llvm] [LAA] Only use inbounds/nusw in isNoWrap if the GEP is dereferenced. (PR #161445)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 14:43:03 PDT 2025


================
@@ -1021,9 +1024,22 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
   // the distance between the previously accessed location and the wrapped
   // location will be larger than half the pointer index type space. In that
   // case, the GEP would be  poison and any memory access dependent on it would
-  // be immediate UB when executed.
+  // be immediate UB when executed. The reasoning can only be applied if the
+  // pointer is dereferenced at least at the last iteration. For now, check if
+  // it is dereferenced in every iteration.
----------------
fhahn wrote:

Yes you are right, I adjusted the comment. (That kind of information gets a bit lost when we just look at the pointer AddRec, which gets incremented by `(1ULL << 62) + 1` in every iteration)

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


More information about the llvm-commits mailing list