diff mbox series

[pushed,PR111225,LRA] : Don't reuse chosen insn alternative with special memory constraint

Message ID a1ae20a6-b756-c9dd-6fed-d080de618d48@redhat.com
State New
Headers show
Series [pushed,PR111225,LRA] : Don't reuse chosen insn alternative with special memory constraint | expand

Commit Message

Vladimir Makarov Sept. 7, 2023, 2:06 p.m. UTC
The following patch solves

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

The patch was successfully bootstrapped and tested on x86-64, aarch64, 
and ppc64le.
diff mbox series

Patch

commit f7bca44d97ad01b39f9d6e7809df7bf517eeb2fb
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date:   Thu Sep 7 09:59:10 2023 -0400

    [LRA]: Don't reuse chosen insn alternative with special memory constraint
    
    To speed up GCC, LRA reuses chosen alternative from previous
    constraint subpass.  A spilled pseudo is considered ok for any memory
    constraint although stack slot assigned to the pseudo later might not
    satisfy the chosen alternative constraint.  As we don't consider all insn
    alternatives on the subsequent LRA sub-passes, it might result in LRA failure
    to generate the correct insn.  This patch solves the problem.
    
    gcc/ChangeLog:
    
            PR target/111225
            * lra-constraints.cc (goal_reuse_alt_p): New global flag.
            (process_alt_operands): Set up the flag.  Clear flag for chosen
            alternative with special memory constraints.
            (process_alt_operands): Set up used insn alternative depending on the flag.
    
    gcc/testsuite/ChangeLog:
    
            PR target/111225
            * gcc.target/i386/pr111225.c: New test.

diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc
index c718bedff32..3aaa4906999 100644
--- a/gcc/lra-constraints.cc
+++ b/gcc/lra-constraints.cc
@@ -1462,6 +1462,9 @@  static int goal_alt_matches[MAX_RECOG_OPERANDS];
 static int goal_alt_dont_inherit_ops_num;
 /* Numbers of operands whose reload pseudos should not be inherited.  */
 static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
+/* True if we should try only this alternative for the next constraint sub-pass
+   to speed up the sub-pass.  */
+static bool goal_reuse_alt_p;
 /* True if the insn commutative operands should be swapped.  */
 static bool goal_alt_swapped;
 /* The chosen insn alternative.	 */
@@ -2130,6 +2133,7 @@  process_alt_operands (int only_alternative)
   int curr_alt_dont_inherit_ops_num;
   /* Numbers of operands whose reload pseudos should not be inherited.	*/
   int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
+  bool curr_reuse_alt_p;
   /* True if output stack pointer reload should be generated for the current
      alternative.  */
   bool curr_alt_out_sp_reload_p;
@@ -2217,6 +2221,7 @@  process_alt_operands (int only_alternative)
       reject += static_reject;
       early_clobbered_regs_num = 0;
       curr_alt_out_sp_reload_p = false;
+      curr_reuse_alt_p = true;
       
       for (nop = 0; nop < n_operands; nop++)
 	{
@@ -2574,7 +2579,10 @@  process_alt_operands (int only_alternative)
 		      if (satisfies_memory_constraint_p (op, cn))
 			win = true;
 		      else if (spilled_pseudo_p (op))
-			win = true;
+			{
+			  curr_reuse_alt_p = false;
+			  win = true;
+			}
 		      break;
 		    }
 		  break;
@@ -3318,6 +3326,7 @@  process_alt_operands (int only_alternative)
 	      goal_alt_offmemok[nop] = curr_alt_offmemok[nop];
 	    }
 	  goal_alt_dont_inherit_ops_num = curr_alt_dont_inherit_ops_num;
+	  goal_reuse_alt_p = curr_reuse_alt_p;
 	  for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++)
 	    goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop];
 	  goal_alt_swapped = curr_swapped;
@@ -4399,7 +4408,8 @@  curr_insn_transform (bool check_only_p)
     }
 
   lra_assert (goal_alt_number >= 0);
-  lra_set_used_insn_alternative (curr_insn, goal_alt_number);
+  lra_set_used_insn_alternative (curr_insn, goal_reuse_alt_p
+				 ? goal_alt_number : LRA_UNKNOWN_ALT);
 
   if (lra_dump_file != NULL)
     {
diff --git a/gcc/testsuite/gcc.target/i386/pr111225.c b/gcc/testsuite/gcc.target/i386/pr111225.c
new file mode 100644
index 00000000000..5d92daf215b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr111225.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O1 -fsanitize=thread -mforce-drap -mavx512cd" } */
+
+typedef long long __m256i __attribute__ ((__vector_size__ (32)));
+
+int foo (__m256i x, __m256i y)
+{
+  __m256i a = x & ~y;
+  return !__builtin_ia32_ptestz256 (a, a);
+}
+
+int bar (__m256i x, __m256i y)
+{
+  __m256i a = ~x & y;
+  return !__builtin_ia32_ptestz256 (a, a);
+}