Skip to content

Commit 7e296d6

Browse files
[sycl-post-link] Do not launch GlobalDCE for spec constants cleanup (#3851)
The pass removes `specialization_id` global variables, because they are unused in a module after `SpecConstantsPass` finishes its work, but they are still referenced by debug metadata (if it is present) and such crippled module can't be later handled by llvm-dis or llvm-spirv. I wasn't able to quickly find a simple way to detect debug info presence and also I think that the effect of `GlobalDCE` here is not so crucial, because the amount of cleaned up code is small and can that code can easily be removed by backends
1 parent ad93cf4 commit 7e296d6

13 files changed

+31
-46
lines changed

llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020.ll

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@
2020
@id_compos = dso_local global %class.specialization_id.1 { %struct.ComposConst { i32 1, double 2.000000e+00, %struct.myConst { i32 13, float 0x4020666660000000 } } }, align 8
2121
@id_compos2 = dso_local global %class.specialization_id.2 { %struct.ComposConst2 { i8 1, %struct.myConst { i32 52, float 0x40479999A0000000 }, double 2.000000e+00 } }, align 8
2222

23-
; check that no longer used globals are removed:
23+
; check that the following globals are preserved: even though they are won't be
24+
; used in the module anymore, they could still be referenced by debug info
25+
; metadata (specialization_id objects are used as template arguments in SYCL
26+
; specialization constant APIs)
27+
; CHECK: @id_double
28+
; CHECK: @id_int
29+
; CHECK: @id_compos
30+
; CHECK: @id_compos2
31+
2432
@__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_doubleE17specialization_idIdEdET1_v = private unnamed_addr constant [37 x i8] c"_ZTS14name_generatorIL_Z9id_doubleEE\00", align 1
25-
; CHECK-NOT: @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_doubleE17specialization_idIdEdET1_v
2633
@__builtin_unique_stable_name._Z27get_specialization_constantIL_Z6id_intE17specialization_idIiEiET1_v = private unnamed_addr constant [34 x i8] c"_ZTS14name_generatorIL_Z6id_intEE\00", align 1
27-
; CHECK-NOT: @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z6id_intE17specialization_idIiEiET1_v
2834
@__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_composE17specialization_idI11ComposConstES1_ET1_v = private unnamed_addr constant [37 x i8] c"_ZTS14name_generatorIL_Z9id_composEE\00", align 1
29-
; CHECK-NOT: @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_composE17specialization_idI11ComposConstES1_ET1_v
3035
@__builtin_unique_stable_name._Z27get_specialization_constantIL_Z10id_compos2E17specialization_idI12ComposConst2ES1_ET1_v = private unnamed_addr constant [39 x i8] c"_ZTS14name_generatorIL_Z10id_compos2EE\00", align 1
31-
; CHECK-NOT: @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z10id_compos2E17specialization_idI12ComposConst2ES1_ET1_v
3236

3337
; CHECK-LABEL: define dso_local void @_Z4testv
3438
define dso_local void @_Z4testv() local_unnamed_addr #0 {

llvm/test/tools/sycl-post-link/spec-constants/composite-O0.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \
2-
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue
2+
; RUN: | FileCheck %s --implicit-check-not "call {{.*}} __sycl_getCompositeSpecConstantValue"
33
;
44
; This test is intended to check that sycl-post-link tool is capable of handling
55
; composite specialization constants by lowering them into a set of SPIR-V

llvm/test/tools/sycl-post-link/spec-constants/composite-O2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \
2-
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue --implicit-check-not __sycl_getComposite2020SpecConstantValue
2+
; RUN: | FileCheck %s --implicit-check-not "call {{.*}} __sycl_getCompositeSpecConstantValue" --implicit-check-not "call {{.*}} __sycl_getComposite2020SpecConstantValue"
33
;
44
; This test is intended to check that sycl-post-link tool is capable of handling
55
; composite specialization constants by lowering them into a set of SPIR-V

llvm/test/tools/sycl-post-link/spec-constants/composite-default-value.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: sycl-post-link -spec-const=default --ir-output-only %s -S -o - \
2-
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue --implicit-check-not __sycl_getComposite2020SpecConstantValue
2+
; RUN: | FileCheck %s --implicit-check-not "call {{.*}} __sycl_getCompositeSpecConstantValue" --implicit-check-not "call {{.*}} __sycl_getComposite2020SpecConstantValue"
33
;
44
; This test checks that composite specialization constants can be correctly
55
; initialized by sycl-post-link tool for AOT use-case (default initialization

llvm/test/tools/sycl-post-link/spec-constants/composite-no-sret.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \
2-
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue --implicit-check-not __sycl_getComposite2020SpecConstantValue
2+
; RUN: | FileCheck %s --implicit-check-not "call {{.*}} __sycl_getCompositeSpecConstantValue" --implicit-check-not "call {{.*}} __sycl_getComposite2020SpecConstantValue"
33

44
; CHECK: %[[#NS0:]] = call i32 @_Z20__spirv_SpecConstantii(i32 [[#ID:]], i32
55
; CHECK: %[[#NS1:]] = call i32 @_Z20__spirv_SpecConstantii(i32 [[#ID + 1]], i32 42)

llvm/test/tools/sycl-post-link/spec-constants/multiple-composite-usages-2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \
2-
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue
2+
; RUN: | FileCheck %s --implicit-check-not "call {{.*}} __sycl_getCompositeSpecConstantValue"
33
;
44
; This test is intended to check that sycl-post-link tool is capable of handling
55
; situations when the same composite specialization constants is used more than

llvm/test/tools/sycl-post-link/spec-constants/multiple-composite-usages.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \
2-
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue
2+
; RUN: | FileCheck %s --implicit-check-not "call {{.*}} __sycl_getCompositeSpecConstantValue"
33
;
44
; This test is intended to check that sycl-post-link tool is capable of handling
55
; situations when the same composite specialization constants is used more than

llvm/test/tools/sycl-post-link/spec-constants/multiple-sym-id-usages.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
; This test checks that the tool does not crash and removes the unused spec
22
; constant global symbol when it is referenced more than once.
33

4-
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \
5-
; RUN: | FileCheck %s
4+
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o %t.ll
65

76
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
87
target triple = "spir64-unknown-unknown-sycldevice"
98

109
%"spec_constant" = type { i8 }
1110

1211
@SCSymID = private unnamed_addr constant [10 x i8] c"SpecConst\00", align 1
13-
; CHECK-NOT: @SCSymID
1412

1513
declare dso_local spir_func float @_Z33__sycl_getScalarSpecConstantValueIfET_PKc(i8 addrspace(4)*)
1614

llvm/test/tools/sycl-post-link/spec-constants/scalar-O0.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ target triple = "spir64-unknown-linux-sycldevice"
1414
$FOO = comdat any
1515

1616
@__unique_stable_name.FOO = private unnamed_addr constant [18 x i8] c"_ZTS11MyBoolConst\00", align 1
17-
; check that post link removes the no longer used global
18-
; CHECK-NOT: @__unique_stable_name.FOO
1917

2018
declare dso_local spir_func zeroext i1 @_Z33__sycl_getScalarSpecConstantValueIbET_PKc(i8 addrspace(4)*) #7
2119

llvm/test/tools/sycl-post-link/spec-constants/scalar-O2.ll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,17 @@ target triple = "spir64-unknown-linux-sycldevice"
1717
$_ZTS17SpecializedKernel = comdat any
1818

1919
@__unique_stable_name.SC_Ib11MyBoolConstE3getEv = private unnamed_addr constant [18 x i8] c"_ZTS11MyBoolConst\00", align 1
20-
;;;;;;;;;;;;;; check that no longer used globals are removed:
21-
; CHECK-NOT: @__unique_stable_name.SC_Ib11MyBoolConstE3getEv
2220
@__unique_stable_name.SC_Ia11MyInt8ConstE3getEv = private unnamed_addr constant [18 x i8] c"_ZTS11MyInt8Const\00", align 1
23-
; CHECK-NOT: @__unique_stable_name.SC_Ia11MyInt8ConstE3getEv
2421
@__unique_stable_name.SC_Ih12MyUInt8ConstE3getEv = private unnamed_addr constant [19 x i8] c"_ZTS12MyUInt8Const\00", align 1
25-
; CHECK-NOT: @__unique_stable_name.SC_Ih12MyUInt8ConstE3getEv
2622
@__unique_stable_name.SC_Is12MyInt16ConstE3getEv = private unnamed_addr constant [19 x i8] c"_ZTS12MyInt16Const\00", align 1
27-
; CHECK-NOT: @__unique_stable_name.SC_Is12MyInt16ConstE3getEv
2823
@__unique_stable_name.SC_It13MyUInt16ConstE3getEv = private unnamed_addr constant [20 x i8] c"_ZTS13MyUInt16Const\00", align 1
29-
; CHECK-NOT: @__unique_stable_name.SC_It13MyUInt16ConstE3getEv
3024
@__unique_stable_name.SC_Ii12MyInt32ConstE3getEv = private unnamed_addr constant [19 x i8] c"_ZTS12MyInt32Const\00", align 1
31-
; CHECK-NOT: @__unique_stable_name.SC_Ii12MyInt32ConstE3getEv
3225
@__unique_stable_name.SC_Ij13MyUInt32ConstE3getEv = private unnamed_addr constant [20 x i8] c"_ZTS13MyUInt32Const\00", align 1
33-
; CHECK-NOT: @__unique_stable_name.SC_Ij13MyUInt32ConstE3getEv
3426
@__unique_stable_name.SC_Il12MyInt64ConstE3getEv = private unnamed_addr constant [19 x i8] c"_ZTS12MyInt64Const\00", align 1
35-
; CHECK-NOT: @__unique_stable_name.SC_Il12MyInt64ConstE3getEv
3627
@__unique_stable_name.SC_Im13MyUInt64ConstE3getEv = private unnamed_addr constant [20 x i8] c"_ZTS13MyUInt64Const\00", align 1
37-
; CHECK-NOT: @__unique_stable_name.SC_Im13MyUInt64ConstE3getEv
3828
@__unique_stable_name.SC_If12MyFloatConstE3getEv = private unnamed_addr constant [19 x i8] c"_ZTS12MyFloatConst\00", align 1
39-
; CHECK-NOT: @__unique_stable_name.SC_If12MyFloatConstE3getEv
4029
@__unique_stable_name.SC_Id13MyDoubleConstE3getEv = private unnamed_addr constant [20 x i8] c"_ZTS13MyDoubleConst\00", align 1
41-
; CHECK-NOT: @__unique_stable_name.SC_Id13MyDoubleConstE3getEv
4230
@__unique_stable_name.SC_Id14MyDoubleConst2E3getEv = private unnamed_addr constant [21 x i8] c"_ZTS14MyDoubleConst2\00", align 1
43-
; CHECK-NOT: @__unique_stable_name.SC_Id14MyDoubleConst2E3getEv
4431

4532
; Function Attrs: norecurse
4633
define weak_odr dso_local spir_kernel void @_ZTS17SpecializedKernel(float addrspace(1)* %0, %"cl::sycl::range"* byval(%"cl::sycl::range") align 8 %1, %"cl::sycl::range"* byval(%"cl::sycl::range") align 8 %2, %"cl::sycl::id"* byval(%"cl::sycl::id") align 8 %3) local_unnamed_addr #0 comdat !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {

llvm/test/tools/sycl-post-link/spec-constants/spec_const_and_split.ll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
; into properties of each device image
88

99
; RUN: sycl-post-link -split=kernel -spec-const=rt -S %s -o %t.files.table
10-
; RUN: FileCheck %s -input-file=%t.files_0.ll --check-prefixes CHECK-IR0,CHECK-IR
11-
; RUN: FileCheck %s -input-file=%t.files_1.ll --check-prefixes CHECK-IR1,CHECK-IR
12-
; RUN: FileCheck %s -input-file=%t.files_2.ll --check-prefixes CHECK-IR2,CHECK-IR
10+
; RUN: FileCheck %s -input-file=%t.files_0.ll --check-prefixes CHECK-IR0
11+
; RUN: FileCheck %s -input-file=%t.files_1.ll --check-prefixes CHECK-IR1
12+
; RUN: FileCheck %s -input-file=%t.files_2.ll --check-prefixes CHECK-IR2
1313
; RUN: FileCheck %s -input-file=%t.files_0.prop --check-prefixes CHECK-PROP0
1414
; RUN: FileCheck %s -input-file=%t.files_1.prop --check-prefixes CHECK-PROP1
1515
; RUN: FileCheck %s -input-file=%t.files_2.prop --check-prefixes CHECK-PROP2
1616

1717
@SCSymID = private unnamed_addr constant [10 x i8] c"SpecConst\00", align 1
1818
@SCSymID2 = private unnamed_addr constant [11 x i8] c"SpecConst2\00", align 1
19-
; CHECK-IR-NOT: @SCSymID
20-
; CHECK-IR-NOT: @SCSymID2
2119

2220
declare dso_local spir_func zeroext i1 @_Z33__sycl_getScalarSpecConstantValueIbET_PKc(i8 addrspace(4)*)
2321

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,6 @@ static TableFiles processOneModule(std::unique_ptr<Module> M, bool IsEsimd,
573573
// Register required analysis
574574
MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
575575
RunSpecConst.addPass(SCP);
576-
// This pass deletes unreachable globals.
577-
RunSpecConst.addPass(GlobalDCEPass());
578576

579577
for (auto &MPtr : ResultModules) {
580578
// perform the spec constant intrinsics transformation on each resulting

sycl/test/basic_tests/SYCL-2020-spec-const-ids-order.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clangxx -fsycl -fsycl-device-only -c -o %t.bc %s
22
// RUN: sycl-post-link %t.bc -spec-const=default -S -o %t-split1.txt
3-
// RUN: cat %t-split1_0.ll | FileCheck %s -check-prefixes=CHECK,CHECK-IR
4-
// RUN: cat %t-split1_0.prop | FileCheck %s -check-prefixes=CHECK,CHECK-PROP
3+
// RUN: cat %t-split1_0.ll | FileCheck %s -check-prefixes=CHECK-IR
4+
// RUN: cat %t-split1_0.prop | FileCheck %s -check-prefixes=CHECK-PROP
55
//
66
//==----------- SYCL-2020-spec-const-ids-order.cpp -------------------------==//
77
//
@@ -46,11 +46,13 @@ int main() {
4646
}
4747

4848
// CHECK-PROP: [SYCL/specialization constants]
49-
// CHECK: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL5Val23EEE
50-
// CHECK-IR-SAME: i32 [[#ID:]]
51-
// CHECK-NEXT: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL10ConstantIdEEE
52-
// CHECK-IR-SAME: i32 [[#ID+1]]
53-
// CHECK-NEXT: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL11SecondValueEEE
54-
// CHECK-IR-SAME: i32 [[#ID+2]]
55-
// CHECK-NEXT: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL11SpecConst42EEE
56-
// CHECK-IR-SAME: i32 [[#ID+3]]
49+
// CHECK-PROP-NEXT: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL5Val23EEE
50+
// CHECK-PROP-NEXT: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL10ConstantIdEEE
51+
// CHECK-PROP-NEXT: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL11SecondValueEEE
52+
// CHECK-PROP-NEXT: _ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL11SpecConst42EEE
53+
//
54+
// CHECK-IR: !sycl.specialization-constants = !{![[#MD0:]], ![[#MD1:]], ![[#MD2:]], ![[#MD3:]]}
55+
// CHECK-IR: ![[#MD0]] = !{!"_ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL5Val23EEE", i32 [[#ID:]]
56+
// CHECK-IR: ![[#MD1]] = !{!"_ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL10ConstantIdEEE", i32 [[#ID+1]]
57+
// CHECK-IR: ![[#MD2]] = !{!"_ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL11SecondValueEEE", i32 [[#ID+2]]
58+
// CHECK-IR: ![[#MD3]] = !{!"_ZTSN2cl4sycl6detail32specialization_id_name_generatorIL_ZL11SpecConst42EEE", i32 [[#ID+3]]

0 commit comments

Comments
 (0)