-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[HLSL] Make bool in hlsl i32 #122977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HLSL] Make bool in hlsl i32 #122977
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-hlsl Author: Sarah Spall (spall) Changesmake a bool's memory representation i32 in hlsl Full diff: https://github.com/llvm/llvm-project/pull/122977.diff 3 Files Affected:
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 86befb1cbc74fc..c0bf4e686cf03c 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -425,6 +425,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
// HLSL explicitly defines the sizes and formats of some data types, and we
// need to conform to those regardless of what architecture you are targeting.
if (Opts.HLSL) {
+ BoolWidth = BoolAlign = 32;
LongWidth = LongAlign = 64;
if (!Opts.NativeHalfType) {
HalfFormat = &llvm::APFloat::IEEEsingle();
diff --git a/clang/test/CodeGenHLSL/Bool.hlsl b/clang/test/CodeGenHLSL/Bool.hlsl
new file mode 100644
index 00000000000000..fb0f32b11241d4
--- /dev/null
+++ b/clang/test/CodeGenHLSL/Bool.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+
+// CHECK-LABEL: define noundef i1 {{.*}}fn{{.*}}(i1 noundef %x)
+// CHECK: [[X:%.*]] = alloca i32, align 4
+// CHECK-NEXT: [[Y:%.*]] = zext i1 {{%.*}} to i32
+// CHECK-NEXT: store i32 [[Y]], ptr [[X]], align 4
+// CHECK-NEXT: [[Z:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT: [[L:%.*]] = trunc i32 [[Z]] to i1
+// CHECK-NEXT: ret i1 [[L]]
+bool fn(bool x) {
+ return x;
+}
diff --git a/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl
index c2dd9e272e0937..f5f223943b4cdd 100644
--- a/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl
@@ -24,12 +24,3 @@ float test_float_half(half p1) {
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: could not match 'vector<half, N>' against 'half'}}
// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: substitution failure [with U = float, T = half]: no type named 'Type'}}
}
-
-
-float test_float_half(bool p1) {
- return asfloat(p1);
- // expected-error@hlsl/hlsl_intrinsics.h:* {{no matching function for call to 'bit_cast'}}
- // expected-note@-2 {{in instantiation of function template specialization 'hlsl::asfloat<bool>'}}
- // expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: could not match 'vector<bool, N>' against 'bool'}}
- // expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: substitution failure [with U = float, T = bool]: no type named 'Type'}}
-}
|
|
||
|
||
float test_float_half(bool p1) { | ||
return asfloat(p1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably, now that p1 is 32 bits, it can be cast to an int for asfloat, so this doesn't emit any errors, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah no errors were being emitted, causing the old test to fail (due to lack of errors).
make a bool's memory representation i32 in hlsl
add new test
fix broken test
Closes #122932