diff --git a/source/fuzz/transformation_set_loop_control.cpp b/source/fuzz/transformation_set_loop_control.cpp index 7e53911b..8c0d13b1 100644 --- a/source/fuzz/transformation_set_loop_control.cpp +++ b/source/fuzz/transformation_set_loop_control.cpp @@ -77,12 +77,14 @@ bool TransformationSetLoopControl::IsApplicable( } } - if ((message_.loop_control() & - (SpvLoopControlPeelCountMask | SpvLoopControlPartialCountMask)) && - !(PeelCountIsSupported(ir_context) && - PartialCountIsSupported(ir_context))) { - // At least one of PeelCount or PartialCount is used, but the SPIR-V version - // in question does not support these loop controls. + // Check that PeelCount and PartialCount are supported if used. + if ((message_.loop_control() & SpvLoopControlPeelCountMask) && + !PeelCountIsSupported(ir_context)) { + return false; + } + + if ((message_.loop_control() & SpvLoopControlPartialCountMask) && + !PartialCountIsSupported(ir_context)) { return false; } @@ -183,14 +185,16 @@ bool TransformationSetLoopControl::LoopControlBitIsAddedByTransformation( bool TransformationSetLoopControl::PartialCountIsSupported( opt::IRContext* ir_context) { - // TODO(afd): We capture the universal environments for which this loop - // control is definitely not supported. The check should be refined on - // demand for other target environments. + // TODO(afd): We capture the environments for which this loop control is + // definitely not supported. The check should be refined on demand for other + // target environments. switch (ir_context->grammar().target_env()) { case SPV_ENV_UNIVERSAL_1_0: case SPV_ENV_UNIVERSAL_1_1: case SPV_ENV_UNIVERSAL_1_2: case SPV_ENV_UNIVERSAL_1_3: + case SPV_ENV_VULKAN_1_0: + case SPV_ENV_VULKAN_1_1: return false; default: return true; diff --git a/test/fuzz/transformation_set_loop_control_test.cpp b/test/fuzz/transformation_set_loop_control_test.cpp index 060d9a8e..5c95ccca 100644 --- a/test/fuzz/transformation_set_loop_control_test.cpp +++ b/test/fuzz/transformation_set_loop_control_test.cpp @@ -958,8 +958,10 @@ TEST(TransformationSetLoopControlTest, CheckSPIRVVersionsRespected) { context.get(), validator_options, kConsoleMessageConsumer)); TransformationContext transformation_context( MakeUnique(context.get()), validator_options); - TransformationSetLoopControl transformation( - 10, SpvLoopControlPeelCountMask | SpvLoopControlPartialCountMask, 4, 4); + TransformationSetLoopControl peel_count( + 10, SpvLoopControlPeelCountMask, 4, 0); + TransformationSetLoopControl partial_count( + 10, SpvLoopControlPartialCountMask, 0, 4); switch (env) { case SPV_ENV_UNIVERSAL_1_0: @@ -971,14 +973,18 @@ TEST(TransformationSetLoopControlTest, CheckSPIRVVersionsRespected) { // PeelCount and PartialCount were introduced in SPIRV 1.4, so are not // valid in the context of older versions. ASSERT_FALSE( - transformation.IsApplicable(context.get(), transformation_context)); + peel_count.IsApplicable(context.get(), transformation_context)); + ASSERT_FALSE( + partial_count.IsApplicable(context.get(), transformation_context)); break; case SPV_ENV_UNIVERSAL_1_4: case SPV_ENV_UNIVERSAL_1_5: case SPV_ENV_VULKAN_1_1_SPIRV_1_4: case SPV_ENV_VULKAN_1_2: ASSERT_TRUE( - transformation.IsApplicable(context.get(), transformation_context)); + peel_count.IsApplicable(context.get(), transformation_context)); + ASSERT_TRUE( + partial_count.IsApplicable(context.get(), transformation_context)); break; default: assert(false && "Unhandled environment");