[llvm] 499fb1b - [Attributor][FIX] Interposable constants cannot be propagated
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 19:29:11 PDT 2023
Author: Johannes Doerfert
Date: 2023-10-20T19:28:09-07:00
New Revision: 499fb1b8d88aac7bc10085ac3b54adb07a067937
URL: https://github.com/llvm/llvm-project/commit/499fb1b8d88aac7bc10085ac3b54adb07a067937
DIFF: https://github.com/llvm/llvm-project/commit/499fb1b8d88aac7bc10085ac3b54adb07a067937.diff
LOG: [Attributor][FIX] Interposable constants cannot be propagated
Added:
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/Attributor/value-simplify.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 1ffafc65ba63a4f..49ced893d5c7340 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -260,7 +260,8 @@ AA::getInitialValueForObj(Attributor &A, const AbstractAttribute &QueryingAA,
if (!Initializer)
return nullptr;
} else {
- if (!GV->hasLocalLinkage() && !(GV->isConstant() && GV->hasInitializer()))
+ if (!GV->hasLocalLinkage() &&
+ (GV->isInterposable() || !(GV->isConstant() && GV->hasInitializer())))
return nullptr;
if (!GV->hasInitializer())
return UndefValue::get(&Ty);
diff --git a/llvm/test/Transforms/Attributor/value-simplify.ll b/llvm/test/Transforms/Attributor/value-simplify.ll
index cbdc190c6ea6341..0ee06afe92f226a 100644
--- a/llvm/test/Transforms/Attributor/value-simplify.ll
+++ b/llvm/test/Transforms/Attributor/value-simplify.ll
@@ -9,10 +9,16 @@ declare ptr @llvm.call.preallocated.arg(token, i32)
@str = private unnamed_addr addrspace(4) constant [1 x i8] c"\00", align 1
@ConstAS3Ptr = addrspace(3) global i32 0, align 4
+ at ConstPtr = constant i32 0, align 4
+ at ConstWeakPtr = weak constant i32 0, align 4
+ at ConstWeakODRPtr = weak_odr constant i32 0, align 4
;.
; CHECK: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr addrspace(4) constant [1 x i8] zeroinitializer, align 1
; CHECK: @[[CONSTAS3PTR:[a-zA-Z0-9_$"\\.-]+]] = addrspace(3) global i32 0, align 4
+; CHECK: @[[CONSTPTR:[a-zA-Z0-9_$"\\.-]+]] = constant i32 0, align 4
+; CHECK: @[[CONSTWEAKPTR:[a-zA-Z0-9_$"\\.-]+]] = weak constant i32 0, align 4
+; CHECK: @[[CONSTWEAKODRPTR:[a-zA-Z0-9_$"\\.-]+]] = weak_odr constant i32 0, align 4
; CHECK: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external global [[STRUCT_X:%.*]]
; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal constant { [2 x ptr] } { [2 x ptr] [ptr @f1, ptr @f2] }
; CHECK: @[[X:[a-zA-Z0-9_$"\\.-]+]] = external global i32
@@ -1632,6 +1638,53 @@ dead5:
ret i8 5
}
+define i32 @readConst() {
+; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; TUNIT-LABEL: define {{[^@]+}}@readConst
+; TUNIT-SAME: () #[[ATTR2]] {
+; TUNIT-NEXT: ret i32 0
+;
+; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; CGSCC-LABEL: define {{[^@]+}}@readConst
+; CGSCC-SAME: () #[[ATTR1]] {
+; CGSCC-NEXT: ret i32 0
+;
+ %l = load i32, ptr @ConstPtr
+ ret i32 %l
+}
+
+define i32 @readWeakConst() {
+; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; TUNIT-LABEL: define {{[^@]+}}@readWeakConst
+; TUNIT-SAME: () #[[ATTR2]] {
+; TUNIT-NEXT: [[L:%.*]] = load i32, ptr @ConstWeakPtr, align 4
+; TUNIT-NEXT: ret i32 [[L]]
+;
+; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; CGSCC-LABEL: define {{[^@]+}}@readWeakConst
+; CGSCC-SAME: () #[[ATTR1]] {
+; CGSCC-NEXT: [[L:%.*]] = load i32, ptr @ConstWeakPtr, align 4
+; CGSCC-NEXT: ret i32 [[L]]
+;
+ %l = load i32, ptr @ConstWeakPtr
+ ret i32 %l
+}
+
+define i32 @readWeakOdrConst() {
+; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; TUNIT-LABEL: define {{[^@]+}}@readWeakOdrConst
+; TUNIT-SAME: () #[[ATTR2]] {
+; TUNIT-NEXT: ret i32 0
+;
+; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
+; CGSCC-LABEL: define {{[^@]+}}@readWeakOdrConst
+; CGSCC-SAME: () #[[ATTR1]] {
+; CGSCC-NEXT: ret i32 0
+;
+ %l = load i32, ptr @ConstWeakODRPtr
+ ret i32 %l
+}
+
;.
; TUNIT: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn }
; TUNIT: attributes #[[ATTR1]] = { memory(readwrite, argmem: none) }
More information about the llvm-commits
mailing list