[llvm] [LLVM] Relax clobbering checks for calls to consider writes only (PR #179721)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 4 10:16:56 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
@llvm/pr-subscribers-llvm-transforms
Author: None (CarolineConcatto)
<details>
<summary>Changes</summary>
Now that getModRefInfo for calls handles read and write effects by examining both calls, the clobbering query no longer needs to treat reads as clobbers. Update the check to consider writes only, aligning call handling with other instructions
I was not able to produce a test that exercises this change with the current setup. The change becomes relevant once target-specific memory locations are introduced, which is the motivation for adding the test.
---
Full diff: https://github.com/llvm/llvm-project/pull/179721.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/MemorySSA.cpp (+1-1)
- (added) llvm/test/Transforms/EarlyCSE/target-memory.ll (+22)
``````````diff
diff --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp
index 0b2e3fcfd76df..4f03080d9af67 100644
--- a/llvm/lib/Analysis/MemorySSA.cpp
+++ b/llvm/lib/Analysis/MemorySSA.cpp
@@ -312,7 +312,7 @@ instructionClobbersQuery(const MemoryDef *MD, const MemoryLocation &UseLoc,
if (auto *CB = dyn_cast_or_null<CallBase>(UseInst)) {
ModRefInfo I = AA.getModRefInfo(DefInst, CB);
- return isModOrRefSet(I);
+ return isModSet(I);
}
if (auto *DefLoad = dyn_cast<LoadInst>(DefInst))
diff --git a/llvm/test/Transforms/EarlyCSE/target-memory.ll b/llvm/test/Transforms/EarlyCSE/target-memory.ll
new file mode 100644
index 0000000000000..88a8db2ed26b5
--- /dev/null
+++ b/llvm/test/Transforms/EarlyCSE/target-memory.ll
@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes='early-cse<memssa>' < %s | FileCheck %s
+define void @foo(){
+; CHECK-LABEL: define void @foo() {
+; CHECK-NEXT: call void @fn_write_target1()
+; CHECK-NEXT: call void @fn_readwrite_target0_read_target1()
+; CHECK-NEXT: call void @fn_write_target1()
+; CHECK-NEXT: call void @fn_readwrite_target0_read_target1()
+; CHECK-NEXT: ret void
+;
+ call void @fn_write_target1()
+ call void @fn_readwrite_target0_read_target1()
+ call void @fn_write_target1()
+ call void @fn_readwrite_target0_read_target1()
+ ret void
+}
+
+declare void @fn_write_target1()
+ memory(target_mem1: write)
+
+declare void @fn_readwrite_target0_read_target1()
+ memory(target_mem0: readwrite, target_mem1: read)
``````````
</details>
https://github.com/llvm/llvm-project/pull/179721
More information about the llvm-commits
mailing list