Skip to content

Commit f022290

Browse files
authored
Treat logical AND and OR as constant-fold-able (#9833)
The logical AND and logical OR should be treated as an IR that can be constant-fold-able.
1 parent dbe2768 commit f022290

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

source/slang/slang-ir-constexpr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ bool opCanBeConstExpr(IROp op)
9797
case kIROp_Less:
9898
case kIROp_Neq:
9999
case kIROp_Eql:
100+
case kIROp_And:
101+
case kIROp_Or:
100102
case kIROp_BitAnd:
101103
case kIROp_BitOr:
102104
case kIROp_BitXor:

source/slang/slang-ir-sccp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ struct SCCPContext
126126
case kIROp_Leq:
127127
case kIROp_Geq:
128128
case kIROp_Less:
129+
case kIROp_And:
130+
case kIROp_Or:
129131
case kIROp_IRem:
130132
case kIROp_FRem:
131133
case kIROp_Greater:

source/slang/slang-ir-specialize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ struct SpecializationContext
8989
case kIROp_Leq:
9090
case kIROp_Geq:
9191
case kIROp_Less:
92+
case kIROp_And:
93+
case kIROp_Or:
9294
case kIROp_IRem:
9395
case kIROp_FRem:
9496
case kIROp_Greater:

source/slang/slang-ir-util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,6 +2790,8 @@ bool canOperationBeSpecConst(IROp op, IRType* resultType, IRInst* const* fixedAr
27902790
case kIROp_Geq:
27912791
case kIROp_Less:
27922792
case kIROp_Greater:
2793+
case kIROp_And:
2794+
case kIROp_Or:
27932795
{
27942796
IRInst* operand1;
27952797
IRInst* operand2;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHK): -shaderobj -output-using-type
2+
3+
//TEST_INPUT:ubuffer(data=[1.0 2.0 3.0 4.0], stride=4):name=gInput
4+
RWStructuredBuffer<float> gInput;
5+
6+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutput
7+
RWStructuredBuffer<float> gOutput;
8+
9+
//CHK:1
10+
//CHK-NEXT:2
11+
//CHK-NEXT:3
12+
//CHK-NEXT:4
13+
14+
struct AppInput<bool COND0, int COND1>
15+
{
16+
float3 position;
17+
Conditional<float4, COND0 && (0 < COND1)> attr;
18+
};
19+
20+
[Shader("compute")]
21+
[NumThreads(4, 1, 1)]
22+
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
23+
{
24+
uint tid = dispatchThreadID.x;
25+
26+
AppInput<true, 1> t1;
27+
t1.attr.set(gInput[tid]);
28+
29+
if (let value = t1.attr.get())
30+
gOutput[tid] = value.x;
31+
}

0 commit comments

Comments
 (0)