Skip to content

Commit 324acf6

Browse files
[sycl-post-link] Support half in SpecConstantsPass (#3911)
1 parent 5eaa14f commit 324acf6

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
; SYCL 2020 specialization constant intrinsics for different types in a device
88
; code.
99

10-
%class.specialization_id = type { double }
10+
%class.specialization_id = type { half }
1111
%class.specialization_id.0 = type { i32 }
1212
%class.specialization_id.1 = type { %struct.ComposConst }
1313
%struct.ComposConst = type { i32, double, %struct.myConst }
1414
%struct.myConst = type { i32, float }
1515
%class.specialization_id.2 = type { %struct.ComposConst2 }
1616
%struct.ComposConst2 = type { i8, %struct.myConst, double }
1717

18-
@id_double = dso_local global %class.specialization_id { double 3.140000e+00 }, align 8
18+
@id_half = dso_local global %class.specialization_id { half 0xH4000 }, align 8
1919
@id_int = dso_local global %class.specialization_id.0 { i32 42 }, align 4
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
@@ -24,39 +24,39 @@
2424
; used in the module anymore, they could still be referenced by debug info
2525
; metadata (specialization_id objects are used as template arguments in SYCL
2626
; specialization constant APIs)
27-
; CHECK: @id_double
27+
; CHECK: @id_half
2828
; CHECK: @id_int
2929
; CHECK: @id_compos
3030
; CHECK: @id_compos2
3131

32-
@__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
32+
@__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_halfE17specialization_idIdEdET1_v = private unnamed_addr constant [35 x i8] c"_ZTS14name_generatorIL_Z9id_halfEE\00", align 1
3333
@__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
3434
@__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
3535
@__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
3636

3737
; CHECK-LABEL: define dso_local void @_Z4testv
3838
define dso_local void @_Z4testv() local_unnamed_addr #0 {
3939
entry:
40-
%call.i = tail call fast double @_Z37__sycl_getScalar2020SpecConstantValueIdET_PKcPvS3_(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_doubleE17specialization_idIdEdET1_v, i64 0, i64 0), i8* bitcast (%class.specialization_id* @id_double to i8*), i8* null)
40+
%call.i = tail call fast half @_Z37__sycl_getScalar2020SpecConstantValueIDhET_PKcPvS3_(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_halfE17specialization_idIdEdET1_v, i64 0, i64 0), i8* bitcast (%class.specialization_id* @id_half to i8*), i8* null)
4141
; CHECK-DEF: %[[GEP:[0-9a-z]+]] = getelementptr i8, i8* null, i32 0
42-
; CHECK-DEF: %[[BITCAST:[0-9a-z]+]] = bitcast i8* %[[GEP]] to double*
43-
; CHECK-DEF: %[[LOAD:[0-9a-z]+]] = load double, double* %[[BITCAST]], align 8
42+
; CHECK-DEF: %[[BITCAST:[0-9a-z]+]] = bitcast i8* %[[GEP]] to half*
43+
; CHECK-DEF: %[[LOAD:[0-9a-z]+]] = load half, half* %[[BITCAST]], align 2
4444
;
45-
; CHECK-RT: call double @_Z20__spirv_SpecConstantid(i32 [[#SCID0:]], double 3.140000e+00)
45+
; CHECK-RT: call half @_Z20__spirv_SpecConstantiDh(i32 [[#SCID0:]], half 0xH4000)
4646

4747
%call.i3 = tail call i32 @_Z37__sycl_getScalar2020SpecConstantValueIiET_PKcPvS3_(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z6id_intE17specialization_idIiEiET1_v, i64 0, i64 0), i8* bitcast (%class.specialization_id.0* @id_int to i8*), i8* null)
48-
; CHECK-DEF: %[[GEP1:[0-9a-z]+]] = getelementptr i8, i8* null, i32 8
48+
; CHECK-DEF: %[[GEP1:[0-9a-z]+]] = getelementptr i8, i8* null, i32 2
4949
; CHECK-DEF: %[[BITCAST1:[0-9a-z]+]] = bitcast i8* %[[GEP1]] to i32*
5050
; CHECK-DEF: %[[LOAD1:[0-9a-z]+]] = load i32, i32* %[[BITCAST1]], align 4
5151
;
5252
; CHECK-RT: call i32 @_Z20__spirv_SpecConstantii(i32 [[#SCID1:]], i32 42)
5353

54-
%call.i4 = tail call fast double @_Z37__sycl_getScalar2020SpecConstantValueIdET_PKcPvS3_(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_doubleE17specialization_idIdEdET1_v, i64 0, i64 0), i8* bitcast (%class.specialization_id* @id_double to i8*), i8* null)
54+
%call.i4 = tail call fast half @_Z37__sycl_getScalar2020SpecConstantValueIDhET_PKcPvS3_(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_halfE17specialization_idIdEdET1_v, i64 0, i64 0), i8* bitcast (%class.specialization_id* @id_half to i8*), i8* null)
5555
; CHECK-DEF: %[[GEP2:[0-9a-z]+]] = getelementptr i8, i8* null, i32 0
56-
; CHECK-DEF: %[[BITCAST2:[0-9a-z]+]] = bitcast i8* %[[GEP2]] to double*
57-
; CHECK-DEF: %[[LOAD2:[0-9a-z]+]] = load double, double* %[[BITCAST2]], align 8
56+
; CHECK-DEF: %[[BITCAST2:[0-9a-z]+]] = bitcast i8* %[[GEP2]] to half*
57+
; CHECK-DEF: %[[LOAD2:[0-9a-z]+]] = load half, half* %[[BITCAST2]], align 2
5858
;
59-
; CHECK-RT: call double @_Z20__spirv_SpecConstantid(i32 [[#SCID0]], double 3.140000e+00)
59+
; CHECK-RT: call half @_Z20__spirv_SpecConstantiDh(i32 [[#SCID0]], half 0xH4000)
6060
ret void
6161
}
6262

@@ -69,7 +69,7 @@ entry:
6969
%0 = bitcast %struct.ComposConst* %tmp to i8*
7070
call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %0) #3
7171
call void @_Z40__sycl_getComposite2020SpecConstantValueI11ComposConstET_PKcPvS4_(%struct.ComposConst* nonnull sret(%struct.ComposConst) align 8 %tmp, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_composE17specialization_idI11ComposConstES1_ET1_v, i64 0, i64 0), i8* bitcast (%class.specialization_id.1* @id_compos to i8*), i8* null)
72-
; CHECK-DEF: %[[GEP:[0-9a-z]+]] = getelementptr i8, i8* null, i32 12
72+
; CHECK-DEF: %[[GEP:[0-9a-z]+]] = getelementptr i8, i8* null, i32 6
7373
; CHECK-DEF: %[[BITCAST:[0-9a-z]+]] = bitcast i8* %[[GEP]] to %struct.ComposConst*
7474
; CHECK-DEF: %[[C1:[0-9a-z]+]] = load %struct.ComposConst, %struct.ComposConst* %[[BITCAST]], align 8
7575
;
@@ -86,7 +86,7 @@ entry:
8686
%1 = getelementptr inbounds %struct.ComposConst2, %struct.ComposConst2* %tmp1, i64 0, i32 0
8787
call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %1) #3
8888
call void @_Z40__sycl_getComposite2020SpecConstantValueI12ComposConst2ET_PKcPvS4_(%struct.ComposConst2* nonnull sret(%struct.ComposConst2) align 8 %tmp1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z10id_compos2E17specialization_idI12ComposConst2ES1_ET1_v, i64 0, i64 0), i8* getelementptr inbounds (%class.specialization_id.2, %class.specialization_id.2* @id_compos2, i64 0, i32 0, i32 0), i8* null) call void @llvm.lifetime.end.p0i8(i64 24, i8* nonnull %1) #3
89-
; CHECK-DEF: %[[GEP1:[0-9a-z]+]] = getelementptr i8, i8* null, i32 36
89+
; CHECK-DEF: %[[GEP1:[0-9a-z]+]] = getelementptr i8, i8* null, i32 30
9090
; CHECK-DEF: %[[BITCAST1:[0-9a-z]+]] = bitcast i8* %[[GEP1]] to %struct.ComposConst2*
9191
; CHECK-DEF: %[[C2:[0-9a-z]+]] = load %struct.ComposConst2, %struct.ComposConst2* %[[BITCAST1]], align 8
9292
;
@@ -102,7 +102,7 @@ entry:
102102
%2 = bitcast %struct.ComposConst* %tmp2 to i8*
103103
call void @llvm.lifetime.start.p0i8(i64 24, i8* nonnull %2) #3
104104
call void @_Z40__sycl_getComposite2020SpecConstantValueI11ComposConstET_PKcPvS4_(%struct.ComposConst* nonnull sret(%struct.ComposConst) align 8 %tmp2, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @__builtin_unique_stable_name._Z27get_specialization_constantIL_Z9id_composE17specialization_idI11ComposConstES1_ET1_v, i64 0, i64 0), i8* bitcast (%class.specialization_id.1* @id_compos to i8*), i8* null)
105-
; CHECK-DEF: %[[GEP2:[0-9a-z]+]] = getelementptr i8, i8* null, i32 12
105+
; CHECK-DEF: %[[GEP2:[0-9a-z]+]] = getelementptr i8, i8* null, i32 6
106106
; CHECK-DEF: %[[BITCAST2:[0-9a-z]+]] = bitcast i8* %[[GEP2]] to %struct.ComposConst*
107107
; CHECK-DEF: %[[C3:[0-9a-z]+]] = load %struct.ComposConst, %struct.ComposConst* %[[BITCAST2]], align 8
108108
;
@@ -123,6 +123,8 @@ declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
123123

124124
declare dso_local double @_Z37__sycl_getScalar2020SpecConstantValueIdET_PKcPvS3_(i8*, i8*, i8*) local_unnamed_addr #1
125125

126+
declare dso_local half @_Z37__sycl_getScalar2020SpecConstantValueIDhET_PKcPvS3_(i8*, i8*, i8*) local_unnamed_addr #1
127+
126128
declare dso_local i32 @_Z37__sycl_getScalar2020SpecConstantValueIiET_PKcPvS3_(i8*, i8*, i8*) local_unnamed_addr #1
127129

128130
declare dso_local void @_Z40__sycl_getComposite2020SpecConstantValueI11ComposConstET_PKcPvS4_(%struct.ComposConst* sret(%struct.ComposConst) align 8, i8*, i8*, i8*) local_unnamed_addr #2
@@ -139,7 +141,7 @@ attributes #3 = { nounwind }
139141
; CHECK-DEF: !sycl.specialization-constants-default-values = !{![[#ID4:]], ![[#ID5:]], ![[#ID6:]], ![[#ID7:]]}
140142
; CHECK-RT-NOT: !sycl.specialization-constants-default-values
141143
;
142-
; CHECK: ![[#ID0]] = !{!"_ZTS14name_generatorIL_Z9id_doubleEE", i32 0, i32 0, i32 8}
144+
; CHECK: ![[#ID0]] = !{!"_ZTS14name_generatorIL_Z9id_halfEE", i32 0, i32 0, i32 2}
143145
; CHECK: ![[#ID1]] = !{!"_ZTS14name_generatorIL_Z6id_intEE", i32 1, i32 0, i32 4}
144146
;
145147
; For composite types, the amount of metadata is a bit different between native and emulated spec constants
@@ -156,7 +158,7 @@ attributes #3 = { nounwind }
156158
; CHECK-RT-SAME: i32 [[#SCID8]], i32 8, i32 4,
157159
; CHECK-RT-SAME: i32 [[#SCID9]], i32 16, i32 8}
158160
;
159-
; CHECK-DEF: ![[#ID4]] = !{double 3.140000e+00}
161+
; CHECK-DEF: ![[#ID4]] = !{half 0xH4000}
160162
; CHECK-DEF: ![[#ID5]] = !{i32 42}
161163
; CHECK-DEF: ![[#ID6]] = !{%struct.ComposConst { i32 1, double 2.000000e+00, %struct.myConst { i32 13, float 0x4020666660000000 } }}
162164
; CHECK-DEF: ![[#ID7]] = !{%struct.ComposConst2 { i8 1, %struct.myConst { i32 52, float 0x40479999A0000000 }, double 2.000000e+00 }}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ std::string manglePrimitiveType(const Type *T) {
174174
return "f";
175175
if (T->isDoubleTy())
176176
return "d";
177+
if (T->isHalfTy())
178+
return "Dh";
177179
if (T->isIntegerTy()) {
178180
switch (T->getIntegerBitWidth()) {
179181
case 1:

0 commit comments

Comments
 (0)