[PATCH] D133668: [HLSL] Use _BitInt(16) for int16_t to avoid promote to int.

Xiang Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 19 10:04:21 PDT 2022


python3kgae updated this revision to Diff 461251.
python3kgae added a comment.

Rebase and update test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133668/new/

https://reviews.llvm.org/D133668

Files:
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_basic_types.h
  clang/test/CodeGenHLSL/basic_types.hlsl
  clang/test/CodeGenHLSL/builtins/abs.hlsl
  clang/test/CodeGenHLSL/int16_t_add.hlsl


Index: clang/test/CodeGenHLSL/int16_t_add.hlsl
===================================================================
--- /dev/null
+++ clang/test/CodeGenHLSL/int16_t_add.hlsl
@@ -0,0 +1,24 @@
+// 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
+
+// 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;
+}
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/test/CodeGenHLSL/basic_types.hlsl
===================================================================
--- clang/test/CodeGenHLSL/basic_types.hlsl
+++ clang/test/CodeGenHLSL/basic_types.hlsl
@@ -3,17 +3,17 @@
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
 
-// CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2
-// CHECK:"?int16_t_Val@@3FA" = global i16 0, align 2
+// CHECK:"?uint16_t_Val@@3U?$_UBitInt@$0BA@@__clang@@A" = global i16 0, align 2
+// CHECK:"?int16_t_Val@@3U?$_BitInt@$0BA@@__clang@@A" = global i16 0, align 2
 // CHECK:"?uint_Val@@3IA" = global i32 0, align 4
 // CHECK:"?uint64_t_Val@@3KA" = global i64 0, align 8
 // CHECK:"?int64_t_Val@@3JA" = global i64 0, align 8
-// CHECK:"?int16_t2_Val@@3T?$__vector at F$01 at __clang@@A" = global <2 x i16> zeroinitializer, align 4
-// CHECK:"?int16_t3_Val@@3T?$__vector at F$02 at __clang@@A" = global <3 x i16> zeroinitializer, align 8
-// CHECK:"?int16_t4_Val@@3T?$__vector at F$03 at __clang@@A" = global <4 x i16> zeroinitializer, align 8
-// CHECK:"?uint16_t2_Val@@3T?$__vector at G$01 at __clang@@A" = global <2 x i16> zeroinitializer, align 4
-// CHECK:"?uint16_t3_Val@@3T?$__vector at G$02 at __clang@@A" = global <3 x i16> zeroinitializer, align 8
-// CHECK:"?uint16_t4_Val@@3T?$__vector at G$03 at __clang@@A" = global <4 x i16> zeroinitializer, align 8
+// CHECK:"?int16_t2_Val@@3T?$__vector at U?$_BitInt@$0BA@@__clang@@$01 at __clang@@A" = global <2 x i16> zeroinitializer, align 4
+// CHECK:"?int16_t3_Val@@3T?$__vector at U?$_BitInt@$0BA@@__clang@@$02 at __clang@@A" = global <3 x i16> zeroinitializer, align 8
+// CHECK:"?int16_t4_Val@@3T?$__vector at U?$_BitInt@$0BA@@__clang@@$03 at __clang@@A" = global <4 x i16> zeroinitializer, align 8
+// CHECK:"?uint16_t2_Val@@3T?$__vector at U?$_UBitInt@$0BA@@__clang@@$01 at __clang@@A" = global <2 x i16> zeroinitializer, align 4
+// CHECK:"?uint16_t3_Val@@3T?$__vector at U?$_UBitInt@$0BA@@__clang@@$02 at __clang@@A" = global <3 x i16> zeroinitializer, align 8
+// CHECK:"?uint16_t4_Val@@3T?$__vector at U?$_UBitInt@$0BA@@__clang@@$03 at __clang@@A" = global <4 x i16> zeroinitializer, align 8
 // CHECK:"?int2_Val@@3T?$__vector at H$01 at __clang@@A" = global <2 x i32> zeroinitializer, align 8
 // CHECK:"?int3_Val@@3T?$__vector at H$02 at __clang@@A" = global <3 x i32> zeroinitializer, align 16
 // CHECK:"?int4_Val@@3T?$__vector at H$03 at __clang@@A" = global <4 x i32> zeroinitializer, align 16
Index: clang/lib/Headers/hlsl/hlsl_basic_types.h
===================================================================
--- clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -13,8 +13,8 @@
 
 #ifdef __HLSL_ENABLE_16_BIT
 // 16-bit integer.
-typedef unsigned short uint16_t;
-typedef short int16_t;
+typedef unsigned _BitInt(16) uint16_t;
+typedef _BitInt(16) int16_t;
 #endif
 
 // unsigned 32-bit integer.
Index: clang/lib/Basic/Targets/DirectX.h
===================================================================
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -65,6 +65,7 @@
   void getTargetDefines(const LangOptions &Opts,
                         MacroBuilder &Builder) const override;
 
+  bool hasBitIntType() const override { return true; }
   bool hasFeature(StringRef Feature) const override {
     return Feature == "directx";
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133668.461251.patch
Type: text/x-patch
Size: 4638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220919/006e6b5b/attachment.bin>


More information about the cfe-commits mailing list