[Bug tree-optimization/71336] Suboptimal code generated for "(a & 1) ? (CST1 + CST2) : CST1"

law at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Oct 25 17:06:28 GMT 2025


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71336

--- Comment #12 from Jeffrey A. Law <law at gcc dot gnu.org> ---
So a note for RV64.  I think this case could be improved into something like
this:

andi    a0,a0,1
slli    a0,a0,2
addi    a0,a0,3

That's the most straightforward improvement and probably suitable for match.pd.

Further improvement would be to:

li t0,3
andi a0,a0,1
sh2add a0,a0,t0

That's marginally better as  the "li" can issue whenever is convenient for an
OoO core (and gives sched freedom to hoist it as well).  This would be
absolutely target dependent.


More information about the Gcc-bugs mailing list