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

    <tr>
        <th>Summary</th>
        <td>
            [AMDGPU] Incorrect outputs from tiling kernel after PR #129464
        </td>
    </tr>

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

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

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

<pre>
    To reproduce, grab https://github.com/user-attachments/files/19236058/129464-reproducer.zip and, on a gfx942/MI-300, `make test` after (if necessary) editing the `Makefile` to point at the LLVM build you'd like to test.

The IR that triggers the miscompile is in `input.ll` within that attached file, and compiles correctly under `-O1` but does not compile correctly under `-O3`.

The test harness, which demonstrates the expected array packing the program performs, is in `driver.cpp` in the attached reproducer. The code takes a 100x250 array of 32-bit ints an input and produces a 16x4x16x32 array, where `out[i][j][k][l] == in[j * 32 + l][i * 16 + k]`, defaulting to `42` for elements that would be out of bounds in `in`.

The failure is
```
Mismatch at (0, 1, 14, 4) got 11014 but wanted 9014
Mismatch at (0, 2, 14, 4) got 19014 but wanted 17014
Mismatch at (1, 0, 14, 4) got 3030 but wanted 1030
Mismatch at (1, 1, 14, 4) got 11030 but wanted 9030
Mismatch at (1, 2, 14, 4) got 19030 but wanted 17030
Mismatch at (2, 0, 14, 4) got 3046 but wanted 1046
Mismatch at (2, 1, 14, 4) got 11046 but wanted 9046
Mismatch at (2, 2, 14, 4) got 19046 but wanted 17046
...
Mismatch at (12, 0, 14, 4) got 3206 but wanted 1206
Mismatch at (12, 1, 14, 4) got 11206 but wanted 9206
Mismatch at (12, 2, 14, 4) got 19206 but wanted 17206
Mismatch at (13, 0, 14, 4) got 3222 but wanted 1222
Mismatch at (13, 1, 14, 4) got 11222 but wanted 9222
Mismatch at (13, 2, 14, 4) got 19222 but wanted 17222
Mismatch at (14, 0, 14, 4) got 3238 but wanted 1238
Mismatch at (14, 1, 14, 4) got 11238 but wanted 9238
Mismatch at (14, 2, 14, 4) got 19238 but wanted 17238
```
as if some particular register were being dropped.

I bisected this failure to #129464 - I don't know if this PR caused the failure or exposed some other underlying bug.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8Vl-P26oT_TTkZZQIj__FD3nY7Wp_WqmrX1X13ndsT2waDBbgJumnvwKn3U0UR4pMBJwz58BoBuGc7DTRjuXPLH9Zicn3xu4O9vfZ_eZ8VZv2vPthwNJoTTs1xPALdFbU0Hs_OpY-MXxl-NpJ30_1pjEDw9fJkV0L70XTD6S9Y_i6l4rCmFSYFjzfhr9YZUW2_stsN7_lCEK3IYTRIKDbn6oMGb6-v61TzsM8K_ggDgSenGcFB7H3ZIHhVu5BU0POCXtmWAG10kvdge8pgN7FgYKGgPEGRiO1B-Hj8tev_75DPUnVwtlMDMsWlAwxTAyzYfyJ8acfPcHbd_B9QFnZdWRdhA_SNWYYpSKQDqQO4aQeJ79RKoQ7St9LPQPnQ6EWohb8EuzCBe2gMdZS49UZJt0GWwVf_z8JHPXkoTXkQBv_Z__97Skr-CfFwQD0wmpyLsQ79rLpoaXBaOet8DR7oNNIjacWhLXiDKNoDn8Ob7Sms2KAkeze2CGy_PXZWvmL7KYZx6AyuqQPk5-uFoKYxrQEXhzIgYCE8xPm_BLR7CHFdS09SO0dCA3xCOP5XEgiqDhlp6Q4pTjjZktk4x2bybP8WbL8heXPP-fhMA-K5S_A0heWvoDUYRkYPkGKwPAZ1LxJxrmkiHMRWMSca2kvJjVnkwmBMgxu98YCKYoZPt_u0UyqhZrATD44qs2k24-UuL6ZvZBqsiFnwlzBLz_-9C7dIHzTh_RkuI0SkvjJwjcL2d0ZD0nCkyxmxlHocHcVT7IFPN7DVzf4pLxLEGPzOwQpT_kVnqd39CcP9F_jq2X8gv6b-OVdAlzWnxXX-rNiAb6g_xpfLeMX9N_EL2eCzWZz5xiWbSC_pkF-R0bywMcNQfWA4L6RWwXl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