@@ -8297,6 +8297,185 @@ OpFunctionEnd
82978297 HasSubstr (" OpSource HLSL 600 %5 \" #define UBER_TYPE(x) x ## Type" ));
82988298}
82998299
8300+ TEST_F (AggressiveDCETest, EliminateCopyLogical) {
8301+ const std::string before = R"(
8302+ ; CHECK: [[float32:%\w+]] = OpTypeFloat 32
8303+ ; CHECK: [[v4float:%\w+]] = OpTypeVector [[float32]] 4
8304+ ; CHECK-NOT: %10 = OpTypeArray [[v4float]] %9
8305+ ; CHECK-NOT: %11 = OpTypeStruct %10 %10
8306+ ; CHECK-NOT: %22 = OpTypePointer Uniform %16
8307+ ; CHECK-NOT: %38 = OpTypePointer Function [[v4float]]
8308+ ; CHECK-NOT: %43 = OpTypePointer Function %10
8309+ ; CHECK-NOT: %44 = OpVariable %42 Function
8310+ ; CHECK-NOT: %23 = OpAccessChain %22 %19 %21
8311+ ; CHECK-NOT: %24 = OpLoad %16 %23
8312+ ; CHECK-NOT: %25 = OpCopyLogical %11 %24
8313+ ; CHECK-NOT: %46 = OpCompositeExtract %10 %25 0
8314+ ; CHECK-NOT: OpStore %44 %46
8315+ OpCapability Shader
8316+ %1 = OpExtInstImport "GLSL.std.450"
8317+ OpMemoryModel Logical GLSL450
8318+ OpEntryPoint Vertex %4 "main" %19 %30 %32
8319+ OpSource GLSL 430
8320+ OpName %4 "main"
8321+ OpDecorate %14 ArrayStride 16
8322+ OpDecorate %15 ArrayStride 16
8323+ OpMemberDecorate %16 0 Offset 0
8324+ OpMemberDecorate %16 1 Offset 32
8325+ OpDecorate %17 Block
8326+ OpMemberDecorate %17 0 Offset 0
8327+ OpDecorate %19 Binding 0
8328+ OpDecorate %19 DescriptorSet 0
8329+ OpDecorate %28 Block
8330+ OpMemberDecorate %28 0 BuiltIn Position
8331+ OpMemberDecorate %28 1 BuiltIn PointSize
8332+ OpMemberDecorate %28 2 BuiltIn ClipDistance
8333+ OpDecorate %32 Location 0
8334+ %2 = OpTypeVoid
8335+ %3 = OpTypeFunction %2
8336+ %6 = OpTypeFloat 32
8337+ %7 = OpTypeVector %6 4
8338+ %8 = OpTypeInt 32 0
8339+ %9 = OpConstant %8 2
8340+ %10 = OpTypeArray %7 %9
8341+ %11 = OpTypeStruct %10 %10
8342+ %14 = OpTypeArray %7 %9
8343+ %15 = OpTypeArray %7 %9
8344+ %16 = OpTypeStruct %14 %15
8345+ %17 = OpTypeStruct %16
8346+ %18 = OpTypePointer Uniform %17
8347+ %19 = OpVariable %18 Uniform
8348+ %20 = OpTypeInt 32 1
8349+ %21 = OpConstant %20 0
8350+ %22 = OpTypePointer Uniform %16
8351+ %26 = OpConstant %8 1
8352+ %27 = OpTypeArray %6 %26
8353+ %28 = OpTypeStruct %7 %6 %27
8354+ %29 = OpTypePointer Output %28
8355+ %30 = OpVariable %29 Output
8356+ %31 = OpTypePointer Input %7
8357+ %32 = OpVariable %31 Input
8358+ %33 = OpConstant %8 0
8359+ %34 = OpTypePointer Input %6
8360+ %38 = OpTypePointer Function %7
8361+ %41 = OpTypePointer Output %7
8362+ %43 = OpTypePointer Function %10
8363+ %48 = OpTypePointer Uniform %14
8364+ %49 = OpTypePointer Uniform %7
8365+ %4 = OpFunction %2 None %3
8366+ %5 = OpLabel
8367+ %44 = OpVariable %43 Function
8368+ %23 = OpAccessChain %22 %19 %21
8369+ %24 = OpLoad %16 %23
8370+ %25 = OpCopyLogical %11 %24
8371+ %46 = OpCompositeExtract %10 %25 0
8372+ %50 = OpAccessChain %48 %19 %21 %33
8373+ OpStore %44 %46
8374+ %35 = OpAccessChain %34 %32 %33
8375+ %36 = OpLoad %6 %35
8376+ %37 = OpConvertFToS %20 %36
8377+ %47 = OpAccessChain %49 %50 %37
8378+ %40 = OpLoad %7 %47
8379+ %42 = OpAccessChain %41 %30 %21
8380+ OpStore %42 %40
8381+ OpReturn
8382+ OpFunctionEnd
8383+ )" ;
8384+
8385+ SetTargetEnv (SPV_ENV_UNIVERSAL_1_6);
8386+ SetAssembleOptions (SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
8387+ SetDisassembleOptions (SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
8388+ SinglePassRunAndMatch<AggressiveDCEPass>(before, true );
8389+ }
8390+
8391+ TEST_F (AggressiveDCETest, KeepCopyLogical) {
8392+ const std::string before = R"(
8393+ ; CHECK: OpCopyLogical
8394+ OpCapability Shader
8395+ %1 = OpExtInstImport "GLSL.std.450"
8396+ OpMemoryModel Logical GLSL450
8397+ OpEntryPoint GLCompute %4 "main" %15 %23 %38
8398+ OpExecutionMode %4 LocalSize 32 32 1
8399+ OpSource GLSL 430
8400+ OpName %4 "main"
8401+ OpDecorate %10 ArrayStride 16
8402+ OpDecorate %11 ArrayStride 16
8403+ OpMemberDecorate %12 0 Offset 0
8404+ OpMemberDecorate %12 1 Offset 2048
8405+ OpDecorate %13 Block
8406+ OpMemberDecorate %13 0 NonReadable
8407+ OpMemberDecorate %13 0 Offset 0
8408+ OpDecorate %15 NonReadable
8409+ OpDecorate %15 Binding 1
8410+ OpDecorate %15 DescriptorSet 0
8411+ OpDecorate %18 ArrayStride 16
8412+ OpDecorate %19 ArrayStride 16
8413+ OpMemberDecorate %20 0 Offset 0
8414+ OpMemberDecorate %20 1 Offset 2048
8415+ OpDecorate %21 Block
8416+ OpMemberDecorate %21 0 NonWritable
8417+ OpMemberDecorate %21 0 Offset 0
8418+ OpDecorate %23 NonWritable
8419+ OpDecorate %23 Binding 0
8420+ OpDecorate %23 DescriptorSet 0
8421+ OpDecorate %30 ArrayStride 16
8422+ OpDecorate %31 ArrayStride 16
8423+ OpMemberDecorate %32 0 Offset 0
8424+ OpMemberDecorate %32 1 Offset 2048
8425+ OpDecorate %34 ArrayStride 4096
8426+ OpMemberDecorate %35 0 Offset 0
8427+ OpDecorate %36 Block
8428+ OpMemberDecorate %36 0 Offset 0
8429+ OpDecorate %38 Binding 0
8430+ OpDecorate %38 DescriptorSet 0
8431+ %2 = OpTypeVoid
8432+ %3 = OpTypeFunction %2
8433+ %6 = OpTypeFloat 32
8434+ %7 = OpTypeVector %6 4
8435+ %8 = OpTypeInt 32 0
8436+ %9 = OpConstant %8 128
8437+ %10 = OpTypeArray %7 %9
8438+ %11 = OpTypeArray %7 %9
8439+ %12 = OpTypeStruct %10 %11
8440+ %13 = OpTypeStruct %12
8441+ %14 = OpTypePointer StorageBuffer %13
8442+ %15 = OpVariable %14 StorageBuffer
8443+ %16 = OpTypeInt 32 1
8444+ %17 = OpConstant %16 0
8445+ %18 = OpTypeArray %7 %9
8446+ %19 = OpTypeArray %7 %9
8447+ %20 = OpTypeStruct %18 %19
8448+ %21 = OpTypeStruct %20
8449+ %22 = OpTypePointer StorageBuffer %21
8450+ %23 = OpVariable %22 StorageBuffer
8451+ %24 = OpTypePointer StorageBuffer %20
8452+ %27 = OpTypePointer StorageBuffer %12
8453+ %30 = OpTypeArray %7 %9
8454+ %31 = OpTypeArray %7 %9
8455+ %32 = OpTypeStruct %30 %31
8456+ %33 = OpConstant %8 8
8457+ %34 = OpTypeArray %32 %33
8458+ %35 = OpTypeStruct %34
8459+ %36 = OpTypeStruct %35
8460+ %37 = OpTypePointer Uniform %36
8461+ %38 = OpVariable %37 Uniform
8462+ %4 = OpFunction %2 None %3
8463+ %5 = OpLabel
8464+ %25 = OpAccessChain %24 %23 %17
8465+ %26 = OpLoad %20 %25
8466+ %28 = OpAccessChain %27 %15 %17
8467+ %29 = OpCopyLogical %12 %26
8468+ OpStore %28 %29
8469+ OpReturn
8470+ OpFunctionEnd
8471+ )" ;
8472+
8473+ SetTargetEnv (SPV_ENV_UNIVERSAL_1_6);
8474+ SetAssembleOptions (SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
8475+ SetDisassembleOptions (SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
8476+ SinglePassRunAndMatch<AggressiveDCEPass>(before, true );
8477+ }
8478+
83008479} // namespace
83018480} // namespace opt
83028481} // namespace spvtools
0 commit comments