[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
Sun Oct 26 19:53:33 PDT 2025
================
@@ -1023,8 +1027,22 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
// case, the GEP would be poison and any memory access dependent on it would
// be immediate UB when executed.
if (auto *GEP = dyn_cast_if_present<GetElementPtrInst>(Ptr);
- GEP && GEP->hasNoUnsignedSignedWrap())
- return true;
+ GEP && GEP->hasNoUnsignedSignedWrap()) {
+ // For the above reasoning to apply, the pointer must be dereferenced in
+ // every iteration.
+ if (L->getHeader() == L->getLoopLatch() ||
+ any_of(GEP->users(), [L, DT](User *U) {
+ if (!isa<LoadInst, StoreInst>(U))
+ return false;
----------------
fhahn wrote:
Yep we should always have at least a memory access here. There might be other users which could improve results, but I didn't find any cases in practice where this triggers, so I left it out of the initial patch.
https://github.com/llvm/llvm-project/pull/161445
More information about the llvm-commits
mailing list