This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR 29984, PPC-SPE segfaults with MAX_EXPR <a, a>


Hi,
  This patch fixes two issues, first this fixes a missed optimization
with the reassociation pass with MIN_EXPR and MAX_EXPR.  As a side
effect it also fixes a testcase where the PPC-SPE compiler segfaults (or
ICEs).  The reason why it ICEs is because the backend is not ready ready
to handle MAX_EXPR <a, a> which was created by the reassociation pass in
the first place.

OK? Bootstrapped and tested on i686-linux-gnu with no regressions.

Thanks,
Andrew Pinski

ChangeLog:

	* tree-ssa-reassoc.c (eliminate_duplicate_pair): Handle MAX_EXPR
	and MIN_EXRP.

	* gcc.dg/tree-ssa/reassoc-12.c: New test.
Index: testsuite/gcc.dg/tree-ssa/reassoc-12.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/reassoc-12.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/reassoc-12.c	(revision 0)
@@ -0,0 +1,11 @@
+/* { dg-do compile } */ 
+/* { dg-options "-O2 -fdump-tree-reassoc1-details" } */
+int f(int a, int b)
+{
+  /* MAX_EXPR <a, a> should cause it to be equivalent to a.  */
+  int c = a>=b?a:b;
+  int d = c>=a?c:a;
+  return d;
+}
+/* { dg-final { scan-tree-dump-times "Equivalence:" 1 "reassoc1"} } */
+/* { dg-final { cleanup-tree-dump "reassoc1" } } */
Index: tree-ssa-reassoc.c
===================================================================
--- tree-ssa-reassoc.c	(revision 119229)
+++ tree-ssa-reassoc.c	(working copy)
@@ -417,8 +417,8 @@ eliminate_duplicate_pair (enum tree_code
 			  operand_entry_t last)
 {
 
-  /* If we have two of the same op, and the opcode is & or |, we can
-     eliminate one of them.
+  /* If we have two of the same op, and the opcode is & |, min, or max,
+     we can eliminate one of them.
      If we have two of the same op, and the opcode is ^, we can
      eliminate both of them.  */
 
@@ -426,13 +426,15 @@ eliminate_duplicate_pair (enum tree_code
     {
       switch (opcode)
 	{
+	case MAX_EXPR:
+	case MIN_EXPR:
 	case BIT_IOR_EXPR:
 	case BIT_AND_EXPR:
 	  if (dump_file && (dump_flags & TDF_DETAILS))
 	    {
 	      fprintf (dump_file, "Equivalence: ");
 	      print_generic_expr (dump_file, curr->op, 0);
-	      fprintf (dump_file, " [&|] ");
+	      fprintf (dump_file, " [&|minmax] ");
 	      print_generic_expr (dump_file, last->op, 0);
 	      fprintf (dump_file, " -> ");
 	      print_generic_stmt (dump_file, last->op, 0);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]