[llvm-branch-commits] [llvm] [LoopInterchange] Identify unsafe instructions for interchange (PR #201402)
Nikita Popov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jun 3 12:07:30 PDT 2026
================
@@ -1472,25 +1472,28 @@ bool LoopInterchangeLegality::canInterchangeLoops(unsigned InnerLoopId,
}
// Check if outer and inner loop contain legal instructions only.
for (auto *BB : OuterLoop->blocks())
- for (Instruction &I : *BB)
- if (CallInst *CI = dyn_cast<CallInst>(&I)) {
- // Functions which don't access memory and don't diverge do not prevent
- // interchanging.
- if ((CI->doesNotAccessMemory() && !CI->mayHaveSideEffects()) ||
- isa<PseudoProbeInst>(CI))
- continue;
- LLVM_DEBUG(
- dbgs() << "Loops with call instructions cannot be interchanged "
- << "safely.");
- ORE->emit([&]() {
- return OptimizationRemarkMissed(DEBUG_TYPE, "CallInst",
- CI->getDebugLoc(),
- CI->getParent())
- << "Cannot interchange loops due to call instruction.";
- });
+ for (Instruction &I : *BB) {
+ // Loads and stores are checked separately, so we can skip them here.
+ if (isa<LoadInst, StoreInst, PseudoProbeInst>(&I))
+ continue;
- return false;
- }
+ // We cannot ignore potential memory reads, e.g., loads inside the called
+ // function.
+ if (!I.mayHaveSideEffects() && !I.mayReadFromMemory() && !I.isAtomic())
----------------
nikic wrote:
The isAtomic() check here is redundant, it's implied by the others.
https://github.com/llvm/llvm-project/pull/201402
More information about the llvm-branch-commits
mailing list