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

    <tr>
        <th>Summary</th>
        <td>
            __builtin_nondeterministic_value is converted to a zero
        </td>
    </tr>

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

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

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

<pre>
    The code:

```c
void f(int x, int a, int b) {
    ext(__builtin_nondeterministic_value(5), a, b);
}
```

gets optimized to `ext(0, a, b);`, thus ending up with an unnecessary zeroing of a register. IR-wise, a `freeze i32 poison` becomes `0` during instcombine. https://godbolt.org/z/6rxsdr634

This means that `__builtin_nondeterministic_value` is unsuitable for efficiently calling a function where the caller knows that the callee won't use some argument(s). The only option that roughly works that I've found is to read an uninitialized variable, but that produces a warning and breaks under memorysanitizer.

Passing the pre-instcombine IR directly to the backend generates the desired assembly: https://godbolt.org/z/on6W17ex4
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVE2P4ygQ_TX4UuoIY8dODj7MbCtS31ajkfbYwlC2axtDBEXSya9f4fTstmYPLVk25uO9V-8BOiWaPeIg9t_F_rnSmZcQB3vXtOpqDPY2_FwQTLAomm9CPgv5693Jx2Me_5dAFiahDuQZ3oX6A0pD_2qMQh1B9N8fkwEA8J2FOry-jpkck3_1wVtkjCt5Skzm9aJdRqEOe6GOBWbDKjii-YAR_fNvYj4rnJEThDPTSne0wAFEJx-s8n943dbFS06A3pKfIZ_hSryA9pC9R4Mp6XiDO8ZQhsMEGiLOlBjjDl5-PF0p4YZbeKaIeEegRsE5UApedBJGNGHFVMaLWLA5FijyiU1YR_K4g4X5nIrX6iTUaQ52DI53Ic5Cne5Cnbr4nmzsmvZzqT8XSrCi9gl40VwIvjS2k0AJsk-ZWI8OYQoRcJrIEHp2NzDauSJPw5S9YQoergtGBC47QjuHEd58uH5w_tuLcA1eqJ4hJ4QUVgQd57yiL9YnoY47KJsqeHfb8gn-gRBDnhd3g2uIbx-gL0L1lyIte1vkcoCI2j5CIU9M2m3pXnSkUsWWaebH6nMMNhtMoOGqo9-K8RbGiPqtlG4xwopriLekC9Yd4-6zrX-W4-HnrbRzxKdPQcHLD7AU0RSnOGxTRm3e0FuY0WPUjGnrtZgoogWdEq6ju4nm25chB9_9Vff43lZ2aOyxOeoKh7pXqqlV1-yrZcDaIB5U19SttC12eFQ9NqZFvcdm0qaiQUnVyr6Rsq1ls9916mgOpm0Po-56OR1EK3HV5HbOXdbCXVFKGYda1rWqK6dHdGm7F5TyeIVtVChVrok4lEVPY56TaKWjxOk_GCZ2OHy1_0qaJvgLRn4cTr0drSpHN_xmD_GSx50Jq1CnwvLxeTrH8DcaFuq0aUtCnT7EXwb1TwAAAP__cMCXHw">