[llvm] GlobalOpt: Use the correct address space when creating a "*.init" global. (PR #118562)

Owen Anderson via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 16:11:49 PST 2024


================
@@ -0,0 +1,60 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals
+; RUN: opt -S -passes=globalopt -o - < %s | FileCheck %s
+
+ at g = internal addrspace(200) global ptr null, align 8
+
+;.
+; CHECK: @g.init = internal unnamed_addr addrspace(200) global i1 false
+;.
+define internal i32 @f1() {
+; CHECK-LABEL: define {{[^@]+}}@f1() unnamed_addr {
+; CHECK-NEXT:    [[G_INIT_VAL:%.*]] = load i1, ptr addrspace(200) @g.init, align 1
+; CHECK-NEXT:    call fastcc void @f2()
+; CHECK-NEXT:    [[NOTINIT:%.*]] = xor i1 [[G_INIT_VAL]], true
+; CHECK-NEXT:    br i1 [[NOTINIT]], label [[TMP1:%.*]], label [[TMP2:%.*]]
+; CHECK:       1:
+; CHECK-NEXT:    br label [[TMP3:%.*]]
+; CHECK:       2:
+; CHECK-NEXT:    br label [[TMP3]]
+; CHECK:       3:
+; CHECK-NEXT:    [[TMP4:%.*]] = phi i32 [ -1, [[TMP1]] ], [ 1, [[TMP2]] ]
+; CHECK-NEXT:    ret i32 [[TMP4]]
+;
+  %1 = load ptr addrspace(200), ptr addrspace(200) @g, align 8
+  call void @f2();
+  %2 = icmp eq ptr addrspace(200) %1, null
+  br i1 %2, label %3, label %4
+
+3:                                          ; preds = %0
----------------
resistor wrote:

Done

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


More information about the llvm-commits mailing list