Skip to content

Commit d486cf4

Browse files
committed
Revert "[SPIRV] Use copy-in/copy-out for non-declaration (#7127)"
This did not solve all of the cases for the issue it was fixing. A new fix was done in the inliner in spirv-opt. This change is no longer needed. This reverts commit 8967dac.
1 parent 6475f98 commit d486cf4

7 files changed

+21
-52
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -3104,12 +3104,6 @@ SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
31043104
argInfo && argInfo->getStorageClass() != spv::StorageClass::Function &&
31053105
isResourceType(paramType);
31063106

3107-
// HLSL requires that the parameters be copied in and out from temporaries.
3108-
// This looks for cases where the copy can be elided. To generate valid
3109-
// SPIR-V, the argument must be a memory declaration.
3110-
//
3111-
//
3112-
31133107
// If argInfo is nullptr and argInst is a rvalue, we do not have a proper
31143108
// pointer to pass to the function. we need a temporary variable in that
31153109
// case.
@@ -3118,7 +3112,7 @@ SpirvInstruction *SpirvEmitter::processCall(const CallExpr *callExpr) {
31183112
// create a temporary variable for it because the function definition
31193113
// expects are point-to-pointer argument for resources, which will be
31203114
// resolved by legalization.
3121-
if ((argInfo || (argInst && argInst->getopcode() == spv::Op::OpVariable)) &&
3115+
if ((argInfo || (argInst && !argInst->isRValue())) &&
31223116
canActAsOutParmVar(param) && !isArgGlobalVarWithResourceType &&
31233117
paramTypeMatchesArgType(paramType, arg->getType())) {
31243118
// Based on SPIR-V spec, function parameter must be always Function

tools/clang/test/CodeGenSPIRV/cs.groupshared.function-param.out.hlsl

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ groupshared S D;
2828
[numthreads(1,1,1)]
2929
void main() {
3030
// CHECK: %E = OpVariable %_ptr_Function_int Function
31-
// CHECK-NEXT: [[TempVar:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_int Function
32-
3331
int E;
3432

3533
// CHECK: [[A:%[0-9]+]] = OpAccessChain %_ptr_Uniform_int %A %int_0 %uint_0
36-
// CHECK-NEXT: [[ld:%[0-9]+]] = OpLoad %int [[A]]
37-
// CHECK-NEXT: OpStore [[TempVar]] [[ld]]
38-
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %foo [[TempVar]] %B %C %D %E
34+
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %foo [[A]] %B %C %D %E
3935
foo(A[0], B, C, D, E);
4036
A[0] = A[0] | B | C | D.a | E;
4137
}

tools/clang/test/CodeGenSPIRV/fn.fixfuncall-compute.hlsl

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ float4 foo(inout float f0, inout int f1)
77
return 0;
88
}
99

10-
// CHECK-DAG: [[s39:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_int Function
11-
// CHECK-DAG: [[s36:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_float Function
10+
// CHECK: [[s39:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_int Function
11+
// CHECK: [[s36:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_float Function
1212
// CHECK: [[s33:%[a-zA-Z0-9_]+]] = OpAccessChain %_ptr_Uniform_float {{%[a-zA-Z0-9_]+}} %int_0
13+
// CHECK: [[s34:%[a-zA-Z0-9_]+]] = OpAccessChain %_ptr_Function_int {{%[a-zA-Z0-9_]+}} %int_1
1314
// CHECK: [[s37:%[a-zA-Z0-9_]+]] = OpLoad %float [[s33]]
1415
// CHECK: OpStore [[s36]] [[s37]]
15-
// CHECK: [[s34:%[a-zA-Z0-9_]+]] = OpAccessChain %_ptr_Function_int {{%[a-zA-Z0-9_]+}} %int_1
1616
// CHECK: [[s40:%[a-zA-Z0-9_]+]] = OpLoad %int [[s34]]
1717
// CHECK: OpStore [[s39]] [[s40]]
1818
// CHECK: {{%[a-zA-Z0-9_]+}} = OpFunctionCall %v4float %foo [[s36]] [[s39]]
19-
// CHECK: [[s38:%[a-zA-Z0-9_]+]] = OpLoad %float [[s36]]
20-
// CHECK: OpStore [[s33]] [[s38]]
2119
// CHECK: [[s41:%[a-zA-Z0-9_]+]] = OpLoad %int [[s39]]
2220
// CHECK: OpStore [[s34]] [[s41]]
21+
// CHECK: [[s38:%[a-zA-Z0-9_]+]] = OpLoad %float [[s36]]
22+
// CHECK: OpStore [[s33]] [[s38]]
2323

2424
struct Stru {
2525
int x;

tools/clang/test/CodeGenSPIRV/fn.fixfuncall-linkage.hlsl

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ RWStructuredBuffer< float4 > output : register(u1);
66

77
// CHECK: OpDecorate %main LinkageAttributes "main" Export
88
// CHECK: %main = OpFunction %int None
9-
// CHECK: [[s36:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_float Function
109
// CHECK: [[s39:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_int Function
10+
// CHECK: [[s36:%[a-zA-Z0-9_]+]] = OpVariable %_ptr_Function_float Function
1111
// CHECK: [[s33:%[a-zA-Z0-9_]+]] = OpAccessChain %_ptr_StorageBuffer_float {{%[a-zA-Z0-9_]+}} %int_0
12+
// CHECK: [[s34:%[a-zA-Z0-9_]+]] = OpAccessChain %_ptr_Function_int %stru %int_1
1213
// CHECK: [[s37:%[a-zA-Z0-9_]+]] = OpLoad %float [[s33]]
1314
// CHECK: OpStore [[s36]] [[s37]]
14-
// CHECK: [[s34:%[a-zA-Z0-9_]+]] = OpAccessChain %_ptr_Function_int %stru %int_1
1515
// CHECK: [[s40:%[a-zA-Z0-9_]+]] = OpLoad %int [[s34]]
1616
// CHECK: OpStore [[s39]] [[s40]]
1717
// CHECK: {{%[a-zA-Z0-9_]+}} = OpFunctionCall %void %func [[s36]] [[s39]]
18-
// CHECK: [[s38:%[a-zA-Z0-9_]+]] = OpLoad %float [[s36]]
19-
// CHECK: OpStore [[s33]] [[s38]]
2018
// CHECK: [[s41:%[a-zA-Z0-9_]+]] = OpLoad %int [[s39]]
2119
// CHECK: OpStore [[s34]] [[s41]]
20+
// CHECK: [[s38:%[a-zA-Z0-9_]+]] = OpLoad %float [[s36]]
21+
// CHECK: OpStore [[s33]] [[s38]]
2222

2323
[noinline]
2424
void func(inout float f0, inout int f1) {

tools/clang/test/CodeGenSPIRV/fn.param.inout.storage-class.hlsl

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ void main(float input : INPUT) {
1111
// CHECK: %param_var_a = OpVariable %_ptr_Function_float Function
1212

1313
// CHECK: [[val:%[0-9]+]] = OpLoad %float %input
14-
// CHECK: OpStore %param_var_a [[val]]
14+
// CHECK: OpStore %param_var_a [[val]]
1515
// CHECK: [[p0:%[0-9]+]] = OpAccessChain %_ptr_Uniform_float %Data %int_0 %uint_0
16-
// CHECK-NEXT: [[ld:%[0-9]+]] = OpLoad %float [[p0]]
17-
// CHECK-NEXT: OpStore [[temp0:%[a-zA-Z0-9_]+]] [[ld]]
1816
// CHECK: [[p1:%[0-9]+]] = OpAccessChain %_ptr_Uniform_float %Data %int_0 %uint_1
19-
// CHECK-NEXT: [[ld:%[0-9]+]] = OpLoad %float %32
20-
// CHECK-NEXT: OpStore [[temp1:%[a-zA-Z0-9_]+]] [[ld]]
21-
// CHECK: OpFunctionCall %void %foo %param_var_a [[temp0]] [[temp1]]
17+
18+
// CHECK: OpFunctionCall %void %foo %param_var_a [[p0]] [[p1]]
2219
foo(input, Data[0], Data[1]);
2320
}

tools/clang/test/CodeGenSPIRV/fn.param.inout.vector.hlsl

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ float4 main() : C {
1818

1919
float4 val;
2020
// CHECK: [[z_ptr:%[0-9]+]] = OpAccessChain %_ptr_Function_float %val %int_2
21-
// CHECK: [[ld:%[0-9]+]] = OpLoad %float [[z_ptr]]
22-
// CHECK: OpStore %param_var_w [[ld]]
23-
// CHECK: {{%[0-9]+}} = OpFunctionCall %void %bar %val %param_var_y %param_var_z %param_var_w
21+
// CHECK: {{%[0-9]+}} = OpFunctionCall %void %bar %val %param_var_y %param_var_z [[z_ptr]]
2422
// CHECK-NEXT: [[y:%[0-9]+]] = OpLoad %v3float %param_var_y
2523
// CHECK-NEXT: [[old:%[0-9]+]] = OpLoad %v4float %val
2624
// Write to val.zwx:
@@ -39,10 +37,6 @@ float4 main() : C {
3937
// CHECK-NEXT: [[old_0:%[0-9]+]] = OpLoad %v4float %val
4038
// CHECK-NEXT: [[new_0:%[0-9]+]] = OpVectorShuffle %v4float [[old_0]] [[z]] 4 5 2 3
4139
// CHECK-NEXT: OpStore %val [[new_0]]
42-
// Write to val.z:
43-
// CHECK-NEXT: [[new:%[0-9]+]] = OpLoad %float %param_var_w
44-
// CHECK-NEXT: OpStore [[z_ptr]] [[new]]
45-
4640
bar(val, val.zwx, val.xy, val.z);
4741

4842
return MyRWBuffer[0];

tools/clang/test/CodeGenSPIRV/fn.param.isomorphism.hlsl

+6-18
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ void main() {
6262
fn.incr();
6363

6464
// CHECK: [[rwsb_0:%[0-9]+]] = OpAccessChain %_ptr_Uniform_R %rwsb %int_0 %uint_0
65-
// CHECK-NEXT: [[ld:%[0-9]+]] = OpLoad %R [[rwsb_0]]
66-
// CHECK-NEXT: [[ex:%[0-9]+]] = OpCompositeExtract %int [[ld]] 0
67-
// CHECK-NEXT: [[v:%[0-9]+]] = OpCompositeConstruct %R_0 [[ex]]
68-
// CHECK-NEXT: OpStore [[TempVar:%[a-zA-Z0-9_]+]] [[v]]
69-
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr [[TempVar]]
65+
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr [[rwsb_0]]
7066
decr(rwsb[0]);
7167

7268
// CHECK: OpFunctionCall %void %decr2 %gs
@@ -91,29 +87,21 @@ void main() {
9187
fnarr[0].incr();
9288

9389
// CHECK: [[gsarr_0:%[0-9]+]] = OpAccessChain %_ptr_Workgroup_S %gsarr %int_0
94-
// CHECK: [[ld:%[0-9]+]] = OpLoad %S [[gsarr_0]]
95-
// CHECK: OpStore [[TempVar:%[a-zA-Z0-9_]+]] [[ld]]
96-
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr2 [[TempVar]]
90+
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr2 [[gsarr_0]]
9791
decr2(gsarr[0]);
9892

9993
// CHECK: [[starr_0:%[0-9]+]] = OpAccessChain %_ptr_Private_S %starr %int_0
100-
// CHECK: [[ld:%[0-9]+]] = OpLoad %S [[starr_0]]
101-
// CHECK: OpStore [[TempVar:%[a-zA-Z0-9_]+]] [[ld]]
102-
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr2 [[TempVar]]
94+
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr2 [[starr_0]]
10395
decr2(starr[0]);
10496

10597
// CHECK: [[fnarr_0:%[0-9]+]] = OpAccessChain %_ptr_Function_S %fnarr %int_0
106-
// CHECK: [[ld:%[0-9]+]] = OpLoad %S [[fnarr_0]]
107-
// CHECK: OpStore [[TempVar:%[a-zA-Z0-9_]+]] [[ld]]
108-
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr2 [[TempVar]]
98+
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %decr2 [[fnarr_0]]
10999
decr2(fnarr[0]);
110100

111101
// CHECK: [[arr:%[0-9]+]] = OpAccessChain %_ptr_Function_int %arr %int_0
112102
// CHECK-NEXT: [[arr_0:%[0-9]+]] = OpLoad %int [[arr]]
113103
// CHECK-NEXT: [[arr_1:%[0-9]+]] = OpIAdd %int [[arr_0]] %int_1
114-
// CHECK-NEXT: OpStore [[arr]] [[arr_1]]
115-
// CHECK-NEXT: [[ld:%[0-9]+]] = OpLoad %int [[arr]]
116-
// CHECK-NEXT: OpStore [[TempVar:%[0-9a-zA-Z_]+]] [[ld]]
117-
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %int_decr [[TempVar]]
104+
// CHECK-NEXT: OpStore [[arr]] [[arr_1]]
105+
// CHECK-NEXT: {{%[0-9]+}} = OpFunctionCall %void %int_decr [[arr]]
118106
int_decr(++arr[0]);
119107
}

0 commit comments

Comments
 (0)