<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138996>138996</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DirectX] DXILCBufferAccess gets tripped up by arrays that are exactly 64 bits long
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:DirectX
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bogner
</td>
</tr>
</table>
<pre>
If an array fits in exactly 64 bits (for example, if it's 2 32 bit integers or 4 16 bit integers), DXILCBufferAccess gets a bit confused. Consider:
https://hlsl.godbolt.org/z/j3aqnEcdx
```hlsl
cbuffer CBArrays : register(b0) {
uint32_t c1[2];
}
struct Arrays {
uint32_t c1[2];
};
RWStructuredBuffer<Arrays> Out : register(u1);
[numthreads(1,1,1)]
void main() {
Out[0].c1 = c1;
}
```
The array copy is turned into a memcpy by clang, which is then simplified into just loading and copying an `i64`. Then, we feed something like the following into DXILCBufferAccess:
```llvm
define void @main() local_unnamed_addr #1 {
entry:
%CBArrays.cb_h.i.i = tail call target("dx.CBuffer", target("dx.Layout", %__cblayout_CBArrays, 20, 0)) @llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CBArrayss_20_0tt(i32 0, i32 0, i32 1, i32 0, i1 false)
store target("dx.CBuffer", target("dx.Layout", %__cblayout_CBArrays, 20, 0)) %CBArrays.cb_h.i.i, ptr @CBArrays.cb, align 4
%0 = tail call target("dx.RawBuffer", %struct.Arrays, 1, 0) @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_s_struct.Arrayss_1_0t(i32 0, i32 1, i32 1, i32 0, i1 false)
%1 = tail call noundef nonnull align 1 dereferenceable(8) ptr @llvm.dx.resource.getpointer.p0.tdx.RawBuffer_s_struct.Arrayss_1_0t(target("dx.RawBuffer", %struct.Arrays, 1, 0) %0, i32 0)
%2 = load i64, ptr addrspace(2) @c1, align 4, !tbaa !6
store i64 %2, ptr %1, align 1, !tbaa !6
ret void
}
```
Seeing the `i64` load, the pass assumes that the type it should use for the access is a 64 bit type, and things go wrong from there.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8Vl-L2zgQ_zTKy1Bjy7ETP-Qh2TRQKBTawvXNyNLYVitLPv3pbu7TH5KTNNttjz0ODrxrZ0bz5_eb0UjMOTloxB2pDqQ6rljwo7G7zgwa7aoz4rx71wPTwKxlZ-ildyA14BPjXp2hXkMXRYRue2OjeJoVEvoAsgfpCd04oFDSuAqk9jigdWAsrKGonwkJbaLZ8cu79w-H0Pdo95yjczCgd8DSWm50HxyKDB6MdlKgJeWe5PEZvZ9d_EVPhJ5G5VQ2GNEZ5TNjB0JPfxF6-lqyP_VbLp6iTZ0vT1xL8j3vUlB4OOwjUgek3IPFQTqPltBtlxPaANkcSL4HCFL7krYeeEGqAyXVkZRRQzbHJR_nbeAerr5eYZY-Pv7xKRkGi2JhgZQPixNSvoUPwf-cVygic4uXfE-qgw6THy0y4QjdFoQ-XP6aGC3ffzdSwMSkJnR7j-hD8KQ65KQ6ZrwAUh5jjveYrnwtgT6PeGkJbuYzSAc-WI0i1tMAgwknPp-hOwNXTA-xtI-j5GNaOaIGJ6dZyV5eTb4G50EZJqQegGmR_C7fQOpc1mtS5xl8HlEnZwg9ogBnJvRjXKfkN4yuoTdKmccoSo5fdNStZ26QlPo-kXwvsJcaITFE1vkdScpwptqgNZtQtEwIC4SWxYU81N6eF68AhFbXFsp4146ZzGSi0zOpgDOlwDM7oE-uqXjKLskRSiOwn5Tv2dkEf9ERWrUt71SStdcwUUPz-D9Pm6iJyUdImXjKLDoTLMdsZFoo7K2ZOqkjyZn_Ebv1t1Cta38Rw7U0b3Mf85IlhRTt2UfxXFJAz5TDmE8kxXlj8X_A_Qvuo372NnJyp4tSpuSgYX2tWv7PVfrIHp_lS2i17PHsRzbFNZl_UYGb39a1zxy6tmjzF4QXryOc0Kr4CY82QQvsQRutg1IX-AUItNijRc2R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