[llvm] [IndVarSimplify] Allow predicateLoopExit on some loops with thread-local writes (PR #155901)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 23 01:18:55 PDT 2025
================
@@ -1704,6 +1709,27 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
return Changed;
}
+static bool crashingBBWithoutEffect(const BasicBlock &BB) {
+ return llvm::all_of(BB, [](const Instruction &I) {
+ // TODO: for now this is overly restrictive, to make sure nothing in this
+ // BB can depend on the loop body.
+ // It's not enough to check for !I.mayHaveSideEffects(), because e.g. a
+ // load does not have a side effect, but we could have
+ // %a = load ptr, ptr %ptr
+ // %b = load i32, ptr %a
+ // Now if the loop stored a non-nullptr to %a, we could cause a nullptr
+ // dereference by skipping over loop iterations.
+ if (const auto *CB = dyn_cast<CallBase>(&I)) {
+ if (CB->onlyAccessesInaccessibleMemory() &&
+ llvm::all_of(CB->args(), [](const llvm::Use &U) {
+ return isa<Constant>(U.get());
----------------
nikic wrote:
Why do we care about constant arguments?
https://github.com/llvm/llvm-project/pull/155901
More information about the llvm-commits
mailing list