Skip to content

Commit 42cd75c

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 for all float types: Half, bfloat, fp128, x86_fp80, ppc_fp128
1 parent 366c619 commit 42cd75c

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

llvm/lib/Transforms/Utils/Local.cpp

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

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

llvm/test/Transforms/SCCP/pr50901.ll

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
; CHECK-DAG: ![[DBGB:[0-9]+]] = distinct !DIGlobalVariable(name: "g_ptr_undef"
6363
; CHECK-DAG: ![[GB:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBGB]], expr: !DIExpression())
6464

65+
; CHECK: ![[G10:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG10:[0-9]+]], expr: !DIExpression(DW_OP_constu, 17293822569102704640, DW_OP_stack_value))
66+
; CHECK-DAG: ![[DBG10]] = distinct !DIGlobalVariable(name: "g_1010", {{.*}}
67+
; CHECK: ![[G11:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG11:[0-9]+]], expr: !DIExpression(DW_OP_constu, 17293822569102704640, DW_OP_stack_value))
68+
; CHECK-DAG: ![[DBG11]] = distinct !DIGlobalVariable(name: "g_1111", {{.*}}
69+
; CHECK: ![[G12:[0-9]+]] = !DIGlobalVariableExpression(var: ![[DBG12:[0-9]+]], expr: !DIExpression(DW_OP_constu, 14480694097861998592, DW_OP_stack_value))
70+
; CHECK-DAG: ![[DBG12]] = distinct !DIGlobalVariable(name: "g_1212", {{.*}}
71+
6572
@g_1 = dso_local global i32 -4, align 4, !dbg !0
6673
@g_2 = dso_local global float 0x4011C28F60000000, align 4, !dbg !8
6774
@g_3 = dso_local global i8 97, align 1, !dbg !10
@@ -71,6 +78,9 @@
7178
@g_7 = dso_local global ptr null, align 8, !dbg !23
7279
@g_8 = dso_local global half 0xH4321, align 4, !dbg !86
7380
@g_9 = dso_local global bfloat 0xR3F80, align 4, !dbg !90
81+
@g_10 = dso_local global fp128 0xLF0000000000000004000921CAC083126, align 16, !dbg !100
82+
@g_11 = dso_local global ppc_fp128 0xMF0000000000000004000921CAC083126, align 16, !dbg !105
83+
@g_12 = dso_local global x86_fp80 0xK4000C8F5C28F5C28F800, align 16, !dbg !110
7484
@_ZL4g_11 = internal global i32 -5, align 4, !dbg !25
7585
@_ZL4g_22 = internal global float 0x4016333340000000, align 4, !dbg !27
7686
@_ZL4g_33 = internal global i8 98, align 1, !dbg !29
@@ -81,6 +91,9 @@
8191
@g_float_undef = internal global float undef, align 4, !dbg !83
8292
@_ZL4g_88 = internal global half 0xH5678, align 4, !dbg !88
8393
@_ZL4g_99 = internal global bfloat 0xR5CAE, align 4, !dbg !92
94+
@_ZL4g_1010 = internal global fp128 0xLF0000000000000004000921CAC083126, align 16, !dbg !102
95+
@_ZL4g_1111 = internal global ppc_fp128 0xMF0000000000000004000921CAC083126, align 16, !dbg !107
96+
@_ZL4g_1212 = internal global x86_fp80 0xK4000C8F5C28F5C28F800, align 16, !dbg !112
8497
@g_i32_undef = internal global i32 undef, align 4, !dbg !95
8598
@g_ptr_undef = internal global ptr undef, align 8, !dbg !97
8699

@@ -112,6 +125,12 @@ entry:
112125
store i32 %9, ptr @g_1, align 4, !dbg !59
113126
%10 = load ptr, ptr @g_ptr_undef, align 8, !dbg !59
114127
store ptr %10, ptr @g_6, align 8, !dbg !59
128+
%11 = load fp128, ptr @_ZL4g_1010, align 16, !dbg !59
129+
store fp128 %11, ptr @g_10, align 16, !dbg !59
130+
%12 = load ppc_fp128, ptr @_ZL4g_1111, align 16, !dbg !59
131+
store ppc_fp128 %12, ptr @g_11, align 16, !dbg !59
132+
%13 = load x86_fp80, ptr @_ZL4g_1212, align 16, !dbg !59
133+
store x86_fp80 %13, ptr @g_12, align 16, !dbg !59
115134

116135
ret void, !dbg !59
117136
}
@@ -133,7 +152,7 @@ entry:
133152
!4 = !{!5}
134153
!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
135154
!6 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
136-
!7 = !{!0, !8, !10, !13, !16, !19, !23, !25, !27, !29, !31, !33, !35, !37, !83, !86, !88, !90, !92, !95, !97}
155+
!7 = !{!0, !8, !10, !13, !16, !19, !23, !25, !27, !29, !31, !33, !35, !37, !83, !86, !88, !90, !92, !95, !97, !100, !102, !105, !107, !110, !112}
137156
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
138157
!9 = distinct !DIGlobalVariable(name: "g_2", scope: !2, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true)
139158
!10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression())
@@ -198,3 +217,20 @@ entry:
198217
!96 = distinct !DIGlobalVariable(name: "g_i32_undef", linkageName: "g_i32_undef", scope: !2, file: !3, line: 9, type: !22, isLocal: true, isDefinition: true)
199218
!97 = !DIGlobalVariableExpression(var: !98, expr: !DIExpression())
200219
!98 = distinct !DIGlobalVariable(name: "g_ptr_undef", linkageName: "g_ptr_undef", scope: !2, file: !3, line: 14, type: !21, isLocal: true, isDefinition: true)
220+
221+
!99 = !DIBasicType(name: "float", size: 128, encoding: DW_ATE_float)
222+
!100 = !DIGlobalVariableExpression(var: !101, expr: !DIExpression())
223+
!101 = distinct !DIGlobalVariable(name: "g_10", scope: !2, file: !3, line: 2, type: !99, isLocal: false, isDefinition: true)
224+
!102 = !DIGlobalVariableExpression(var: !103, expr: !DIExpression())
225+
!103 = distinct !DIGlobalVariable(name: "g_1010", linkageName: "_ZL4g_1010", scope: !2, file: !3, line: 15, type: !99, isLocal: true, isDefinition: true)
226+
227+
!105 = !DIGlobalVariableExpression(var: !106, expr: !DIExpression())
228+
!106 = distinct !DIGlobalVariable(name: "g_11", scope: !2, file: !3, line: 2, type: !99, isLocal: false, isDefinition: true)
229+
!107 = !DIGlobalVariableExpression(var: !108, expr: !DIExpression())
230+
!108 = distinct !DIGlobalVariable(name: "g_1111", linkageName: "_ZL4g_1111", scope: !2, file: !3, line: 15, type: !99, isLocal: true, isDefinition: true)
231+
232+
!109 = !DIBasicType(name: "float", size: 80, encoding: DW_ATE_float)
233+
!110 = !DIGlobalVariableExpression(var: !111, expr: !DIExpression())
234+
!111 = distinct !DIGlobalVariable(name: "g_12", scope: !2, file: !3, line: 2, type: !109, isLocal: false, isDefinition: true)
235+
!112 = !DIGlobalVariableExpression(var: !113, expr: !DIExpression())
236+
!113 = distinct !DIGlobalVariable(name: "g_1212", linkageName: "_ZL4g_1212", scope: !2, file: !3, line: 15, type: !109, isLocal: true, isDefinition: true)

