diff mbox series

ira: Fix go_through_subreg offset calculation [PR115281]

Message ID mpt7cfbenlu.fsf@arm.com
State New
Headers show
Series ira: Fix go_through_subreg offset calculation [PR115281] | expand

Commit Message

Richard Sandiford May 30, 2024, 7:59 a.m. UTC
go_through_subreg used:

  else if (!can_div_trunc_p (SUBREG_BYTE (x),
			     REGMODE_NATURAL_SIZE (GET_MODE (x)), offset))

to calculate the register offset for a pseudo subreg x.  In the blessed
days before poly-int, this was:

    *offset = (SUBREG_BYTE (x) / REGMODE_NATURAL_SIZE (GET_MODE (x)));

But I think this is testing the wrong natural size.  If we exclude
paradoxical subregs (which will get an offset of zero regardless),
it's the inner register that is being split, so it should be the
inner register's natural size that we use.

This matters in the testcase because we have an SFmode lowpart
subreg into the last of three variable-sized vectors.  The
SUBREG_BYTE is therefore equal to the size of two variable-sized
vectors.  Dividing by the vector size gives a register offset of 2,
as expected, but dividing by the size of a scalar FPR would give
a variable offset.

I think something similar could happen for fixed-size targets if
REGMODE_NATURAL_SIZE is different for vectors and integers (say).

Tested on aarch64-linux-gnu & x86_64-linux-gnu.  OK to install?

Richard


gcc/
	PR rtl-optimization/115281
	* ira-conflicts.cc (go_through_subreg): Use the natural size of
	the inner mode rather than the outer mode.

gcc/testsuite/
	PR rtl-optimization/115281
	* gfortran.dg/pr115281.f90: New test.
---
 gcc/ira-conflicts.cc                   |  3 +-
 gcc/testsuite/gfortran.dg/pr115281.f90 | 39 ++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr115281.f90

Comments

Vladimir Makarov May 30, 2024, 2:44 p.m. UTC | #1
On 5/30/24 03:59, Richard Sandiford wrote:
>
> Tested on aarch64-linux-gnu & x86_64-linux-gnu.  OK to install?
Yes.  Thank you, Richard.
>
> gcc/
> 	PR rtl-optimization/115281
> 	* ira-conflicts.cc (go_through_subreg): Use the natural size of
> 	the inner mode rather than the outer mode.
>
> gcc/testsuite/
> 	PR rtl-optimization/115281
> 	* gfortran.dg/pr115281.f90: New test.
diff mbox series

Patch

diff --git a/gcc/ira-conflicts.cc b/gcc/ira-conflicts.cc
index 83274c53330..15ac42d8848 100644
--- a/gcc/ira-conflicts.cc
+++ b/gcc/ira-conflicts.cc
@@ -227,8 +227,9 @@  go_through_subreg (rtx x, int *offset)
   if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
     *offset = subreg_regno_offset (REGNO (reg), GET_MODE (reg),
 				   SUBREG_BYTE (x), GET_MODE (x));
+  /* The offset is always 0 for paradoxical subregs.  */
   else if (!can_div_trunc_p (SUBREG_BYTE (x),
-			     REGMODE_NATURAL_SIZE (GET_MODE (x)), offset))
+			     REGMODE_NATURAL_SIZE (GET_MODE (reg)), offset))
     /* Checked by validate_subreg.  We must know at compile time which
        inner hard registers are being accessed.  */
     gcc_unreachable ();
diff --git a/gcc/testsuite/gfortran.dg/pr115281.f90 b/gcc/testsuite/gfortran.dg/pr115281.f90
new file mode 100644
index 00000000000..80aa822e745
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr115281.f90
@@ -0,0 +1,39 @@ 
+! { dg-options "-O3" }
+! { dg-additional-options "-mcpu=neoverse-v1" { target aarch64*-*-* } }
+
+SUBROUTINE fn0(ma, mb, nt)
+  CHARACTER ca
+  REAL r0(ma)
+  INTEGER i0(mb)
+  REAL r1(3,mb)
+  REAL r2(3,mb)
+  REAL r3(3,3)
+  zero=0.0
+  do na = 1, nt
+     nt = i0(na)
+     do l = 1, 3
+        r1 (l, na) =   r0 (nt)
+        r2(l, na) = zero
+     enddo
+  enddo
+  if (ca  .ne.'z') then
+     do j = 1, 3
+        do i = 1, 3
+           r4  = zero
+        enddo
+     enddo
+     do na = 1, nt
+        do k =  1, 3
+           do l = 1, 3
+              do m = 1, 3
+                 r3 = r4 * v
+              enddo
+           enddo
+        enddo
+     do i = 1, 3
+           do k = 1, ifn (r3)
+           enddo
+        enddo
+     enddo
+     endif
+END