[pushed,PR118017,LRA] : Don't inherit reg of non-uniform reg class

Message ID 9673bd05-8463-4016-9599-82c8e77b84b1@redhat.com
State New
Headers
Series [pushed,PR118017,LRA] : Don't inherit reg of non-uniform reg class |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Vladimir Makarov Jan. 9, 2025, 9:28 p.m. UTC
  The patch in the attachment solves

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

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

Patch

commit 6ffaed8d8713874b7c4ee112249ed82222a91ff9
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date:   Thu Jan 9 16:22:02 2025 -0500

    [PR118017][LRA]: Don't inherit reg of non-uniform reg class
    
    In the PR case LRA inherited value of register of class INT_SSE_REGS
    which resulted in LRA cycling when LRA tried to use different move
    alternatives with SSE/general regs and memory.  The patch rejects to
    inherit such (non-uniform) classes to prevent cycling.
    
    gcc/ChangeLog:
    
            PR target/118017
            * lra-constraints.cc (inherit_reload_reg): Check reg class on uniformity.
    
    gcc/testsuite/ChangeLog:
    
            PR target/118017
            * gcc.target/i386/pr118017.c: New.

diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index a0f05b290dd..8f32e98f1c4 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -5878,6 +5878,20 @@  inherit_reload_reg (bool def_p, int original_regno,
 	}
       return false;
     }
+  if (ira_reg_class_min_nregs[rclass][GET_MODE (original_reg)]
+      != ira_reg_class_max_nregs[rclass][GET_MODE (original_reg)])
+    {
+      if (lra_dump_file != NULL)
+	{
+	  fprintf (lra_dump_file,
+		   "    Rejecting inheritance for %d "
+		   "because of requiring non-uniform class %s\n",
+		   original_regno, reg_class_names[rclass]);
+	  fprintf (lra_dump_file,
+		   "    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
+	}
+      return false;
+    }
   new_reg = lra_create_new_reg (GET_MODE (original_reg), original_reg,
 				rclass, NULL, "inheritance");
   start_sequence ();
diff --git a/gcc/testsuite/gcc.target/i386/pr118017.c b/gcc/testsuite/gcc.target/i386/pr118017.c
new file mode 100644
index 00000000000..c82d71e8d29
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr118017.c
@@ -0,0 +1,21 @@ 
+/* PR target/118017 */
+/* { dg-do compile } */
+/* { dg-options "-Og -frounding-math -mno-80387 -mno-mmx -Wno-psabi" } */
+
+typedef __attribute__((__vector_size__ (64))) _Float128 F;
+typedef __attribute__((__vector_size__ (64))) _Decimal64 G;
+typedef __attribute__((__vector_size__ (64))) _Decimal128 H;
+
+void
+bar(_Float32, _BitInt(1025), _BitInt(1025), _Float128, __int128, __int128,  F,
+        int, int, G, _Float64, __int128, __int128, H, F);
+
+
+void
+foo ()
+{
+  bar ((__int128)68435455, 0, 0, 0, 0, 0, (F){}, 0, 0, (G){3689348814741910323},
+       0, 0, 0, (H){0, (_Decimal128) ((__int128) 860933398830926 << 64),
+       (_Decimal128) ((__int128) 966483857959145 << 64), 4},
+       (F){(__int128) 3689348814741910323 << 64 | 3});
+}