[RFC][PR target/90000] Compile time hog w/impossible asm constraint lra loop
    
Hi,
  RFC for a bandaid/patch to partially address target PR/90000.

This adds an escape condition from the forever loop where 
LRA gets stuck while attempting to handle constraints from an 
instruction that has previously suffered an impossible constraint error.

This is somewhat inspired by MAX_RELOAD_INSNS_NUMBER as
seen in lra-constraints.c lra_constraints().   This utilizes the
existing counter variable lra_constraint_iter.

More needs to be done here, as this does replace a spin-forever
situation with an ICE.

Thanks
-Will


gcc/
2020-04-10  Will Schmidt  <will_schm...@vnet.ibm.com>

        * lra.c: Add include of rtl-error.h.
        (MAX_LRA_CONSTRAINT_PASSES): New define.
        (lra): Add check of lra_constraint_iter value.



diff --git a/gcc/lra.c b/gcc/lra.c
index 5e8b75b..36f5dd9 100644
--- a/gcc/lra.c
+++ b/gcc/lra.c
@@ -116,15 +116,22 @@ along with GCC; see the file COPYING3.    If not see
 #include "ira.h"
 #include "recog.h"
 #include "expr.h"
 #include "cfgrtl.h"
 #include "cfgbuild.h"
+#include "rtl-error.h"
 #include "lra.h"
 #include "lra-int.h"
 #include "print-rtl.h"
 #include "function-abi.h"
 
+/*  Bail-out from lra-constraint processing.
+  This band-aid prevents an infinite loop after we have previously
+  experienced an invalid constraint error, and our lra processing
+  has gotten stuck repeatedly inserting instructions.  (PR/90060) */
+#define  MAX_LRA_CONSTRAINT_PASSES 100
+
 /* Dump bitmap SET with TITLE and BB INDEX.  */
 void
 lra_dump_bitmap_with_title (const char *title, bitmap set, int index)
 {
   unsigned int i;
@@ -2520,10 +2527,17 @@ lra (FILE *f)
          if (! live_p) {
            /* We need the correct reg notes for work of constraint sub-pass.  
*/
            lra_create_live_ranges (true, true);
            live_p = true;
          }
+         if (lra_constraint_iter > MAX_LRA_CONSTRAINT_PASSES)
+           {
+             internal_error
+               ("maximum number of lra constraint passes achieved (%d)",
+                MAX_LRA_CONSTRAINT_PASSES);
+              break;
+         }
        }
       /* Don't clear optional reloads bitmap until all constraints are
         satisfied as we need to differ them from regular reloads.  */
       bitmap_clear (&lra_optional_reload_pseudos);
       bitmap_clear (&lra_subreg_reload_pseudos);

Reply via email to