-
Notifications
You must be signed in to change notification settings - Fork 15k
[HLSL][DirectX] Fix resource lowering when using structs with select
#158361
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
Conversation
@llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Kaitlin Peng (kmpeng) ChangesFixes #156550. The Full diff: https://github.com/llvm/llvm-project/pull/158361.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index 5004c09e0d5cf..7b5b924b1fe82 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -604,12 +604,12 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
Value *OpTrue =
RValTrue.isScalar()
? RValTrue.getScalarVal()
- : RValTrue.getAggregatePointer(E->getArg(1)->getType(), *this);
+ : Builder.CreateLoad(RValTrue.getAggregateAddress(), "true_val");
RValue RValFalse = EmitAnyExpr(E->getArg(2));
Value *OpFalse =
RValFalse.isScalar()
? RValFalse.getScalarVal()
- : RValFalse.getAggregatePointer(E->getArg(2)->getType(), *this);
+ : Builder.CreateLoad(RValFalse.getAggregateAddress(), "false_val");
if (auto *VTy = E->getType()->getAs<VectorType>()) {
if (!OpTrue->getType()->isVectorTy())
OpTrue =
diff --git a/clang/test/CodeGenHLSL/builtins/select.hlsl b/clang/test/CodeGenHLSL/builtins/select.hlsl
index 196b8a90cd877..a5a398af44646 100644
--- a/clang/test/CodeGenHLSL/builtins/select.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/select.hlsl
@@ -11,8 +11,10 @@ int test_select_bool_int(bool cond0, int tVal, int fVal) {
struct S { int a; };
// CHECK-LABEL: test_select_infer
-// CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, ptr {{%.*}}, ptr {{%.*}}
-// CHECK: store ptr [[SELECT]]
+// CHECK: [[TRUE_VAL:%.*]] = load %struct.S, ptr {{%.*}}, align 1
+// CHECK: [[FALSE_VAL:%.*]] = load %struct.S, ptr {{%.*}}, align 1
+// CHECK: [[SELECT:%.*]] = select i1 {{%.*}}, %struct.S [[TRUE_VAL]], %struct.S [[FALSE_VAL]]
+// CHECK: store %struct.S [[SELECT]], ptr {{%.*}}, align 1
// CHECK: ret void
struct S test_select_infer(bool cond0, struct S tVal, struct S fVal) {
return select(cond0, tVal, fVal);
|
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.
Can you add an array test?
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.
LGTM!
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.
lgtm
Fixes #156550.
The
select
instruction should be using the struct values themselves rather than pointers to temporary allocas.This PR also adds an array test for select in
select.hlsl
.