Test case:
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 3
; Bound: 43
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %o
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 430
OpName %main "main"
OpName %U_t "U_t"
OpMemberName %U_t 0 "g_F"
OpName %_ ""
OpName %o "o"
OpDecorate %arr_float_uint_10 ArrayStride 4
OpMemberDecorate %U_t 0 Offset 0
OpDecorate %U_t BufferBlock
OpDecorate % DescriptorSet 0
OpDecorate %o Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Function_float = OpTypePointer Function %float
%float_0 = OpConstant %float 0
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%int_0 = OpConstant %int 0
%int_10 = OpConstant %int 10
%bool = OpTypeBool
%uint = OpTypeInt 32 0
%uint_10 = OpConstant %uint 10
%_arr_float_uint_10 = OpTypeArray %float %uint_10
%U_t = OpTypeStruct %_arr_float_uint_10
%ptr_Uniform_U_t = OpTypePointer Uniform %U_t
% = OpVariable %_ptr_Uniform_U_t Uniform
%_ptr_Uniform_float = OpTypePointer Uniform %float
%int_1 = OpConstant %int 1
%_ptr_Output_float = OpTypePointer Output %float
%o = OpVariable %_ptr_Output_float Output
%main = OpFunction %void None %3
%5 = OpLabel
OpBranch %14
%14 = OpLabel
%41 = OpPhi %float %float_0 %5 %34 %17
%42 = OpPhi %int %int_0 %5 %37 %17
OpLoopMerge %16 %17 None
OpBranch %18
%18 = OpLabel
%22 = OpSLessThan %bool %42 %int_10
OpBranchConditional %22 %15 %16
%15 = OpLabel
%31 = OpAccessChain %ptr_Uniform_float % %int_0 %42
%32 = OpLoad %float %31
%34 = OpFAdd %float %41 %32
OpBranch %17
%17 = OpLabel
%37 = OpIAdd %int %42 %int_1
OpBranch %14
%16 = OpLabel
OpStore %o %41
OpReturn
OpFunctionEnd
spirv-opt --ccp generates the following for the function:
%main = OpFunction %void None %3
%5 = OpLabel
OpBranch %14
%14 = OpLabel
%41 = OpPhi %float %float_0 %5 %34 %17
%42 = OpPhi %int %int_0 %5 %int_1 %17
OpLoopMerge %16 %17 None
OpBranch %18
%18 = OpLabel
%22 = OpSLessThan %bool %int_0 %int_10
OpBranchConditional %true %15 %16
%15 = OpLabel
%31 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_0
%32 = OpLoad %float %31
%34 = OpFAdd %float %float_0 %32
OpBranch %17
%17 = OpLabel
%37 = OpIAdd %int %int_0 %int_1
OpBranch %14
%16 = OpLabel
OpStore %o %float_0
OpReturn
OpFunctionEnd
This instruction is incorrect:
%42 = OpPhi %int %int_0 %5 %int_1 %17
Specifically, the %int_1 value is wrong.
Test case:
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 3
; Bound: 43
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %o
OpExecutionMode %main OriginUpperLeft
OpSource GLSL 430
OpName %main "main"
OpName %U_t "U_t"
OpMemberName %U_t 0 "g_F"
OpName %_ ""
OpName %o "o"
OpDecorate %arr_float_uint_10 ArrayStride 4
OpMemberDecorate %U_t 0 Offset 0
OpDecorate %U_t BufferBlock
OpDecorate % DescriptorSet 0
OpDecorate %o Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Function_float = OpTypePointer Function %float
%float_0 = OpConstant %float 0
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%int_0 = OpConstant %int 0
%int_10 = OpConstant %int 10
%bool = OpTypeBool
%uint = OpTypeInt 32 0
%uint_10 = OpConstant %uint 10
%_arr_float_uint_10 = OpTypeArray %float %uint_10
%U_t = OpTypeStruct %_arr_float_uint_10
%ptr_Uniform_U_t = OpTypePointer Uniform %U_t
% = OpVariable %_ptr_Uniform_U_t Uniform
%_ptr_Uniform_float = OpTypePointer Uniform %float
%int_1 = OpConstant %int 1
%_ptr_Output_float = OpTypePointer Output %float
%o = OpVariable %_ptr_Output_float Output
%main = OpFunction %void None %3
%5 = OpLabel
OpBranch %14
%14 = OpLabel
%41 = OpPhi %float %float_0 %5 %34 %17
%42 = OpPhi %int %int_0 %5 %37 %17
OpLoopMerge %16 %17 None
OpBranch %18
%18 = OpLabel
%22 = OpSLessThan %bool %42 %int_10
OpBranchConditional %22 %15 %16
%15 = OpLabel
%31 = OpAccessChain %ptr_Uniform_float % %int_0 %42
%32 = OpLoad %float %31
%34 = OpFAdd %float %41 %32
OpBranch %17
%17 = OpLabel
%37 = OpIAdd %int %42 %int_1
OpBranch %14
%16 = OpLabel
OpStore %o %41
OpReturn
OpFunctionEnd
spirv-opt --ccp generates the following for the function:
This instruction is incorrect:
Specifically, the %int_1 value is wrong.