Skip to content

Commit 499fb1b

Browse files
committed
[Attributor][FIX] Interposable constants cannot be propagated
1 parent 0a0c23b commit 499fb1b

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ AA::getInitialValueForObj(Attributor &A, const AbstractAttribute &QueryingAA,
260260
if (!Initializer)
261261
return nullptr;
262262
} else {
263-
if (!GV->hasLocalLinkage() && !(GV->isConstant() && GV->hasInitializer()))
263+
if (!GV->hasLocalLinkage() &&
264+
(GV->isInterposable() || !(GV->isConstant() && GV->hasInitializer())))
264265
return nullptr;
265266
if (!GV->hasInitializer())
266267
return UndefValue::get(&Ty);

llvm/test/Transforms/Attributor/value-simplify.ll

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ declare ptr @llvm.call.preallocated.arg(token, i32)
99

1010
@str = private unnamed_addr addrspace(4) constant [1 x i8] c"\00", align 1
1111
@ConstAS3Ptr = addrspace(3) global i32 0, align 4
12+
@ConstPtr = constant i32 0, align 4
13+
@ConstWeakPtr = weak constant i32 0, align 4
14+
@ConstWeakODRPtr = weak_odr constant i32 0, align 4
1215

1316
;.
1417
; CHECK: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr addrspace(4) constant [1 x i8] zeroinitializer, align 1
1518
; CHECK: @[[CONSTAS3PTR:[a-zA-Z0-9_$"\\.-]+]] = addrspace(3) global i32 0, align 4
19+
; CHECK: @[[CONSTPTR:[a-zA-Z0-9_$"\\.-]+]] = constant i32 0, align 4
20+
; CHECK: @[[CONSTWEAKPTR:[a-zA-Z0-9_$"\\.-]+]] = weak constant i32 0, align 4
21+
; CHECK: @[[CONSTWEAKODRPTR:[a-zA-Z0-9_$"\\.-]+]] = weak_odr constant i32 0, align 4
1622
; CHECK: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external global [[STRUCT_X:%.*]]
1723
; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal constant { [2 x ptr] } { [2 x ptr] [ptr @f1, ptr @f2] }
1824
; CHECK: @[[X:[a-zA-Z0-9_$"\\.-]+]] = external global i32
@@ -1632,6 +1638,53 @@ dead5:
16321638
ret i8 5
16331639
}
16341640

1641+
define i32 @readConst() {
1642+
; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1643+
; TUNIT-LABEL: define {{[^@]+}}@readConst
1644+
; TUNIT-SAME: () #[[ATTR2]] {
1645+
; TUNIT-NEXT: ret i32 0
1646+
;
1647+
; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1648+
; CGSCC-LABEL: define {{[^@]+}}@readConst
1649+
; CGSCC-SAME: () #[[ATTR1]] {
1650+
; CGSCC-NEXT: ret i32 0
1651+
;
1652+
%l = load i32, ptr @ConstPtr
1653+
ret i32 %l
1654+
}
1655+
1656+
define i32 @readWeakConst() {
1657+
; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1658+
; TUNIT-LABEL: define {{[^@]+}}@readWeakConst
1659+
; TUNIT-SAME: () #[[ATTR2]] {
1660+
; TUNIT-NEXT: [[L:%.*]] = load i32, ptr @ConstWeakPtr, align 4
1661+
; TUNIT-NEXT: ret i32 [[L]]
1662+
;
1663+
; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1664+
; CGSCC-LABEL: define {{[^@]+}}@readWeakConst
1665+
; CGSCC-SAME: () #[[ATTR1]] {
1666+
; CGSCC-NEXT: [[L:%.*]] = load i32, ptr @ConstWeakPtr, align 4
1667+
; CGSCC-NEXT: ret i32 [[L]]
1668+
;
1669+
%l = load i32, ptr @ConstWeakPtr
1670+
ret i32 %l
1671+
}
1672+
1673+
define i32 @readWeakOdrConst() {
1674+
; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1675+
; TUNIT-LABEL: define {{[^@]+}}@readWeakOdrConst
1676+
; TUNIT-SAME: () #[[ATTR2]] {
1677+
; TUNIT-NEXT: ret i32 0
1678+
;
1679+
; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
1680+
; CGSCC-LABEL: define {{[^@]+}}@readWeakOdrConst
1681+
; CGSCC-SAME: () #[[ATTR1]] {
1682+
; CGSCC-NEXT: ret i32 0
1683+
;
1684+
%l = load i32, ptr @ConstWeakODRPtr
1685+
ret i32 %l
1686+
}
1687+
16351688
;.
16361689
; TUNIT: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn }
16371690
; TUNIT: attributes #[[ATTR1]] = { memory(readwrite, argmem: none) }

0 commit comments

Comments
 (0)