Consider the following SPIR-V
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main"
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 310
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeVector %6 3
%8 = OpConstant %6 0
%9 = OpConstantComposite %7 %8 %8 %8
%10 = OpTypeVector %6 4
%4 = OpFunction %2 None %3
%5 = OpLabel
%11 = OpCompositeConstruct %10 %9 %8
%12 = OpCompositeExtract %6 %11 3
OpReturn
OpFunctionEnd
An attempt to replace the use of %11 in %12 fails because of the off-by-1 error in
|
uint32_t vector_size = element_type->element_count(); |
|
if (vector_size < element_index) { |
|
// The element we want comes after this vector. |
|
element_index -= vector_size; |
|
} else { |
|
// We want an element of this vector. |
|
operands.push_back({SPV_OPERAND_TYPE_ID, {element_id}}); |
|
operands.push_back( |
|
{SPV_OPERAND_TYPE_LITERAL_INTEGER, {element_index}}); |
|
break; |
|
} |
Can be reproduced on b78f4b1.
Consider the following SPIR-V
An attempt to replace the use of
%11in%12fails because of the off-by-1 error inSPIRV-Tools/source/opt/folding_rules.cpp
Lines 1469 to 1479 in b78f4b1
Can be reproduced on b78f4b1.