Skip to content

Conversation

@topperc
Copy link
Collaborator

@topperc topperc commented Dec 11, 2025

onlyAccessesInaccessibleMemory can't alias with a load. This allows us to ignore more intrinsics than llvm.assume.

Follow up from #171547

@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Craig Topper (topperc)

Changes

onlyAccessesInaccessibleMemory can't alias with a load. This allows us to ignore more intrinsics than llvm.assume.

Follow up from #171547


Full diff: https://github.com/llvm/llvm-project/pull/171910.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/LoopPeel.cpp (+3-3)
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index 635b90020f625..960ec9d4c7d6e 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -447,10 +447,10 @@ static unsigned peelToTurnInvariantLoadsDereferenceable(Loop &L,
   const DataLayout &DL = L.getHeader()->getDataLayout();
   for (BasicBlock *BB : L.blocks()) {
     for (Instruction &I : *BB) {
-      // Don't consider llvm.assume as writing to memory.
+      // Calls that only access inaccessible memory can never alias with loads.
       if (I.mayWriteToMemory() &&
-          !(isa<IntrinsicInst>(I) &&
-            cast<IntrinsicInst>(I).getIntrinsicID() == Intrinsic::assume))
+          !(isa<CallBase>(I) &&
+            cast<CallBase>(I).onlyAccessesInaccessibleMemory()))
         return 0;
 
       if (LoadUsers.contains(&I))

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

Can you add a test with a different call that is supported now?

@topperc
Copy link
Collaborator Author

topperc commented Dec 11, 2025

LGTM, thanks.

Can you add a test with a different call that is supported now?

Sure. Do you have a good suggestion?

…ssume in peelToTurnInvariantLoadsDereferenceable.

onlyAccessesInaccessibleMemory can't alias with a load. This
allows us to ignore more intrinsics than llvm.assume.

Follow up from llvm#171547
@topperc topperc force-pushed the pr/looppeel-follow-up branch from 039e8fa to 9b4fa08 Compare December 12, 2025 02:44
@topperc
Copy link
Collaborator Author

topperc commented Dec 12, 2025

LGTM, thanks.
Can you add a test with a different call that is supported now?

Sure. Do you have a good suggestion?

I used llvm.sideeffect.

@topperc topperc merged commit ef21740 into llvm:main Dec 12, 2025
10 checks passed
@topperc topperc deleted the pr/looppeel-follow-up branch December 12, 2025 18:45
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 12, 2025

LLVM Buildbot has detected a new failure on builder ppc64le-mlir-rhel-clang running on ppc64le-mlir-rhel-test while building llvm at step 6 "test-build-check-mlir-build-only-check-mlir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/34928

Here is the relevant piece of the build log for the reference
Step 6 (test-build-check-mlir-build-only-check-mlir) failure: 1200 seconds without output running [b'ninja', b'check-mlir'], attempting to kill
...
PASS: MLIR :: mlir-tblgen/op-decl-and-defs.td (3747 of 3758)
PASS: MLIR-Unit :: Interfaces/./MLIRInterfacesTests/13/22 (3748 of 3758)
PASS: MLIR :: mlir-tblgen/llvm-intrinsics.td (3749 of 3758)
PASS: MLIR :: mlir-translate/split-markers.mlir (3750 of 3758)
PASS: MLIR :: mlir-reduce/dce-test.mlir (3751 of 3758)
PASS: MLIR :: Pass/pipeline-parsing.mlir (3752 of 3758)
PASS: MLIR :: mlir-tblgen/cpp-class-comments.td (3753 of 3758)
PASS: MLIR :: mlir-runner/simple.mlir (3754 of 3758)
PASS: MLIR :: Pass/pipeline-options-parsing.mlir (3755 of 3758)
PASS: MLIR :: mlir-tblgen/op-error.td (3756 of 3758)
command timed out: 1200 seconds without output running [b'ninja', b'check-mlir'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1921.823751

anonymouspc pushed a commit to anonymouspc/llvm that referenced this pull request Dec 15, 2025
…ssume in peelToTurnInvariantLoadsDereferenceable. (llvm#171910)

onlyAccessesInaccessibleMemory can't alias with a load. This allows us
to ignore more intrinsics than llvm.assume.

Follow up from llvm#171547
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants