Skip to content

Commit 366c619

Browse files
[IPSCCP] Variable not visible at Og:
https://bugs.llvm.org/show_bug.cgi?id=51559 #50901 IPSCCP pass removes the global variable and does not create a constant expression for the initializer value. Extend test coverage to include: - half and bfloat types. - checks for undef (int32 and ptr).
1 parent dd7386d commit 366c619

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3586,7 +3586,8 @@ DIExpression *llvm::getExpressionForConstant(DIBuilder &DIB, const Constant &C,
35863586
return createIntegerExpression(C);
35873587

35883588
auto *FP = dyn_cast<ConstantFP>(&C);
3589-
if (FP && (Ty.isFloatTy() || Ty.isDoubleTy())) {
3589+
if (FP &&
3590+
(Ty.isFloatTy() || Ty.isDoubleTy() || Ty.isHalfTy() || Ty.isBFloatTy())) {
35903591
const APFloat &APF = FP->getValueAPF();
35913592
return DIB.createConstantValueExpression(
35923593
APF.bitcastToAPInt().getZExtValue());

llvm/test/Transforms/SCCP/pr50901.ll

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,25 @@
5252
; CHECK: = !DIGlobalVariableExpression(var: ![[DBG_FLOAT_UNDEF:.+]], expr: !DIExpression())
5353
; CHECK-DAG: ![[DBG_FLOAT_UNDEF]] = distinct !DIGlobalVariable(name: "g_float_undef"
5454

55+
; CHECK: ![[G8:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG8:[0-9]+]], expr: !DIExpression(DW_OP_constu, 22136, DW_OP_stack_value))
56+
; CHECK-DAG: ![[DBG8]] = distinct !DIGlobalVariable(name: "g_88", {{.*}}
57+
; CHECK: ![[G9:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG9:[0-9]+]], expr: !DIExpression(DW_OP_constu, 23726, DW_OP_stack_value))
58+
; CHECK-DAG: ![[DBG9]] = distinct !DIGlobalVariable(name: "g_99", {{.*}}
59+
60+
; CHECK-DAG: ![[DBGA:[0-9]+]] = distinct !DIGlobalVariable(name: "g_i32_undef"
61+
; CHECK-DAG: ![[GA:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBGA]], expr: !DIExpression())
62+
; CHECK-DAG: ![[DBGB:[0-9]+]] = distinct !DIGlobalVariable(name: "g_ptr_undef"
63+
; CHECK-DAG: ![[GB:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBGB]], expr: !DIExpression())
64+
5565
@g_1 = dso_local global i32 -4, align 4, !dbg !0
5666
@g_2 = dso_local global float 0x4011C28F60000000, align 4, !dbg !8
5767
@g_3 = dso_local global i8 97, align 1, !dbg !10
5868
@g_4 = dso_local global i32 4, align 4, !dbg !13
5969
@g_5 = dso_local global i8 1, align 1, !dbg !16
6070
@g_6 = dso_local global ptr null, align 8, !dbg !19
6171
@g_7 = dso_local global ptr null, align 8, !dbg !23
72+
@g_8 = dso_local global half 0xH4321, align 4, !dbg !86
73+
@g_9 = dso_local global bfloat 0xR3F80, align 4, !dbg !90
6274
@_ZL4g_11 = internal global i32 -5, align 4, !dbg !25
6375
@_ZL4g_22 = internal global float 0x4016333340000000, align 4, !dbg !27
6476
@_ZL4g_33 = internal global i8 98, align 1, !dbg !29
@@ -67,6 +79,10 @@
6779
@_ZL4g_66 = internal global ptr null, align 8, !dbg !35
6880
@_ZL4g_77 = internal global ptr inttoptr (i64 70 to ptr), align 8, !dbg !37
6981
@g_float_undef = internal global float undef, align 4, !dbg !83
82+
@_ZL4g_88 = internal global half 0xH5678, align 4, !dbg !88
83+
@_ZL4g_99 = internal global bfloat 0xR5CAE, align 4, !dbg !92
84+
@g_i32_undef = internal global i32 undef, align 4, !dbg !95
85+
@g_ptr_undef = internal global ptr undef, align 8, !dbg !97
7086

7187
define dso_local void @_Z3barv() !dbg !46 {
7288
entry:
@@ -88,6 +104,15 @@ entry:
88104
store ptr %6, ptr @g_7, align 8, !dbg !59
89105
%l = load float, ptr @g_float_undef, align 8, !dbg !59
90106
store float %l, ptr @g_2, align 8, !dbg !59
107+
%7 = load half, ptr @_ZL4g_88, align 4, !dbg !59
108+
store half %7, ptr @g_8, align 4, !dbg !59
109+
%8 = load bfloat, ptr @_ZL4g_99, align 4, !dbg !59
110+
store bfloat %8, ptr @g_9, align 4, !dbg !59
111+
%9 = load i32, ptr @g_i32_undef, align 4, !dbg !59
112+
store i32 %9, ptr @g_1, align 4, !dbg !59
113+
%10 = load ptr, ptr @g_ptr_undef, align 8, !dbg !59
114+
store ptr %10, ptr @g_6, align 8, !dbg !59
115+
91116
ret void, !dbg !59
92117
}
93118

@@ -108,7 +133,7 @@ entry:
108133
!4 = !{!5}
109134
!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
110135
!6 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
111-
!7 = !{!0, !8, !10, !13, !16, !19, !23, !25, !27, !29, !31, !33, !35, !37, !83}
136+
!7 = !{!0, !8, !10, !13, !16, !19, !23, !25, !27, !29, !31, !33, !35, !37, !83, !86, !88, !90, !92, !95, !97}
112137
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
113138
!9 = distinct !DIGlobalVariable(name: "g_2", scope: !2, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true)
114139
!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression())
@@ -159,3 +184,17 @@ entry:
159184
!82 = !DILocation(line: 31, column: 1, scope: !77)
160185
!83 = !DIGlobalVariableExpression(var: !84, expr: !DIExpression())
161186
!84 = distinct !DIGlobalVariable(name: "g_float_undef", linkageName: "g_float_undef", scope: !2, file: !3, line: 15, type: !6, isLocal: true, isDefinition: true)
187+
!85 = !DIBasicType(name: "float", size: 16, encoding: DW_ATE_float)
188+
!86 = !DIGlobalVariableExpression(var: !87, expr: !DIExpression())
189+
!87 = distinct !DIGlobalVariable(name: "g_8", scope: !2, file: !3, line: 2, type: !85, isLocal: false, isDefinition: true)
190+
!88 = !DIGlobalVariableExpression(var: !89, expr: !DIExpression())
191+
!89 = distinct !DIGlobalVariable(name: "g_88", linkageName: "_ZL4g_88", scope: !2, file: !3, line: 10, type: !85, isLocal: true, isDefinition: true)
192+
!90 = !DIGlobalVariableExpression(var: !91, expr: !DIExpression())
193+
!91 = distinct !DIGlobalVariable(name: "g_9", scope: !2, file: !3, line: 2, type: !85, isLocal: false, isDefinition: true)
194+
!92 = !DIGlobalVariableExpression(var: !93, expr: !DIExpression())
195+
!93 = distinct !DIGlobalVariable(name: "g_99", linkageName: "_ZL4g_99", scope: !2, file: !3, line: 10, type: !85, isLocal: true, isDefinition: true)
196+
197+
!95 = !DIGlobalVariableExpression(var: !96, expr: !DIExpression())
198+
!96 = distinct !DIGlobalVariable(name: "g_i32_undef", linkageName: "g_i32_undef", scope: !2, file: !3, line: 9, type: !22, isLocal: true, isDefinition: true)
199+
!97 = !DIGlobalVariableExpression(var: !98, expr: !DIExpression())
200+
!98 = distinct !DIGlobalVariable(name: "g_ptr_undef", linkageName: "g_ptr_undef", scope: !2, file: !3, line: 14, type: !21, isLocal: true, isDefinition: true)

llvm/unittests/Transforms/Utils/LocalTest.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,18 @@ TEST(Local, ExpressionForConstant) {
12411241
EXPECT_NE(Expr, nullptr);
12421242
EXPECT_EQ(Expr->getElement(1), 13841306799765140275U);
12431243

1244+
// Half.
1245+
Type *HalfTy = Type::getHalfTy(Context);
1246+
Expr = createExpression(ConstantFP::get(HalfTy, 5.55), HalfTy);
1247+
EXPECT_NE(Expr, nullptr);
1248+
EXPECT_EQ(Expr->getElement(1), 17805U);
1249+
1250+
// BFloat.
1251+
Type *BFloatTy = Type::getBFloatTy(Context);
1252+
Expr = createExpression(ConstantFP::get(BFloatTy, -5.55), BFloatTy);
1253+
EXPECT_NE(Expr, nullptr);
1254+
EXPECT_EQ(Expr->getElement(1), 49330U);
1255+
12441256
// Pointer.
12451257
PointerType *PtrTy = PointerType::get(Context, 0);
12461258
Expr = createExpression(ConstantPointerNull::get(PtrTy), PtrTy);
@@ -1258,14 +1270,6 @@ TEST(Local, ExpressionForConstant) {
12581270
EXPECT_EQ(Expr->getElement(1), 5678U);
12591271

12601272
// Others.
1261-
Type *HalfTy = Type::getHalfTy(Context);
1262-
Expr = createExpression(ConstantFP::get(HalfTy, 32), HalfTy);
1263-
EXPECT_EQ(Expr, nullptr);
1264-
1265-
Type *BFloatTy = Type::getBFloatTy(Context);
1266-
Expr = createExpression(ConstantFP::get(BFloatTy, 32), BFloatTy);
1267-
EXPECT_EQ(Expr, nullptr);
1268-
12691273
Type *FP128Ty = Type::getFP128Ty(Context);
12701274
Expr = createExpression(ConstantFP::get(FP128Ty, 32), FP128Ty);
12711275
EXPECT_EQ(Expr, nullptr);

0 commit comments

Comments
 (0)