[tint][ast] Fix dynamic indices in DirectVariableAccess
The logic to extract the callee's dynamic indices was incorrect.
Add more tests, for both the AST and IR transforms.
Bug: tint:2053
Change-Id: I9fa2eeded5a9ba525b1529377a0ab443e80d8634
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/169263
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/test/tint/array/strides.spvasm.expected.spvasm b/test/tint/array/strides.spvasm.expected.spvasm
index 3d87847..d319985 100644
--- a/test/tint/array/strides.spvasm.expected.spvasm
+++ b/test/tint/array/strides.spvasm.expected.spvasm
@@ -71,181 +71,181 @@
%uint_0 = OpConstant %uint 0
%int = OpTypeInt 32 1
%24 = OpConstantNull %int
+ %int_1 = OpConstant %int 1
+ %int_2 = OpConstant %int 2
%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
%_arr_uint_uint_2 = OpTypeArray %uint %uint_2
- %31 = OpTypeFunction %void %_arr_uint_uint_2 %_arr_strided_arr_uint_2
- %37 = OpConstantNull %uint
+ %33 = OpTypeFunction %void %_arr_uint_uint_2 %_arr_strided_arr_uint_2
+ %39 = OpConstantNull %uint
%_ptr_Function_uint = OpTypePointer Function %uint
%bool = OpTypeBool
%_ptr_Function__arr_strided_arr_uint_2 = OpTypePointer Function %_arr_strided_arr_uint_2
- %52 = OpConstantNull %_arr_strided_arr_uint_2
+ %54 = OpConstantNull %_arr_strided_arr_uint_2
%uint_1 = OpConstant %uint 1
%_ptr_Function_strided_arr = OpTypePointer Function %strided_arr
%_arr_uint_uint_1 = OpTypeArray %uint %uint_1
- %65 = OpTypeFunction %void %_arr_uint_uint_1 %_arr__arr_strided_arr_uint_2_uint_3
+ %67 = OpTypeFunction %void %_arr_uint_uint_1 %_arr__arr_strided_arr_uint_2_uint_3
%_ptr_Function__arr__arr_strided_arr_uint_2_uint_3 = OpTypePointer Function %_arr__arr_strided_arr_uint_2_uint_3
- %83 = OpConstantNull %_arr__arr_strided_arr_uint_2_uint_3
- %93 = OpTypeFunction %void %_arr_uint_uint_1 %strided_arr_1
- %102 = OpTypeFunction %void %_arr_strided_arr_1_uint_4
+ %85 = OpConstantNull %_arr__arr_strided_arr_uint_2_uint_3
+ %95 = OpTypeFunction %void %_arr_uint_uint_1 %strided_arr_1
+ %104 = OpTypeFunction %void %_arr_strided_arr_1_uint_4
%_ptr_Function__arr_strided_arr_1_uint_4 = OpTypePointer Function %_arr_strided_arr_1_uint_4
- %118 = OpConstantNull %_arr_strided_arr_1_uint_4
+ %120 = OpConstantNull %_arr_strided_arr_1_uint_4
%_ptr_Function_strided_arr_1 = OpTypePointer Function %strided_arr_1
- %128 = OpTypeFunction %void
+ %130 = OpTypeFunction %void
%_ptr_StorageBuffer__arr_strided_arr_1_uint_4 = OpTypePointer StorageBuffer %_arr_strided_arr_1_uint_4
%int_3 = OpConstant %int 3
%_ptr_StorageBuffer__arr__arr_strided_arr_uint_2_uint_3 = OpTypePointer StorageBuffer %_arr__arr_strided_arr_uint_2_uint_3
- %int_2 = OpConstant %int 2
%_ptr_StorageBuffer__arr_strided_arr_uint_2 = OpTypePointer StorageBuffer %_arr_strided_arr_uint_2
- %int_1 = OpConstant %int 1
%float_5 = OpConstant %float 5
%assign_and_preserve_padding_4_s_a_X_el_X_X = OpFunction %void None %15
%dest = OpFunctionParameter %_arr_uint_uint_3
%value = OpFunctionParameter %strided_arr
%21 = OpLabel
%25 = OpCompositeExtract %uint %dest 0
- %26 = OpCompositeExtract %uint %dest 0
- %27 = OpCompositeExtract %uint %dest 0
- %29 = OpAccessChain %_ptr_StorageBuffer_float %s %uint_0 %uint_0 %25 %uint_0 %26 %27 %uint_0
- %30 = OpCompositeExtract %float %value 0
- OpStore %29 %30
+ %27 = OpCompositeExtract %uint %dest 1
+ %29 = OpCompositeExtract %uint %dest 2
+ %31 = OpAccessChain %_ptr_StorageBuffer_float %s %uint_0 %uint_0 %25 %uint_0 %27 %29 %uint_0
+ %32 = OpCompositeExtract %float %value 0
+ OpStore %31 %32
OpReturn
OpFunctionEnd
-%assign_and_preserve_padding_3_s_a_X_el_X = OpFunction %void None %31
+%assign_and_preserve_padding_3_s_a_X_el_X = OpFunction %void None %33
%dest_0 = OpFunctionParameter %_arr_uint_uint_2
%value_0 = OpFunctionParameter %_arr_strided_arr_uint_2
- %36 = OpLabel
- %i = OpVariable %_ptr_Function_uint Function %37
-%var_for_index = OpVariable %_ptr_Function__arr_strided_arr_uint_2 Function %52
- OpStore %i %37
- OpBranch %40
- %40 = OpLabel
- OpLoopMerge %41 %42 None
- OpBranch %43
- %43 = OpLabel
- %45 = OpLoad %uint %i
- %46 = OpULessThan %bool %45 %uint_2
- %44 = OpLogicalNot %bool %46
- OpSelectionMerge %48 None
- OpBranchConditional %44 %49 %48
- %49 = OpLabel
- OpBranch %41
- %48 = OpLabel
- OpStore %var_for_index %value_0
- %54 = OpCompositeExtract %uint %dest_0 0
- %56 = OpCompositeExtract %uint %dest_0 1
- %57 = OpLoad %uint %i
- %58 = OpCompositeConstruct %_arr_uint_uint_3 %54 %56 %57
- %59 = OpLoad %uint %i
- %61 = OpAccessChain %_ptr_Function_strided_arr %var_for_index %59
- %62 = OpLoad %strided_arr %61
- %53 = OpFunctionCall %void %assign_and_preserve_padding_4_s_a_X_el_X_X %58 %62
+ %38 = OpLabel
+ %i = OpVariable %_ptr_Function_uint Function %39
+%var_for_index = OpVariable %_ptr_Function__arr_strided_arr_uint_2 Function %54
+ OpStore %i %39
OpBranch %42
%42 = OpLabel
- %63 = OpLoad %uint %i
- %64 = OpIAdd %uint %63 %uint_1
- OpStore %i %64
- OpBranch %40
- %41 = OpLabel
+ OpLoopMerge %43 %44 None
+ OpBranch %45
+ %45 = OpLabel
+ %47 = OpLoad %uint %i
+ %48 = OpULessThan %bool %47 %uint_2
+ %46 = OpLogicalNot %bool %48
+ OpSelectionMerge %50 None
+ OpBranchConditional %46 %51 %50
+ %51 = OpLabel
+ OpBranch %43
+ %50 = OpLabel
+ OpStore %var_for_index %value_0
+ %56 = OpCompositeExtract %uint %dest_0 0
+ %58 = OpCompositeExtract %uint %dest_0 1
+ %59 = OpLoad %uint %i
+ %60 = OpCompositeConstruct %_arr_uint_uint_3 %56 %58 %59
+ %61 = OpLoad %uint %i
+ %63 = OpAccessChain %_ptr_Function_strided_arr %var_for_index %61
+ %64 = OpLoad %strided_arr %63
+ %55 = OpFunctionCall %void %assign_and_preserve_padding_4_s_a_X_el_X_X %60 %64
+ OpBranch %44
+ %44 = OpLabel
+ %65 = OpLoad %uint %i
+ %66 = OpIAdd %uint %65 %uint_1
+ OpStore %i %66
+ OpBranch %42
+ %43 = OpLabel
OpReturn
OpFunctionEnd
-%assign_and_preserve_padding_2_s_a_X_el = OpFunction %void None %65
+%assign_and_preserve_padding_2_s_a_X_el = OpFunction %void None %67
%dest_1 = OpFunctionParameter %_arr_uint_uint_1
%value_1 = OpFunctionParameter %_arr__arr_strided_arr_uint_2_uint_3
- %70 = OpLabel
- %i_0 = OpVariable %_ptr_Function_uint Function %37
-%var_for_index_1 = OpVariable %_ptr_Function__arr__arr_strided_arr_uint_2_uint_3 Function %83
- OpStore %i_0 %37
- OpBranch %72
%72 = OpLabel
- OpLoopMerge %73 %74 None
- OpBranch %75
- %75 = OpLabel
- %77 = OpLoad %uint %i_0
- %78 = OpULessThan %bool %77 %uint_3
- %76 = OpLogicalNot %bool %78
- OpSelectionMerge %79 None
- OpBranchConditional %76 %80 %79
- %80 = OpLabel
- OpBranch %73
- %79 = OpLabel
- OpStore %var_for_index_1 %value_1
- %85 = OpCompositeExtract %uint %dest_1 0
- %86 = OpLoad %uint %i_0
- %87 = OpCompositeConstruct %_arr_uint_uint_2 %85 %86
- %88 = OpLoad %uint %i_0
- %89 = OpAccessChain %_ptr_Function__arr_strided_arr_uint_2 %var_for_index_1 %88
- %90 = OpLoad %_arr_strided_arr_uint_2 %89
- %84 = OpFunctionCall %void %assign_and_preserve_padding_3_s_a_X_el_X %87 %90
+ %i_0 = OpVariable %_ptr_Function_uint Function %39
+%var_for_index_1 = OpVariable %_ptr_Function__arr__arr_strided_arr_uint_2_uint_3 Function %85
+ OpStore %i_0 %39
OpBranch %74
%74 = OpLabel
- %91 = OpLoad %uint %i_0
- %92 = OpIAdd %uint %91 %uint_1
- OpStore %i_0 %92
- OpBranch %72
- %73 = OpLabel
+ OpLoopMerge %75 %76 None
+ OpBranch %77
+ %77 = OpLabel
+ %79 = OpLoad %uint %i_0
+ %80 = OpULessThan %bool %79 %uint_3
+ %78 = OpLogicalNot %bool %80
+ OpSelectionMerge %81 None
+ OpBranchConditional %78 %82 %81
+ %82 = OpLabel
+ OpBranch %75
+ %81 = OpLabel
+ OpStore %var_for_index_1 %value_1
+ %87 = OpCompositeExtract %uint %dest_1 0
+ %88 = OpLoad %uint %i_0
+ %89 = OpCompositeConstruct %_arr_uint_uint_2 %87 %88
+ %90 = OpLoad %uint %i_0
+ %91 = OpAccessChain %_ptr_Function__arr_strided_arr_uint_2 %var_for_index_1 %90
+ %92 = OpLoad %_arr_strided_arr_uint_2 %91
+ %86 = OpFunctionCall %void %assign_and_preserve_padding_3_s_a_X_el_X %89 %92
+ OpBranch %76
+ %76 = OpLabel
+ %93 = OpLoad %uint %i_0
+ %94 = OpIAdd %uint %93 %uint_1
+ OpStore %i_0 %94
+ OpBranch %74
+ %75 = OpLabel
OpReturn
OpFunctionEnd
-%assign_and_preserve_padding_1_s_a_X = OpFunction %void None %93
+%assign_and_preserve_padding_1_s_a_X = OpFunction %void None %95
%dest_2 = OpFunctionParameter %_arr_uint_uint_1
%value_2 = OpFunctionParameter %strided_arr_1
- %97 = OpLabel
- %99 = OpCompositeExtract %uint %dest_2 0
- %100 = OpCompositeConstruct %_arr_uint_uint_1 %99
- %101 = OpCompositeExtract %_arr__arr_strided_arr_uint_2_uint_3 %value_2 0
- %98 = OpFunctionCall %void %assign_and_preserve_padding_2_s_a_X_el %100 %101
+ %99 = OpLabel
+ %101 = OpCompositeExtract %uint %dest_2 0
+ %102 = OpCompositeConstruct %_arr_uint_uint_1 %101
+ %103 = OpCompositeExtract %_arr__arr_strided_arr_uint_2_uint_3 %value_2 0
+ %100 = OpFunctionCall %void %assign_and_preserve_padding_2_s_a_X_el %102 %103
OpReturn
OpFunctionEnd
-%assign_and_preserve_padding_s_a = OpFunction %void None %102
+%assign_and_preserve_padding_s_a = OpFunction %void None %104
%value_3 = OpFunctionParameter %_arr_strided_arr_1_uint_4
- %105 = OpLabel
- %i_1 = OpVariable %_ptr_Function_uint Function %37
-%var_for_index_2 = OpVariable %_ptr_Function__arr_strided_arr_1_uint_4 Function %118
- OpStore %i_1 %37
- OpBranch %107
%107 = OpLabel
- OpLoopMerge %108 %109 None
- OpBranch %110
- %110 = OpLabel
- %112 = OpLoad %uint %i_1
- %113 = OpULessThan %bool %112 %uint_4
- %111 = OpLogicalNot %bool %113
- OpSelectionMerge %114 None
- OpBranchConditional %111 %115 %114
- %115 = OpLabel
- OpBranch %108
- %114 = OpLabel
- OpStore %var_for_index_2 %value_3
- %120 = OpLoad %uint %i_1
- %121 = OpCompositeConstruct %_arr_uint_uint_1 %120
- %122 = OpLoad %uint %i_1
- %124 = OpAccessChain %_ptr_Function_strided_arr_1 %var_for_index_2 %122
- %125 = OpLoad %strided_arr_1 %124
- %119 = OpFunctionCall %void %assign_and_preserve_padding_1_s_a_X %121 %125
+ %i_1 = OpVariable %_ptr_Function_uint Function %39
+%var_for_index_2 = OpVariable %_ptr_Function__arr_strided_arr_1_uint_4 Function %120
+ OpStore %i_1 %39
OpBranch %109
%109 = OpLabel
- %126 = OpLoad %uint %i_1
- %127 = OpIAdd %uint %126 %uint_1
- OpStore %i_1 %127
- OpBranch %107
- %108 = OpLabel
+ OpLoopMerge %110 %111 None
+ OpBranch %112
+ %112 = OpLabel
+ %114 = OpLoad %uint %i_1
+ %115 = OpULessThan %bool %114 %uint_4
+ %113 = OpLogicalNot %bool %115
+ OpSelectionMerge %116 None
+ OpBranchConditional %113 %117 %116
+ %117 = OpLabel
+ OpBranch %110
+ %116 = OpLabel
+ OpStore %var_for_index_2 %value_3
+ %122 = OpLoad %uint %i_1
+ %123 = OpCompositeConstruct %_arr_uint_uint_1 %122
+ %124 = OpLoad %uint %i_1
+ %126 = OpAccessChain %_ptr_Function_strided_arr_1 %var_for_index_2 %124
+ %127 = OpLoad %strided_arr_1 %126
+ %121 = OpFunctionCall %void %assign_and_preserve_padding_1_s_a_X %123 %127
+ OpBranch %111
+ %111 = OpLabel
+ %128 = OpLoad %uint %i_1
+ %129 = OpIAdd %uint %128 %uint_1
+ OpStore %i_1 %129
+ OpBranch %109
+ %110 = OpLabel
OpReturn
OpFunctionEnd
- %f_1 = OpFunction %void None %128
- %130 = OpLabel
- %132 = OpAccessChain %_ptr_StorageBuffer__arr_strided_arr_1_uint_4 %s %uint_0 %uint_0
- %133 = OpLoad %_arr_strided_arr_1_uint_4 %132
- %136 = OpAccessChain %_ptr_StorageBuffer__arr__arr_strided_arr_uint_2_uint_3 %s %uint_0 %uint_0 %int_3 %uint_0
- %137 = OpLoad %_arr__arr_strided_arr_uint_2_uint_3 %136
- %140 = OpAccessChain %_ptr_StorageBuffer__arr_strided_arr_uint_2 %s %uint_0 %uint_0 %int_3 %uint_0 %int_2
- %141 = OpLoad %_arr_strided_arr_uint_2 %140
+ %f_1 = OpFunction %void None %130
+ %132 = OpLabel
+ %134 = OpAccessChain %_ptr_StorageBuffer__arr_strided_arr_1_uint_4 %s %uint_0 %uint_0
+ %135 = OpLoad %_arr_strided_arr_1_uint_4 %134
+ %138 = OpAccessChain %_ptr_StorageBuffer__arr__arr_strided_arr_uint_2_uint_3 %s %uint_0 %uint_0 %int_3 %uint_0
+ %139 = OpLoad %_arr__arr_strided_arr_uint_2_uint_3 %138
+ %141 = OpAccessChain %_ptr_StorageBuffer__arr_strided_arr_uint_2 %s %uint_0 %uint_0 %int_3 %uint_0 %int_2
+ %142 = OpLoad %_arr_strided_arr_uint_2 %141
%143 = OpAccessChain %_ptr_StorageBuffer_float %s %uint_0 %uint_0 %int_3 %uint_0 %int_2 %int_1 %uint_0
%144 = OpLoad %float %143
- %145 = OpFunctionCall %void %assign_and_preserve_padding_s_a %118
+ %145 = OpFunctionCall %void %assign_and_preserve_padding_s_a %120
%146 = OpAccessChain %_ptr_StorageBuffer_float %s %uint_0 %uint_0 %int_3 %uint_0 %int_2 %int_1 %uint_0
OpStore %146 %float_5
OpReturn
OpFunctionEnd
- %f = OpFunction %void None %128
+ %f = OpFunction %void None %130
%149 = OpLabel
%150 = OpFunctionCall %void %f_1
OpReturn