[llvm] [DSE] Consider the aliasing through global variable while checking clobber (PR #120044)

Haopeng Liu via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 15:56:55 PST 2024


================
@@ -299,3 +321,23 @@ define i16 @large_p2_may_or_partial_alias_caller2(ptr %base1, ptr %base2) {
   ret i16 %l
 }
 
+ at g = global i16 123, align 2
+
+declare void @read_global(ptr nocapture noundef initializes((0, 2))) nounwind
+  memory(read, argmem: write, inaccessiblemem: none) nounwind
+
+define i16 @global_var_alias() {
+; CHECK-LABEL: @global_var_alias(
+; CHECK-NEXT:    store i16 0, ptr @g, align 4
+; CHECK-NEXT:    [[G_ADDR:%.*]] = getelementptr i8, ptr @g, i64 1
+; CHECK-NEXT:    call void @read_global(ptr [[G_ADDR]])
+; CHECK-NEXT:    [[L:%.*]] = load i16, ptr @g, align 2
+; CHECK-NEXT:    ret i16 [[L]]
+;
+  store i16 0, ptr @g, align 4
+  %g_addr = getelementptr i8, ptr @g, i64 1
+  call void @read_global(ptr %g_addr)
----------------
haopliu wrote:

Ooops, removed the GEP and directly read/write @g. Thanks.

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


More information about the llvm-commits mailing list