The following patch solves

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

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

commit 81d762cbec9685c2f2571da21d48f42c42eff33b
Author: Vladimir N. Makarov <vmaka...@redhat.com>
Date:   Wed Mar 22 12:33:11 2023 -0400

    LRA: Do not repeat inheritance and live range splitting in case of asm error
    
    LRA was trying to do live range splitting again and again as there were
    no enough regs for asm.  This patch solves the problem.
    
            PR target/109137
    
    gcc/ChangeLog:
    
            * lra.cc (lra): Do not repeat inheritance and live range splitting
            when asm error is found.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr109137.c: New.

diff --git a/gcc/lra.cc b/gcc/lra.cc
index f7fdd601e71..eb3ee1f8b63 100644
--- a/gcc/lra.cc
+++ b/gcc/lra.cc
@@ -2453,7 +2453,7 @@ lra (FILE *f)
 		  lra_hard_reg_split_p = true;
 		}
 	    }
-	  while (fails_p);
+	  while (fails_p && !lra_asm_error_p);
 	  if (! live_p) {
 	    /* We need the correct reg notes for work of constraint sub-pass.  */
 	    lra_create_live_ranges (true, true);
diff --git a/gcc/testsuite/gcc.target/i386/pr109137.c b/gcc/testsuite/gcc.target/i386/pr109137.c
new file mode 100644
index 00000000000..ffd8e8c574b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr109137.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-m32 -O3 -march=znver1 -fPIC -mfpmath=sse -w" } */
+#include <string.h>
+typedef struct {
+  char bytestream_end;
+} CABACContext;
+int get_cabac___trans_tmp_3, get_cabac_tmp, get_cabac_c,
+    decode_cabac_mb_intra4x4_pred_mode_mode, ff_h264_decode_mb_cabac_h_0,
+    ff_h264_decode_mb_cabac_bit;
+typedef struct {
+  char intra4x4_pred_mode_cache[2];
+} H264SliceContext;
+H264SliceContext ff_h264_decode_mb_cabac_sl;
+void ff_h264_decode_mb_cabac(void) {
+  memset((void*)ff_h264_decode_mb_cabac_h_0, 6, 48);
+  int i;
+  for (;; i++) {
+    __asm__(""/* { dg-error "'asm' operand has impossible constraints" } */
+            : "=&r"(ff_h264_decode_mb_cabac_bit), "=&r"(get_cabac_c),
+              "=&r"(get_cabac_c), "=&q"(get_cabac_tmp)
+            : "r"(get_cabac___trans_tmp_3),
+              "r"(__builtin_offsetof(CABACContext, bytestream_end))
+            : "ecx");
+    ff_h264_decode_mb_cabac_sl.intra4x4_pred_mode_cache[i] =
+        decode_cabac_mb_intra4x4_pred_mode_mode;
+  }
+}
+

Reply via email to