diff mbox

[PR68809] Fix same_close_phi_node

Message ID 56E90B9A.1020305@mentor.com
State New
Headers show

Commit Message

Tom de Vries March 16, 2016, 7:30 a.m. UTC
Hi,

this patch fixes graphite PR68809, a 6 regression.

The problem we run into is that we return true in same_close_phi_node 
for two single-argument phis, one with an int 0 argument, and one with a 
char 0 argument:
...
   _1 = PHI <(int)0>
   _2 = PHI <(char)0>
...
The result types of the two phis are not the same though.

So when we replace uses of _1 by uses of _2 in 
remove_duplicate_close_phi, we introduce type errors, which causes an 
ICE during gimple verification.

The patch fixes this by testing for equality of the result type of the 
phis in same_close_phi_node.

Bootstrapped and reg-tested on x86_64.

OK for stage4 trunk?

Thanks,
- Tom

Comments

Richard Biener March 16, 2016, 8:33 a.m. UTC | #1
On Wed, 16 Mar 2016, Tom de Vries wrote:

> Hi,
> 
> this patch fixes graphite PR68809, a 6 regression.
> 
> The problem we run into is that we return true in same_close_phi_node for two
> single-argument phis, one with an int 0 argument, and one with a char 0
> argument:
> ...
>   _1 = PHI <(int)0>
>   _2 = PHI <(char)0>
> ...
> The result types of the two phis are not the same though.
> 
> So when we replace uses of _1 by uses of _2 in remove_duplicate_close_phi, we
> introduce type errors, which causes an ICE during gimple verification.
> 
> The patch fixes this by testing for equality of the result type of the phis in
> same_close_phi_node.
> 
> Bootstrapped and reg-tested on x86_64.
> 
> OK for stage4 trunk?

Please use types_compatible_p () rather than strict equality.

Ok with that change.

Richard.
diff mbox

Patch

Fix same_close_phi_node

2016-03-15  Tom de Vries  <tom@codesourcery.com>

	PR tree-optimization/68809
	* graphite-scop-detection.c (same_close_phi_node): Test if result types
	are the same.

	* gcc.dg/graphite/pr68809-2.c: New test.
	* gcc.dg/graphite/pr68809.c: New test.

---
 gcc/graphite-scop-detection.c             |  6 ++++--
 gcc/testsuite/gcc.dg/graphite/pr68809-2.c | 27 +++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/graphite/pr68809.c   | 28 ++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index 03b1c49..9161cb7 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -273,8 +273,10 @@  trivially_empty_bb_p (basic_block bb)
 static inline bool
 same_close_phi_node (gphi *p1, gphi *p2)
 {
-  return operand_equal_p (gimple_phi_arg_def (p1, 0),
-			  gimple_phi_arg_def (p2, 0), 0);
+  return ((TREE_TYPE (gimple_phi_result (p1))
+	   == TREE_TYPE (gimple_phi_result (p2)))
+	  && operand_equal_p (gimple_phi_arg_def (p1, 0),
+			      gimple_phi_arg_def (p2, 0), 0));
 }
 
 static void make_close_phi_nodes_unique (basic_block bb);
diff --git a/gcc/testsuite/gcc.dg/graphite/pr68809-2.c b/gcc/testsuite/gcc.dg/graphite/pr68809-2.c
new file mode 100644
index 0000000..e6639b8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr68809-2.c
@@ -0,0 +1,27 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -floop-nest-optimize" } */
+
+int ae, vs, gf;
+char ue;
+
+void
+kc (char);
+
+void
+pm (void)
+{
+  unsigned int v9;
+  int td = (gf != 0);
+  while (vs)
+    {
+      kc (ue);
+      for (ae = 0; ae < 70; ++ae)
+	{
+	}
+      ae &= 4;
+      ae ^ td && ((ue = 0) != 0);
+      ++vs;
+    }
+  v9 = ue + 1;
+  ue - v9 && ((ue = 0) != 0);
+}
diff --git a/gcc/testsuite/gcc.dg/graphite/pr68809.c b/gcc/testsuite/gcc.dg/graphite/pr68809.c
new file mode 100644
index 0000000..1d75841
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr68809.c
@@ -0,0 +1,28 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -floop-nest-optimize" } */
+
+int ae, vs;
+char ue;
+
+void
+kc (char);
+
+void
+pm (void)
+{
+  unsigned int v9;
+  int gf = 0;
+  vs = 1;
+  while (vs)
+    {
+      gf -= ue;
+      kc (ue);
+      for (ae = 0; ae < 70; ++ae)
+	{
+	}
+      ae &= 4;
+      ae ^ (gf != 0) && ((ue = 0) != 0);
+    }
+  v9 = ue + 1;
+  ue - v9 && ((ue = 0) != 0);
+}