Skip to content

spirv-opt: CCP pass might create a new constant and return SuccessWithoutChange #3636

@Vasniktel

Description

@Vasniktel
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %4 "main"
               OpExecutionMode %4 OriginUpperLeft
               OpSource ESSL 320
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
          %6 = OpTypeInt 32 1
          %7 = OpConstant %6 2
         %13 = OpConstant %6 4
         %21 = OpConstant %6 1
         %10 = OpTypeBool
         %17 = OpTypePointer Function %6
          %4 = OpFunction %2 None %3
         %11 = OpLabel
               OpBranch %5
          %5 = OpLabel
         %23 = OpPhi %6 %7 %11 %20 %15
          %9 = OpSLessThan %10 %23 %13
               OpLoopMerge %8 %15 None
               OpBranchConditional %9 %15 %8
         %15 = OpLabel
         %20 = OpIAdd %6 %23 %21
               OpBranch %5
          %8 = OpLabel
               OpReturn
               OpFunctionEnd

The attached shader contains a SPIR-V that causes an assertion failure at

assert(optimized_binary_with_nop.size() == original_binary_size &&
"Binary size unexpectedly changed despite the optimizer saying "
"there was no change");

if the tool is executed with the following command spirv-opt <attached binary> -o out.spv --ccp (can be reproduced on b78f4b1).

The reason is that a new OpConstantTrue is created here

Instruction* folded_inst =
context()->get_instruction_folder().FoldInstructionToConstant(instr,
map_func);

when a CCP pass tries to fold an instruction with id %9 for the first time. The second time the pass tries to simulate the execution of that instruction, it finds out that the instruction actually has a varying value, so the pass returns SuccessWithoutChange even though a new constant was created previously.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions