diff mbox series

[i386] : FIx PR 86994, gcc.target/i386/20040112-1.c FAILs

Message ID CAFULd4b-zsNMH2RM++FThN9B_Zt7jmPD=ryiDSpjCc3h0rtjwA@mail.gmail.com
State New
Headers show
Series [i386] : FIx PR 86994, gcc.target/i386/20040112-1.c FAILs | expand

Commit Message

Uros Bizjak Aug. 19, 2018, 7:08 p.m. UTC
On Sat, Aug 18, 2018 at 12:11 PM, Richard Sandiford
<richard.sandiford@arm.com> wrote:

> The problem in this case is that insn_cost says:
>
>   (set (reg:QI X) (const_int 0))
>
> has a cost of 4 but:
>
>   (set (reg:QI X) (const_int -1))
>
> has a cost of 2.  So the costs make -1 seem like the cheaper immediate.
>
> This in turn seems to be a bad interaction between ix86_rtx_costs and:
>
>   cost = set_src_cost (SET_SRC (set), GET_MODE (SET_DEST (set)), speed);
>   return cost > 0 ? cost : COSTS_N_INSNS (1);
>
> in pattern_cost.  ix86_rtx_costs returns 0 for 0 and 2 for -1, where 2
> is a sub-insn cost.  But pattern_cost converts the 0 cost into the cost
> of a full instruction, making 0 seem more expensive than -1.

Let's go with the attached patch then, which simplifies calculating
costs of immediate operands a bit. The idea is that everything that
can be stuffed into immediate field of an insn gets cost 0, and
everything else gets cost 1. This is not entirely correct, considering
how return of 0 is treated, but it is a minimum change that gets the
job done and doesn't regress the testsuite. If needed, we'll
eventually refine it later.

2018-08-19  Uros Bizjak  <ubizjak@gmail.com>

    PR target/86994
    * config/i386/i386.c (ix86_rtx_costs) [case SET]: Check source for
    register_operand when calling ix86_set_reg_reg_cost.
    [case CONST_INT, case CONST, case LABEL_REF, case SYMBOL_REF]:
    Set *total to 0 for operands that satisfy x86_64_immediate_operand
    predicate and to 1 otherwise.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Committed to mainline SVN.

Uros.
diff mbox series

Patch

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 263644)
+++ config/i386/i386.c	(working copy)
@@ -40554,7 +40554,7 @@  ix86_rtx_costs (rtx x, machine_mode mode, int oute
     {
     case SET:
       if (register_operand (SET_DEST (x), VOIDmode)
-	  && reg_or_0_operand (SET_SRC (x), VOIDmode))
+	  && register_operand (SET_SRC (x), VOIDmode))
 	{
 	  *total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
 	  return true;
@@ -40581,20 +40581,10 @@  ix86_rtx_costs (rtx x, machine_mode mode, int oute
     case CONST:
     case LABEL_REF:
     case SYMBOL_REF:
-      if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
-	*total = 3;
-      else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
-	*total = 2;
-      else if (flag_pic && SYMBOLIC_CONST (x)
-	       && !(TARGET_64BIT
-		    && (GET_CODE (x) == LABEL_REF
-			|| (GET_CODE (x) == SYMBOL_REF
-			    && SYMBOL_REF_LOCAL_P (x))))
-	       /* Use 0 cost for CONST to improve its propagation.  */
-	       && (TARGET_64BIT || GET_CODE (x) != CONST))
+      if (x86_64_immediate_operand (x, VOIDmode))
+	*total = 0;
+     else
 	*total = 1;
-      else
-	*total = 0;
       return true;
 
     case CONST_DOUBLE: