Bug 110071 - improve_allocation() routine should consider save/restore cost of callee-save registers
Summary: improve_allocation() routine should consider save/restore cost of callee-save...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Surya Kumari Jangala
URL:
Keywords: missed-optimization, ra
Depends on:
Blocks:
 
Reported: 2023-06-01 07:55 UTC by Surya Kumari Jangala
Modified: 2024-02-01 08:54 UTC (History)
4 users (show)

See Also:
Host:
Target: powerpc
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-02-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Surya Kumari Jangala 2023-06-01 07:55:01 UTC
For the following test:

long
foo (long i, long cond)
{
  if (cond)
    bar ();
  return i+1;
}
   
Input RTL to IRA:

BB2:
  set r123, r4
  set r122, r3
  set r120, compare(r123, 0)
  set r118, r122
  if r120 jump BB4 else jump BB3
BB3:
  call bar()
BB4:
  set r3, r118+1
  return r3

IRA assigns r31 to r118.
Since r31 is a callee save register in powerpc, we need to generate spill/restore code.

This assignment of r31 to r118 causes shrink wrap to fail for this test.
Since r31 is assigned to r118, BB2 requires a prolog and shrink wrap fails.

In the IRA pass, after graph coloring, r118 gets assigned to r3.
The routine improve_allocation() is called after graph coloring. This routine changes the assignment of r118 to r31.

In improve_allocation() routine, IRA checks for each allocno if spilling any conflicting allocnos can improve the allocation of this allocno. This routine computes the cost improvement for usage of each profitable hard register for a given allocno.

The existing code in improve_allocation() does not consider the save/restore costs of callee save registers while computing the cost improvement.

This bug is for adding save/restore costs while computing cost improvement.

Save/restore costs should be considered only for the first assignment of a callee save register. Subsequent assignments of the same register do not need to consider this cost.
Comment 1 GCC Commits 2023-09-20 01:55:53 UTC
The master branch has been updated by Surya Kumari Jangala <jskumari@gcc.gnu.org>:

https://gcc.gnu.org/g:677249a23243b5b51832611767366d6eb199bdc7

commit r14-4162-g677249a23243b5b51832611767366d6eb199bdc7
Author: Surya Kumari Jangala <jskumari@linux.ibm.com>
Date:   Thu Sep 14 02:12:50 2023 -0500

    ira: Consider save/restore costs of callee-save registers [PR110071]
    
    In improve_allocation() routine, IRA checks for each allocno if spilling
    any conflicting allocnos can improve the allocation of this allocno.
    This routine computes the cost improvement for usage of each profitable
    hard register for a given allocno. The existing code in
    improve_allocation() does not consider the save/restore costs of callee
    save registers while computing the cost improvement.
    
    This can result in a callee save register being assigned to a pseudo
    that is live in the entire function and across a call, overriding a
    non-callee save register assigned to the pseudo by graph coloring. So
    the entry basic block requires a prolog, thereby causing shrink wrap to
    fail.
    
    2023-09-14  Surya Kumari Jangala  <jskumari@linux.ibm.com>
    
    gcc/
            PR rtl-optimization/110071
            * ira-color.cc (improve_allocation): Consider cost of callee
            save registers.
    
    gcc/testsuite/
            PR rtl-optimization/110071
            * gcc.target/powerpc/pr110071.c: New test.
Comment 2 Surya Kumari Jangala 2024-02-01 08:54:01 UTC
Fixed by the commit in comment 1.