[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
Sun Sep 11 06:05:38 PDT 2022
python3kgae created this revision.
python3kgae added reviewers: beanz, pow2clk, Anastasia, aaron.ballman, bogner.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
short will be promited to int in UsualUnaryConversions.
To avoid it, switch to _BitInt(16) for int16_t.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133668
Files:
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/Basic/Targets/DirectX.h
clang/lib/Headers/hlsl/hlsl_basic_types.h
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/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
@@ -63,6 +63,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";
}
Index: clang/lib/AST/MicrosoftMangle.cpp
===================================================================
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -3073,14 +3073,17 @@
void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals,
SourceRange Range) {
- const BuiltinType *ET = T->getElementType()->getAs<BuiltinType>();
- assert(ET && "vectors with non-builtin elements are unsupported");
+ QualType EltTy = T->getElementType();
+ const BuiltinType *ET = EltTy->getAs<BuiltinType>();
+ const BitIntType *BitIntTy = EltTy->getAs<BitIntType>();
+ assert((ET || BitIntTy) &&
+ "vectors with non-builtin/_BitInt elements are unsupported");
uint64_t Width = getASTContext().getTypeSize(T);
// Pattern match exactly the typedefs in our intrinsic headers. Anything that
// doesn't match the Intel types uses a custom mangling below.
size_t OutSizeBefore = Out.tell();
if (!isa<ExtVectorType>(T)) {
- if (getASTContext().getTargetInfo().getTriple().isX86()) {
+ if (getASTContext().getTargetInfo().getTriple().isX86() && ET) {
if (Width == 64 && ET->getKind() == BuiltinType::LongLong) {
mangleArtificialTagType(TTK_Union, "__m64");
} else if (Width >= 128) {
@@ -3105,7 +3108,11 @@
MicrosoftCXXNameMangler Extra(Context, Stream);
Stream << "?$";
Extra.mangleSourceName("__vector");
- Extra.mangleType(QualType(ET, 0), Range, QMM_Escape);
+ if (ET)
+ Extra.mangleType(QualType(ET, 0), Range, QMM_Escape);
+ else
+ Extra.mangleType(QualType(BitIntTy, 0), Range, QMM_Escape);
+
Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumElements()));
mangleArtificialTagType(TTK_Union, TemplateMangling, {"__clang"});
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133668.459358.patch
Type: text/x-patch
Size: 3609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220911/c367f5b5/attachment.bin>
More information about the cfe-commits
mailing list