On 11/22/19 6:05 PM, Uros Bizjak wrote: > Indeed, this is a different case, an overflow test that results in one > CMP insn. I think, we should check if the second operand is either 0 > (then proceed as it is now), or if the second operand equals first > operand of PLUS insn, then we actually emit CMP insn (please see > PR30315).
Here's what I committed - preapproved by Uros off-list (I forgot Reply-All again). Bernd
Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 278653) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2019-11-24 Bernd Schmidt <bernds_...@t-online.de> + + * config/i386/i386.c (ix86_rtx_costs): Handle care of a PLUS in a + COMPARE, representing an overflow detection. + 2019-11-23 Jan Hubicka <hubi...@ucw.cz> * cif-code.def (MAX_INLINE_INSNS_SINGLE_O2_LIMIT): Remove. Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c (revision 278653) +++ gcc/config/i386/i386.c (working copy) @@ -19501,6 +19501,15 @@ ix86_rtx_costs (rtx x, machine_mode mode return true; } + if (GET_CODE (XEXP (x, 0)) == PLUS + && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1))) + { + /* This is an overflow detection, count it as a normal compare. */ + *total = rtx_cost (XEXP (x, 0), GET_MODE (XEXP (x, 0)), + COMPARE, 0, speed); + return true; + } + /* The embedded comparison operand is completely free. */ if (!general_operand (XEXP (x, 0), GET_MODE (XEXP (x, 0))) && XEXP (x, 1) == const0_rtx)