[PATCH] D133668: [HLSL] Disable int16_t to avoid promote to int for HLSL.
Xiang Li via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 18 16:07:46 PDT 2022
python3kgae updated this revision to Diff 468731.
python3kgae marked an inline comment as done.
python3kgae added a comment.
Update comment and fix tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133668/new/
https://reviews.llvm.org/D133668
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGenHLSL/builtins/abs.hlsl
clang/test/CodeGenHLSL/no_int_promotion.hlsl
clang/test/SemaHLSL/BitInt128.hlsl
Index: clang/test/SemaHLSL/BitInt128.hlsl
===================================================================
--- /dev/null
+++ clang/test/SemaHLSL/BitInt128.hlsl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s -verify
+
+// expected-error at +1 {{_BitInt is not supported on this target}}
+_BitInt(128) i128;
+
+// expected-error at +1 {{_BitInt is not supported on this target}}
+unsigned _BitInt(128) u128;
Index: clang/test/CodeGenHLSL/no_int_promotion.hlsl
===================================================================
--- /dev/null
+++ clang/test/CodeGenHLSL/no_int_promotion.hlsl
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN: dxil-pc-shadermodel6.3-library %s -D__HLSL_ENABLE_16_BIT \
+// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+
+// FIXME: add test for char/int8_t/uint8_t when these types are supported in HLSL.
+// See https://github.com/llvm/llvm-project/issues/58453.
+
+// Make sure generate i16 add.
+// CHECK: add nsw i16 %
+int16_t add(int16_t a, int16_t b) {
+ return a + b;
+}
+// CHECK: define noundef <2 x i16> @
+// CHECK: add <2 x i16>
+int16_t2 add(int16_t2 a, int16_t2 b) {
+ return a + b;
+}
+// CHECK: define noundef <3 x i16> @
+// CHECK: add <3 x i16>
+int16_t3 add(int16_t3 a, int16_t3 b) {
+ return a + b;
+}
+// CHECK: define noundef <4 x i16> @
+// CHECK: add <4 x i16>
+int16_t4 add(int16_t4 a, int16_t4 b) {
+ return a + b;
+}
+// CHECK: define noundef zeroext i16 @
+// CHECK: add i16 %
+uint16_t add(uint16_t a, uint16_t b) {
+ return a + b;
+}
+// CHECK: define noundef <2 x i16> @
+// CHECK: add <2 x i16>
+uint16_t2 add(uint16_t2 a, uint16_t2 b) {
+ return a + b;
+}
+// CHECK: define noundef <3 x i16> @
+// CHECK: add <3 x i16>
+uint16_t3 add(uint16_t3 a, uint16_t3 b) {
+ return a + b;
+}
+// CHECK: define noundef <4 x i16> @
+// CHECK: add <4 x i16>
+uint16_t4 add(uint16_t4 a, uint16_t4 b) {
+ return a + b;
+}
Index: clang/test/CodeGenHLSL/builtins/abs.hlsl
===================================================================
--- clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -7,8 +7,7 @@
// CHECK: define noundef signext i16 @
-// FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed.
-// CHECK: call i32 @llvm.abs.i32(
+// CHECK: call i16 @llvm.abs.i16(
int16_t test_abs_int16_t ( int16_t p0 ) {
return abs ( p0 );
}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -837,7 +837,10 @@
E = ImpCastExprToType(E, PTy, CK_IntegralCast).get();
return E;
}
- if (Ty->isPromotableIntegerType()) {
+ if (Ty->isPromotableIntegerType() &&
+ // HLSL doesn't promote all small integer types to int, it
+ // just uses the rank-based promotion rules for all types.
+ !getLangOpts().HLSL) {
QualType PT = Context.getPromotedIntegerType(Ty);
E = ImpCastExprToType(E, PT, CK_IntegralCast).get();
return E;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133668.468731.patch
Type: text/x-patch
Size: 3129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221018/fe485de1/attachment.bin>
More information about the cfe-commits
mailing list