llvm/unittests/Transforms/Utils/LocalTest.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,18 +1269,31 @@ TEST(Local, ExpressionForConstant) {
12691269
EXPECT_NE(Expr, nullptr);
12701270
EXPECT_EQ(Expr->getElement(1), 5678U);
12711271

1272-
// Others.
1272+
// FP128.
12731273
Type *FP128Ty = Type::getFP128Ty(Context);
1274-
Expr = createExpression(ConstantFP::get(FP128Ty, 32), FP128Ty);
1275-
EXPECT_EQ(Expr, nullptr);
1274+
Expr = createExpression(
1275+
ConstantFP::get(FP128Ty, APFloat(APFloat::IEEEquad(), APInt(128, 12345))),
1276+
FP128Ty);
1277+
EXPECT_NE(Expr, nullptr);
1278+
EXPECT_EQ(Expr->getElement(1), 12345U);
12761279

1280+
// X86_FP80.
12771281
Type *X86_FP80Ty = Type::getX86_FP80Ty(Context);
1278-
Expr = createExpression(ConstantFP::get(X86_FP80Ty, 32), X86_FP80Ty);
1279-
EXPECT_EQ(Expr, nullptr);
1282+
Expr = createExpression(
1283+
ConstantFP::get(X86_FP80Ty,
1284+
APFloat(APFloat::x87DoubleExtended(), APInt(80, 67890))),
1285+
X86_FP80Ty);
1286+
EXPECT_NE(Expr, nullptr);
1287+
EXPECT_EQ(Expr->getElement(1), 67890U);
12801288

1289+
// PPC_FP128.
12811290
Type *PPC_FP128Ty = Type::getPPC_FP128Ty(Context);
1282-
Expr = createExpression(ConstantFP::get(PPC_FP128Ty, 32), PPC_FP128Ty);
1283-
EXPECT_EQ(Expr, nullptr);
1291+
Expr = createExpression(
1292+
ConstantFP::get(PPC_FP128Ty,
1293+
APFloat(APFloat::PPCDoubleDouble(), APInt(80, 123890))),
1294+
PPC_FP128Ty);
1295+
EXPECT_NE(Expr, nullptr);
1296+
EXPECT_EQ(Expr->getElement(1), 123890U);
12841297
}
12851298

12861299
TEST(Local, ReplaceDPValue) {

0 commit comments

Comments
 (0)