https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128794
--- Comment #3 from Roger Sayle <roger at nextmovesoftware dot com> --- Created attachment 66210 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66210&action=edit proposed patch So looking a little deeper into this issue reveals that it's actually a missed optimization opportunity. Notice that the new code for ubar is: mpy.f r0,r0,r1 mov_s r2,5 ;3 j_s.d [blink] mov.eq r0,r2 when (with this patch) it could be: mpy.f r0,r0,r1 j_s.d [blink] mov.eq r0,5 The hold-up is that in combine we see, but fail to recognize: (set (reg/v:SI 152 [ <retval> ]) (if_then_else:SI (ne (reg:CC_ZN 61 cc) (const_int 0 [0])) (reg/v:SI 152 [ <retval> ]) (const_int 5 [0x5]))) The recent patch to *movsicc_insn allowed it to invert the condition, to swap the true and false branches if they are both registers. Alas, this helps (eliminates a mov instruction) when we have two registers, but doesn't help when the problematic operand is an immediate constant. This patch adds a second define_insn to specifically handle the case that the else operand of a movsicc_insn is a constant. As shown in the regressed test case, this allows us to reduce the number of instructions. If someone can (please) confirm that this is OK on real hardware, the regression status of this PR should allow us to get this optimization into GCC 17.
