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

    <tr>
        <th>Summary</th>
        <td>
            powerpc64le: power9 codgen bug when generating setb instructions
        </td>
    </tr>

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

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

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

<pre>
    The rust frontend ran into a bug when running tests on ppc64le with pgo enabled on [centos](https://kojihub.stream.centos.org/kojifiles/vol/koji02/packages/rust/1.86.0/1.el10/data/logs/ppc64le/build.log). The compilation of the compiler's `rustc_errors` crate with `-mcpu=power9` created a bug where a boolean value is clobbered, resulting in incorrect json values.

I was able to extract the llvm input from rust, and run `llvm-reduce` to produce a reasonably sized reproducer using the upstream llvm repo. 

The following codegen is suspect:
```
        andi. 3, 4, 1
        setb 3, 2
        cmpldi  4, 0
        std 28, 80(1) # 8-byte Folded Spill
        stw 3, 60(1)
```
Notably, `cr2` in the `setb` above has no live value (I am assuming this is following the ELFv2 ABI).

After the `machine-cp` pass, a copy from `cr0gt` to `cr2lt` goes missing. Likewise, the other bits of `cr2` appear to be undefined. Furthermore, `setb` potentially examines all bits of the input `cr`, so moving one bit is not sufficient for well-defined behavior.

Attached is the reduced llvm input [reduced.ll.txt](https://github.com/user-attachments/files/20717223/reduced.ll.txt). Likewise, I assembled it via:
```
llc -march=ppc64le -mcpu=pwr9 reduced.ll.ltxt
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8Vc2OozgXfRpncxUEJhBYsEh1f0gltb7NzH5k7Au429jIP0nXPP3oAlWVnhlNFCXg-3d8DhyLEPRkETtWvbDq60mkODvfrUvyp8Gpt-73GcGnEGH0zka0CrywoG10IGBIEzxmtOCTtdpOEDHEAM7Cusr6YhAeOs6wTg7QisGgohirXiTa6AKrvjLezDGugZU3x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