http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58517
Oleg Endo <olegendo at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |steven at gcc dot gnu.org --- Comment #3 from Oleg Endo <olegendo at gcc dot gnu.org> --- The problematic transformation happens in ifcvt.c (noce_try_cmove_arith). I've only briefly looked over that code and can think of the following options how to fix the issue: 1) Check whether insn_a and insn_b modify the src reg (ccreg) of the conditional branch. If they do, don't do the transformation. On SH, the resulting code would be the same as not specifying -mpretend-cmove: cmp/ge r5,r4 mov r6,r0 bf/s .L6 sub r4,r0 rts nop .L6: sett mov r5,r0 rts subc r4,r0 2) Check whether insn_a and insn_b modify the src reg (ccreg) of the conditional branch. If they do, try to move the insn that sets the ccreg before the conditional branch, _after_ the emitted insn_a and insn_b and right before the conditional move. On SH, the resulting code would look something like this: sett mov r5,r0 sub r4,r6 subc r4,r0 cmp/ge r5,r4 bf 0f mov r6,r0 0: rts nop Steven, since you're RTL optimizers reviewer, could you please provide some feedback regarding the matter?