[llvm] [AA] Improve precision for monotonic atomic load/store operations (PR #158169)

Jin Huang via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 23 12:56:30 PDT 2025


================
@@ -21,3 +20,17 @@ define i32 @test9() {
   store i32 1, ptr @x
   ret i32 %x
 }
+
+; DSE across monotonic load (blocked if the atomic load's address isn't NoAlias)
+define i32 @test9a(ptr %ptr) {
----------------
jinhuang1102 wrote:

Hi @nikic, I think for DSE across monotonic store has already test by test10 in `atomic.ll`. 

Because the monotonic should not be eliminated so I might need to add a new test case 
```
; DSE doesn't remove monotonic store.
define void @test9b() {
; CHECK-LABEL: @test9b(
; CHECK-NEXT:    store atomic i32 2, ptr @x monotonic, align 4
; CHECK-NEXT:    store i32 1, ptr @x, align 4
; CHECK-NEXT:    ret void
;
  store atomic i32 2, ptr @x monotonic, align 4
  store i32 1, ptr @x
  ret void
}
``` 
as a good contrast to [@test4](https://github.com/llvm/llvm-project/blob/73c83bb84095c7adb602e6be8ce119db22e8f844/llvm/test/Transforms/DeadStoreElimination/atomic.ll#L30), which does eliminate the `unordered` store.

What do you think? Would this be a useful addition?

https://github.com/llvm/llvm-project/pull/158169


More information about the llvm-commits mailing list