Skip to content

Commit 19b4465

Browse files
committed
[SYCL] Restore missing 'signed char' SPIR-V builtins
A previous change 23584c1 inadvertently removed SPIR-V builtins for signed char types. Fixing this uncovered several missing builtins for regular 'char' types, too. This commit re-introduces SPIR-V builtins for all three char types where appropriate. It also fixes the codegen for several cases, as seen in the clang tests where 'char' types were previously being unnecessarily promoted to int.
1 parent 3a0acb8 commit 19b4465

File tree

4 files changed

+111
-88
lines changed

4 files changed

+111
-88
lines changed

clang/lib/Sema/SPIRVBuiltins.td

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ class ConstOCLSPVBuiltin<string _Name, list<Type> _Signature> :
321321

322322
// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
323323
def Bool : IntType<"bool", QualType<"Context.BoolTy">, 1>;
324-
def TrueChar : IntType<"_char", QualType<"Context.CharTy", 0, 1>, 8>;
325-
def Char : IntType<"char", QualTypeFromFunction<"GetCharType", 0, 1>, 8>;
324+
def Char : IntType<"char", QualType<"Context.CharTy", 0, 1>, 8>;
325+
def SChar : IntType<"schar", QualType<"Context.SignedCharTy", 0, 1>, 8>;
326326
def UChar : UIntType<"uchar", QualType<"Context.UnsignedCharTy">, 8>;
327327
def Short : IntType<"short", QualType<"Context.ShortTy", 0, 1>, 16>;
328328
def UShort : UIntType<"ushort", QualType<"Context.UnsignedShortTy">, 16>;
@@ -355,19 +355,20 @@ def Vec16 : IntList<"Vec16", [16]>;
355355
def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
356356

