[committed,PR99531] IRA:Modify pseudo class cost calculation when processing move involving the pseudo and a hard register

Message ID 33833f83-4941-d859-1ca3-f879425708da@redhat.com
State Committed
Headers
Series [committed,PR99531] IRA:Modify pseudo class cost calculation when processing move involving the pseudo and a hard register |

Commit Message

Vladimir Makarov Dec. 13, 2021, 7:12 p.m. UTC
  The following patch solves

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

The patch was successfully bootstrapped and tested on x86-64, aarch64, 
and ppc64.

After some observation, if all is ok, I will commit the patch into gcc 
release branches mentioned in the PR.
  

Patch

    [PR99531] Modify pseudo class cost calculation when processing move involving the pseudo and a hard register
    
    Pseudo class calculated on the 1st iteration should not have a
    special treatment in cost calculation when processing move involving
    the pseudo and a hard register.
    
    gcc/ChangeLog:
    
            PR target/99531
            * ira-costs.c (record_operand_costs): Do not take pseudo class
            calculated on the 1st iteration into account when processing move
            involving the pseudo and a hard register.
    
    gcc/testsuite/ChangeLog:
    
            PR target/99531
            * gcc.target/i386/pr99531.c: New test.

diff --git a/gcc/ira-costs.c b/gcc/ira-costs.c
index cb5ca8bc21b..d7191dcee3e 100644
--- a/gcc/ira-costs.c
+++ b/gcc/ira-costs.c
@@ -1310,7 +1310,7 @@  record_operand_costs (rtx_insn *insn, enum reg_class *pref)
 	  machine_mode mode = GET_MODE (SET_SRC (set));
 	  cost_classes_t cost_classes_ptr = regno_cost_classes[regno];
 	  enum reg_class *cost_classes = cost_classes_ptr->classes;
-	  reg_class_t rclass, hard_reg_class, pref_class, bigger_hard_reg_class;
+	  reg_class_t rclass, hard_reg_class, bigger_hard_reg_class;
 	  int cost, k;
 	  move_table *move_costs;
 	  bool dead_p = find_regno_note (insn, REG_DEAD, REGNO (src));
@@ -1336,23 +1336,6 @@  record_operand_costs (rtx_insn *insn, enum reg_class *pref)
 		      : move_costs[rclass][hard_reg_class]);
 	      
 	      op_costs[i]->cost[k] = cost * frequency;
-	      /* If we have assigned a class to this allocno in our
-		 first pass, add a cost to this alternative
-		 corresponding to what we would add if this allocno
-		 were not in the appropriate class.  */
-	      if (pref)
-		{
-		  if ((pref_class = pref[COST_INDEX (regno)]) == NO_REGS)
-		    op_costs[i]->cost[k]
-		      += ((i == 0 ? ira_memory_move_cost[mode][rclass][0] : 0)
-			  + (i == 1 ? ira_memory_move_cost[mode][rclass][1] : 0)
-			  * frequency);
-		  else if (ira_reg_class_intersect[pref_class][rclass]
-			   == NO_REGS)
-		    op_costs[i]->cost[k]
-		      += (move_costs[pref_class][rclass]
-			  * frequency);
-		}
 	      /* If this insn is a single set copying operand 1 to
 		 operand 0 and one operand is an allocno with the
 		 other a hard reg or an allocno that prefers a hard
@@ -1378,9 +1361,6 @@  record_operand_costs (rtx_insn *insn, enum reg_class *pref)
 	    }
 	  op_costs[i]->mem_cost
 	    = ira_memory_move_cost[mode][hard_reg_class][i] * frequency;
-	  if (pref && (pref_class = pref[COST_INDEX (regno)]) != NO_REGS)
-	    op_costs[i]->mem_cost
-	      += ira_memory_move_cost[mode][pref_class][i] * frequency;
 	  return;
 	}
     }
diff --git a/gcc/testsuite/gcc.target/i386/pr99531.c b/gcc/testsuite/gcc.target/i386/pr99531.c
new file mode 100644
index 00000000000..0e1a08b7c77
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr99531.c
@@ -0,0 +1,7 @@ 
+/* { dg-do compile { target { x86_64-*-linux* } } } */
+/* { dg-options "-O2" } */
+
+int func(int, int, int, int, int, int);
+int caller(int a, int b, int c, int d, int e) { return func(0, a, b, c, d, e); }
+
+/* { dg-final { scan-assembler-not "push" } } */