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

    <tr>
        <th>Summary</th>
        <td>
            llvm/amdgcn: regression with `-cl-fast-relaxed-math` (compute doesn't produce correct result)
        </td>
    </tr>

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

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

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

<pre>
    The issue was first reported on Mesa side, but it looks like the issue is not on Mesa side:

- https://gitlab.freedesktop.org/mesa/mesa/-/issues/5671  
_clover: OpenCL regression with LuxMark 3.1 and -cl-fast-relaxed-math default option: it now renders garbage but it worked before_

The issue can be reproduced with the [Luxmark 3.1](http://wiki.luxcorerender.org/LuxMark_v3#Binaries) OpenCL benchmark tool.

How it looked before with `-cl-fast-relaxed-math` enabled or not, and how it looks today if `-cl-fast-relaxed-math` is **disabled**:

[![](https://dl.illwieckz.net/b/mesa/bugs/clover-amdgcn-luxmark-garbage/20220406-022232-000.luxmark-mesa-clover-oland-r7-240-2gd5-l.png)](https://dl.illwieckz.net/b/mesa/bugs/clover-amdgcn-luxmark-garbage/20220406-022232-000.luxmark-mesa-clover-oland-r7-240-2gd5-l.png)

How it now looks like with `-cl-fast-relaxed-math` enabled:

[![](https://dl.illwieckz.net/b/mesa/bugs/clover-amdgcn-luxmark-garbage/20220327-212141-000.luxmark-mesa-clover-hawaii-r9-390x.png)](https://dl.illwieckz.net/b/mesa/bugs/clover-amdgcn-luxmark-garbage/20220327-212141-000.luxmark-mesa-clover-hawaii-r9-390x.png)

The `-cl-fast-relaxed-math` option is enabled by default by LuxMark, so the correct render is expected to be produced with `-cl-fast-relaxed-math` enabled.

Karol Herbst [said](https://gitlab.freedesktop.org/mesa/mesa/-/issues/5671#note_1328388):

> mhh, smells like something broke inside llvm or radeonsi. Clover itself doesn't really do anything with -cl-fast-relaxed-math besides passing it on to LLVM

He is right about the fact `-cl-fast-relaxed-math` is an LLVM OpenCL command line option:

- https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-cl-fast-relaxed-math

> `-cl-fast-relaxed-math`
> OpenCL only. Sets `-cl-finite-math-only` and `-cl-unsafe-math-optimizations`, and defines `__FAST_RELAXED_MATH__`.

It is known to be working with old LLVM 9-based Ubuntu packages ([proof](http://luxmark.info/node/9355)). One can use my [`ubuntu-amdgpu`](https://gitlab.com/illwieckz/i-love-compute/-/blob/master/scripts/ubuntu-amdgpu) script to install a working Clover/LLVM on Ubuntu 20.04 or 21.10 that does not reproduce the bug, or to use my [`user-mesa`](https://gitlab.com/illwieckz/i-love-compute/-/blob/master/scripts/user-mesa) script to build a current LLVM//mesa that reproduces the bug.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVttu2zgQ_Rr7haAgU7JjPfghzQVZrIMCbXexbwYlUhbXFGmQVBz363eGkuU4TbNFgb0AiS2L5HDOmZkzU1pxXH1pJFHed5IcuCe1cj4QJ_fWBSmINeRRek68EnLCbkjZBaIC0dbuPNFqJ0kYjytPjA2XR7LrSXo7SYdPSpoQ9h7fsnv426qgeZnUTkoh_S7YfWLdFhZaMHD-ovAfr_DwMF9czQjp7W0qbZ-kA3vk416amzU4vnXSewVOHFRoyLp7fuRuR7JkRrgRhFaa1twH6qTmz1LQlsMuIWveaXB9H-AkmgOMxh7AnBHSebLlruRbeYJ_sG4H5JSytk5uXiI8k1lxAxuQSWdFV8H26BDSNZl_AL_awa_J_HbClkjMyMtB7VSiu-cKzPcuDLwMcDZP2YRlH5ThTiEpxQl-KU3VRMPBWp289OwB4AyRG13vXZos0jdpgfdEGl5qzAOHscUMQBabsy0PNwl-JKp-1w7kxoQBumuhfLTY_3qVH0DMhM3wc-TknCxCJ0rrg5LV7mtiJDhzX55zpOy2mB19QlDeim1lqO5ZpkP4YJ2ljKV5uqDwzTJG0zRNTrvQEh0MWA04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