<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/147114>147114</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [DirectX] Direct stores to array allocas cause validation error: Explicit load/store type does not match pointee type of pointer operand
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Icohedron
      </td>
    </tr>
</table>

<pre>
    ## The Problem
This shader fails to validate due to the validation error: `Explicit load/store type does not match pointee type of pointer operand`

Surprisingly, no DML shaders are failing to validate due to this error.

```hlsl
uint2 Foo(uint2 a[2], uint i) {
 return a[i];
}
RWStructuredBuffer<uint2> output;
[numthreads(1, 1, 1)]
void CSMain(uint3 Tid : SV_DispatchThreadID) {
  uint2 arr[2] = {Tid.xy, Tid.yx};
  output[0] = Foo(arr, Tid.z);
}
```
https://godbolt.org/z/PdW9d7brE

Using lldb, I have found that the validation error is due to direct scalar stores into array allocas:
```llvm
  %1 = alloca [4 x i32], align 8
  %4 = call i32 @dx.op.threadId.i32(i32 93, i32 0) #3, !dbg !86
  store i32 %4, ptr %1, align 8, !dbg !105
```
returning this error https://github.com/microsoft/DirectXShaderCompiler/blob/4fcf67f78f7d6ffd286316112694a3ae000860e2/lib/Bitcode/Reader/BitcodeReader.cpp#L3693

## Proposed solution

The dxil-flatten-arrays pass or the dxil-legalize pass could insert GEPs for these kinds of store and load instructions.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVE1v4zYQ_TXjyyAGNfqyDj7YcVQE2AWCTdrtraBEymJLkwJJpc7--oKUvJsugp4KGJbEefP45pN7r85Gyj2URyhPGz6H0br9Y29HKZw1m86Ktz1QDpTjyyjxydlOywuww8uoPPqRC-lw4Ep7DBZfuVaCB4lilvE7jPJ2pqxB6Zx1kB8QKvZwnbTqVUBtuQBqfbBOYnib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