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

    <tr>
        <th>Summary</th>
        <td>
            PowerPC: Rust test fails when optimized for power9
        </td>
    </tr>

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

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

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

<pre>
    Here is my test case extracted from a Rust LTO build: [reduced.bc.gz](https://github.com/llvm/llvm-project/files/14441197/reduced.bc.gz)
(originally from the rust `image` crate at version 0.23.14)

We ran into a test failure in an EPEL build for CentOS Stream 9 ppc64le, which has LLVM 17.0.6. For the purpose of this report, I am using LLVM main as of commit d1f04443b14f3cfc565656fb14d283f729d95344.

The test works fine (prints "ok") with the default CPU:

```
$ clang -lm reduced.bc -o test && ./test
ok
$ clang -lm reduced.bc -o test -O1 && ./test
ok
```

However, with `-mcpu=power9`, it fails at `-O1`:

```
$ clang -lm reduced.bc -o test -mcpu=power9 && ./test
ok
$ clang -lm reduced.bc -o test -mcpu=power9 -O1 && ./test
thread 'main' panicked at examples/test_bgra16.rs:16:5:
bad red channel in [0, 255, 0]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

At @nikic's suggestion, I tried the optimized build with `-debug-counter=dagcombine-count=0`, and that ran fine. Then I used `bisect-skip-count` to narrow the failure to `-debug-counter=dagcombine-skip=1463229,dagcombine-count=201`. I hope that's a small enough range that someone who knows dagcombine and/or powerpc better can inspect the problem!

I was also trying to reduce the testcase further with llvm-reduce, but I think it quickly got into UB, because even when I verified with an `-O0` build, that got into the weeds where the same build would sometimes print "ok" and sometimes crash.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVVFv2zYX_TX0y0UEipIl68EPjl2jwZcPCdp0eywo8kriTJEaSdlNf_1AyknaYVs3FDYk2CQvzz3n3nO596o3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