Fix case when Phi variable is a loop variable.

Need to flush variable to static expression rather than a variable.
This commit is contained in:
Hans-Kristian Arntzen 2017-09-25 10:15:17 +02:00
parent 860f8970e5
commit 3339fd4e87
3 changed files with 100 additions and 1 deletions

View File

@ -0,0 +1,9 @@
#version 450
void main()
{
for (int _22 = 35; _22 >= 0; _22--)
{
}
}

View File

@ -0,0 +1,71 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 1
; Bound: 59
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main"
OpExecutionMode %4 OriginUpperLeft
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%_ptr_Function_mat2v2float = OpTypePointer Function %mat2v2float
%v3float = OpTypeVector %float 3
%11 = OpTypeFunction %v3float %_ptr_Function_mat2v2float
%_ptr_Function_v3float = OpTypePointer Function %v3float
%float_1 = OpConstant %float 1
%18 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%int_35 = OpConstant %int 35
%int_0 = OpConstant %int 0
%bool = OpTypeBool
%int_1 = OpConstant %int 1
%4 = OpFunction %void None %3
%5 = OpLabel
OpBranch %48
%48 = OpLabel
%58 = OpPhi %int %int_35 %5 %56 %50
OpLoopMerge %49 %50 None
OpBranch %51
%51 = OpLabel
%53 = OpSGreaterThanEqual %bool %58 %int_0
OpBranchConditional %53 %54 %49
%54 = OpLabel
OpBranch %50
%50 = OpLabel
%56 = OpISub %int %58 %int_1
OpBranch %48
%49 = OpLabel
OpReturn
OpFunctionEnd
%13 = OpFunction %v3float None %11
%12 = OpFunctionParameter %_ptr_Function_mat2v2float
%14 = OpLabel
%16 = OpVariable %_ptr_Function_v3float Function
%21 = OpVariable %_ptr_Function_int Function
OpStore %16 %18
OpStore %21 %int_35
OpBranch %23
%23 = OpLabel
OpLoopMerge %25 %26 None
OpBranch %27
%27 = OpLabel
%28 = OpLoad %int %21
%31 = OpSGreaterThanEqual %bool %28 %int_0
OpBranchConditional %31 %24 %25
%24 = OpLabel
OpBranch %26
%26 = OpLabel
%32 = OpLoad %int %21
%34 = OpISub %int %32 %int_1
OpStore %21 %34
OpBranch %23
%25 = OpLabel
%35 = OpLoad %v3float %16
OpReturnValue %35
OpFunctionEnd

View File

@ -6815,8 +6815,27 @@ void CompilerGLSL::flush_phi(uint32_t from, uint32_t to)
auto &child = get<SPIRBlock>(to);
for (auto &phi : child.phi_variables)
{
if (phi.parent == from)
statement(to_expression(phi.function_variable), " = ", to_expression(phi.local_variable), ";");
{
auto &var = get<SPIRVariable>(phi.function_variable);
// A Phi variable might be a loop variable, so flush to static expression.
if (var.loop_variable && !var.loop_variable_enable)
var.static_expression = phi.local_variable;
else
{
flush_variable_declaration(phi.function_variable);
// This might be called in continue block, so make sure we
// this to emit ESSL 1.0 compliant increments/decrements.
auto lhs = to_expression(phi.function_variable);
auto rhs = to_expression(phi.local_variable);
if (!optimize_read_modify_write(lhs, rhs))
statement(lhs, " = ", rhs, ";");
}
}
}
}
void CompilerGLSL::branch(uint32_t from, uint32_t to)