-
Notifications
You must be signed in to change notification settings - Fork 14.3k
GlobalOpt: Use the correct address space when creating a "*.init" global. #118562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms Author: Owen Anderson (resistor) ChangesFull diff: https://github.com/llvm/llvm-project/pull/118562.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 3381b5f77683b5..72d332ee316ca3 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -950,7 +950,8 @@ OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI,
new GlobalVariable(Type::getInt1Ty(GV->getContext()), false,
GlobalValue::InternalLinkage,
ConstantInt::getFalse(GV->getContext()),
- GV->getName()+".init", GV->getThreadLocalMode());
+ GV->getName()+".init", GV->getThreadLocalMode(),
+ GV->getType()->getAddressSpace());
bool InitBoolUsed = false;
// Loop over all instruction uses of GV, processing them in turn.
diff --git a/llvm/test/Transforms/GlobalOpt/malloc-promote-addrspace.ll b/llvm/test/Transforms/GlobalOpt/malloc-promote-addrspace.ll
new file mode 100644
index 00000000000000..054c60bd235bd4
--- /dev/null
+++ b/llvm/test/Transforms/GlobalOpt/malloc-promote-addrspace.ll
@@ -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
+
+@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
+ br label %5
+
+4: ; preds = %0
+ br label %5
+
+5: ; preds = %3, %4
+ %6 = phi i32 [ -1, %3 ], [ 1, %4 ]
+ ret i32 %6
+}
+
+define internal void @f2() {
+; CHECK-LABEL: define {{[^@]+}}@f2() unnamed_addr {
+; CHECK-NEXT: store i1 true, ptr addrspace(200) @g.init, align 1
+; CHECK-NEXT: ret void
+;
+ %1 = call noalias ptr @malloc(i64 4)
+ store ptr %1, ptr addrspace(200) @g, align 8
+ ret void
+}
+
+define dso_local i32 @main() {
+; CHECK-LABEL: define {{[^@]+}}@main() local_unnamed_addr {
+; CHECK-NEXT: store i1 false, ptr addrspace(200) @g.init, align 1
+; CHECK-NEXT: [[TMP1:%.*]] = call fastcc i32 @f1()
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ store ptr null, ptr addrspace(200) @g, align 8
+ %1 = call i32 @f1()
+ ret i32 %1
+}
+
+declare dso_local noalias ptr @malloc(i64) allockind("alloc,uninitialized") allocsize(0)
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
560635a
to
e22d260
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/11553 Here is the relevant piece of the build log for the reference
|
Tagging @jrtc27 and @arichardson for awareness on CHERI-derived PRs |
No description provided.