[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:19 PST 2026


https://github.com/CarolineConcatto created https://github.com/llvm/llvm-project/pull/179721

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.

>From 0e2232a3c2f1391c11bd7a0a72c5a9aef0da662b Mon Sep 17 00:00:00 2001
From: CarolineConcatto <caroline.concatto at arm.com>
Date: Wed, 4 Feb 2026 10:20:12 +0000
Subject: [PATCH] [LLVM] Relax clobbering checks for calls to consider writes
 only

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.
---
 llvm/lib/Analysis/MemorySSA.cpp               |  2 +-
 .../test/Transforms/EarlyCSE/target-memory.ll | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Transforms/EarlyCSE/target-memory.ll

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)



More information about the llvm-commits mailing list