357357
// Type lists.
358-
def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
359-
def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
360-
def TLAllWithBool : TypeList<[Bool, Char, UChar, Short, UShort, Int, UInt, Long,
358+
def TLAll : TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
359+
def TLAllUnsigned : TypeList<[UChar, UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
360+
def TLAllWithBool : TypeList<[Bool, Char, SChar, UChar, Short, UShort, Int, UInt, Long,
361361
ULong, Float, Double, Half]>;
362362
def TLFloat : TypeList<[Float, Double, Half]>;
363363
// FIXME: handle properly char (signed or unsigned depending on host)
364-
def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
365-
def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
364+
def TLSignedInts : TypeList<[Char, SChar, Short, Int, Long]>;
365+
def TLUIToSIInts : TypeList<[UChar, UChar, UShort, UInt, ULong]>;
366+
def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
366367

367368
// Signed to Unsigned conversion
368369
// FIXME: handle properly char (signed or unsigned depending on host)
369-
def TLSToUSignedInts : TypeList<[Char, Short, Int, Long]>;
370-
def TLSToUUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
370+
def TLSToUSignedInts : TypeList<[Char, SChar, Short, Int, Long]>;
371+
def TLSToUUnsignedInts : TypeList<[UChar, UChar, UShort, UInt, ULong]>;
371372

372373
def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
373374

@@ -376,7 +377,7 @@ def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
376377
// uchar abs(uchar).
377378
def TLAllUIntsTwice : TypeList<[UChar, UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
378379

379-
def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
380+
def TLAllInts : TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong]>;
380381

381382
// GenType definitions for multiple base types (e.g. all floating point types,
382383
// or all integer types).
@@ -393,6 +394,8 @@ def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
393394
def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
394395
def AUIGenTypeN : GenericType<"AUIGenTypeN", TLUnsignedInts, VecAndScalar>;
395396
def ASIGenTypeN : GenericType<"ASIGenTypeN", TLSignedInts, VecAndScalar>;
397+
// unsigned integers matching 1:1 with signed ints
398+
def AUIToSIGenTypeN : GenericType<"AUIToSIGenTypeN", TLUIToSIInts, VecAndScalar>;
396399
def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
397400
// All integer to unsigned
398401
def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
@@ -402,6 +405,7 @@ def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar
402405
// Unsigned integer
403406
def UGenType1 : GenericType<"UGenType1", TLUnsignedInts, Vec1>;
404407
def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
408+
def UToSGenTypeN : GenericType<"UToSGenTypeN", TLUIToSIInts, VecAndScalar>;
405409
def UInt4 : GenericType<"UInt4", TypeList<[UInt]>, Vec4>;
406410
// Float
407411
def FGenType1 : GenericType<"FGenType1", TLFloat, Vec1>;
@@ -411,7 +415,7 @@ def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats
411415

412416
// GenType definitions for every single base type (e.g. fp32 only).
413417
// Names are like: GenTypeFloatVecAndScalar.
414-
foreach Type = [Char, UChar, Short, UShort,
418+
foreach Type = [Char, SChar, UChar, Short, UShort,
415419
Int, UInt, Long, ULong,
416420
Float, Double, Half] in {
417421
foreach VecSizes = [VecAndScalar, VecNoScalar] in {
@@ -549,9 +553,9 @@ foreach name = ["clz", "ctz", "popcount"] in {
549553

550554
def : ConstOCLSPVBuiltin<"rotate", [AIGenTypeN, AIGenTypeN, AIGenTypeN]>;
551555

552-
def : ConstOCLSPVBuiltin<"s_abs", [AUIGenTypeN, ASIGenTypeN]>;
556+
def : ConstOCLSPVBuiltin<"s_abs", [AUIToSIGenTypeN, ASIGenTypeN]>;
553557

554-
def : ConstOCLSPVBuiltin<"s_abs_diff", [AUIGenTypeN, ASIGenTypeN, ASIGenTypeN]>;
558+
def : ConstOCLSPVBuiltin<"s_abs_diff", [AUIToSIGenTypeN, ASIGenTypeN, ASIGenTypeN]>;
555559

556560
foreach name = ["s_add_sat",
557561
"s_hadd", "s_rhadd",
@@ -651,9 +655,9 @@ def : ConstOCLSPVBuiltin<"bitselect", [AGenTypeN, AGenTypeN, AGenTypeN, AGenType
651655

652656
foreach name = ["select"] in {
653657
def : ConstOCLSPVBuiltin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN]>;
654-
def : ConstOCLSPVBuiltin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN]>;
658+
def : ConstOCLSPVBuiltin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UToSGenTypeN]>;
655659
def : ConstOCLSPVBuiltin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN]>;
656-
def : ConstOCLSPVBuiltin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN]>;
660+
def : ConstOCLSPVBuiltin<name, [UToSGenTypeN, UToSGenTypeN, UToSGenTypeN, SGenTypeN]>;
657661
def : ConstOCLSPVBuiltin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar]>;
658662
def : ConstOCLSPVBuiltin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar]>;
659663
def : ConstOCLSPVBuiltin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar]>;
@@ -988,7 +992,7 @@ foreach name = ["GroupLogicalAndKHR", "GroupLogicalOrKHR"] in {
988992

989993
def SubgroupShuffleINTELVecType
990994
: GenericType<"SubgroupShuffleINTELVecType",
991-
TypeList<[Char, UChar, Short, UShort, Int, UInt, Float]>,
995+
TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Float]>,
992996
VecNoScalar>;
993997

994998
foreach name = ["SubgroupShuffleINTEL", "SubgroupShuffleXorINTEL"] in {

clang/lib/Sema/SemaLookup.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include <utility>
5252
#include <vector>
5353

54-
static inline clang::QualType GetCharType(clang::ASTContext &Context);
5554
static inline clang::QualType GetFloat16Type(clang::ASTContext &Context);
5655

5756
#include "OpenCLBuiltins.inc"
@@ -702,10 +701,6 @@ LLVM_DUMP_METHOD void LookupResult::dump() {
702701
D->dump();
703702
}
704703

705-
static inline QualType GetCharType(clang::ASTContext &Context) {
706-
return Context.getLangOpts().OpenCL ? Context.CharTy : Context.SignedCharTy;
707-
}
708-
709704
static inline QualType GetFloat16Type(clang::ASTContext &Context) {
710705
return Context.getLangOpts().OpenCL ? Context.HalfTy : Context.Float16Ty;
711706
}

clang/test/CodeGenSPIRV/spirv-builtin-lookup-group-non-uniform.cpp

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ template <class T> void test_logical() {
189189
void test() {
190190
test_with_bool<bool>();
191191
test_with_bool<char>();
192+
test_with_bool<signed char>();
192193
test_with_bool<unsigned char>();
193194
test_with_bool<short>();
194195
test_with_bool<unsigned short>();
@@ -199,13 +200,15 @@ void test() {
199200
test_with_bool<double>();
200201

201202
test_integer<char>();
203+
test_integer<signed char>();
202204
test_integer<unsigned char>();
203205
test_integer<short>();
204206
test_integer<unsigned short>();
205207
test_integer<int>();
206208
test_integer<unsigned int>();
207209

208210
test_signed<char>();
211+
test_signed<signed char>();
209212
test_signed<short>();
210213
test_signed<int>();
211214

@@ -232,13 +235,20 @@ void test() {
232235
// CHECK: call noundef zeroext i1 @_Z33__spirv_GroupNonUniformShuffleXoribj
233236
// CHECK: call noundef zeroext i1 @_Z32__spirv_GroupNonUniformShuffleUpibj
234237
// CHECK: call noundef zeroext i1 @_Z34__spirv_GroupNonUniformShuffleDownibj
235-
// CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualii
236-
// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBroadcastiij
237-
// CHECK: call noundef i32 @_Z37__spirv_GroupNonUniformBroadcastFirstii
238-
// CHECK: call noundef i32 @_Z30__spirv_GroupNonUniformShuffleiij
239-
// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformShuffleXoriij
240-
// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformShuffleUpiij
241-
// CHECK: call noundef i32 @_Z34__spirv_GroupNonUniformShuffleDowniij
238+
// CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualic
239+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBroadcasticj
240+
// CHECK: call noundef signext i8 @_Z37__spirv_GroupNonUniformBroadcastFirstic
241+
// CHECK: call noundef signext i8 @_Z30__spirv_GroupNonUniformShuffleicj
242+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformShuffleXoricj
243+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformShuffleUpicj
244+
// CHECK: call noundef signext i8 @_Z34__spirv_GroupNonUniformShuffleDownicj
245+
// CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualia
246+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBroadcastiaj
247+
// CHECK: call noundef signext i8 @_Z37__spirv_GroupNonUniformBroadcastFirstia
248+
// CHECK: call noundef signext i8 @_Z30__spirv_GroupNonUniformShuffleiaj
249+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformShuffleXoriaj
250+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformShuffleUpiaj
251+
// CHECK: call noundef signext i8 @_Z34__spirv_GroupNonUniformShuffleDowniaj
242252
// CHECK: call noundef zeroext i1 @_Z31__spirv_GroupNonUniformAllEqualih
243253
// CHECK: call noundef zeroext i8 @_Z32__spirv_GroupNonUniformBroadcastihj
244254
// CHECK: call noundef zeroext i8 @_Z37__spirv_GroupNonUniformBroadcastFirstih
@@ -295,16 +305,26 @@ void test() {
295305
// CHECK: call noundef double @_Z33__spirv_GroupNonUniformShuffleXoridj
296306
// CHECK: call noundef double @_Z32__spirv_GroupNonUniformShuffleUpidj
297307
// CHECK: call noundef double @_Z34__spirv_GroupNonUniformShuffleDownidj
298-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIAddiii
299-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIAddiiij
300-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIMuliii
301-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformIMuliiij
302-
// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseAndiii
303-
// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseAndiiij
304-
// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBitwiseOriii
305-
// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBitwiseOriiij
306-
// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriii
307-
// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriiij
308+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiic
309+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiicj
310+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliic
311+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliicj
312+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiic
313+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiicj
314+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriic
315+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriicj
316+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriic
317+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriicj
318+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiia
319+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIAddiiaj
320+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliia
321+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformIMuliiaj
322+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiia
323+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseAndiiaj
324+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriia
325+
// CHECK: call noundef signext i8 @_Z32__spirv_GroupNonUniformBitwiseOriiaj
326+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriia
327+
// CHECK: call noundef signext i8 @_Z33__spirv_GroupNonUniformBitwiseXoriiaj
308328
// CHECK: call noundef zeroext i8 @_Z27__spirv_GroupNonUniformIAddiih
309329
// CHECK: call noundef zeroext i8 @_Z27__spirv_GroupNonUniformIAddiihj
310330
// CHECK: call noundef zeroext i8 @_Z27__spirv_GroupNonUniformIMuliih
@@ -355,10 +375,14 @@ void test() {
355375
// CHECK: call noundef i32 @_Z32__spirv_GroupNonUniformBitwiseOriijj
356376
// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriij
357377
// CHECK: call noundef i32 @_Z33__spirv_GroupNonUniformBitwiseXoriijj
358-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMiniii
359-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMiniiij
360-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMaxiii
361-
// CHECK: call noundef i32 @_Z27__spirv_GroupNonUniformSMaxiiij
378+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniic
379+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniicj
380+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiic
381+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiicj
382+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniia
383+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMiniiaj
384+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiia
385+
// CHECK: call noundef signext i8 @_Z27__spirv_GroupNonUniformSMaxiiaj
362386
// CHECK: call noundef signext i16 @_Z27__spirv_GroupNonUniformSMiniis
363387
// CHECK: call noundef signext i16 @_Z27__spirv_GroupNonUniformSMiniisj
364388
// CHECK: call noundef signext i16 @_Z27__spirv_GroupNonUniformSMaxiis

0 commit comments

Comments
 (0)