llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.23k stars 12.07k forks source link

Useless copies of x0 (zero) to registers used in branch comparisons without ISel patterns explicitly selecting X0 #56872

Open asb opened 2 years ago

asb commented 2 years ago

See D130809 for the patch to work around this in the RISC-V backend by adding additional ISel patterns. As noted by @topperc, the register coalescer doesn't always seem to succeed in doing this, when really it should.

Creating this issue to track the problem, as it would be nice to be able to remove these patterns at a later point if the problem can be identified and resolved.

llvmbot commented 2 years ago

@llvm/issue-subscribers-backend-risc-v

asb commented 2 years ago

@arichardson noted another case where this seems to be happening in the in-tree tests.

topperc commented 2 years ago

Some of the lit test cases that show this have multiple selects being expanded in the same basic block. These end up expanding into phis that use an x0 copy from a basic block that isn't an immediate predecessor of the phi.