diff mbox

Fix recognize_single_bit_test (PR tree-optimization/61684)

Message ID 20140703184428.GL31640@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek July 3, 2014, 6:44 p.m. UTC
Hi!

The rhs1 of CONVERT_EXPR_CODE_P doesn't have to be a SSA_NAME, can be e.g.
invariant like ADDR_EXPR of a var, but ifcombine didn't think about that
possibility.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/4.9/4.8?

2014-07-03  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/61684
	* tree-ssa-ifcombine.c (recognize_single_bit_test): Make sure
	rhs1 of conversion is a SSA_NAME before using SSA_NAME_DEF_STMT on it.

	* gcc.c-torture/compile/pr61684.c: New test.


	Jakub

Comments

Richard Biener July 4, 2014, 8:17 a.m. UTC | #1
On July 3, 2014 8:44:28 PM CEST, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>The rhs1 of CONVERT_EXPR_CODE_P doesn't have to be a SSA_NAME, can be
>e.g.
>invariant like ADDR_EXPR of a var, but ifcombine didn't think about
>that
>possibility.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk/4.9/4.8?

Ok.

Thanks
Richard.

>2014-07-03  Jakub Jelinek  <jakub@redhat.com>
>
>	PR tree-optimization/61684
>	* tree-ssa-ifcombine.c (recognize_single_bit_test): Make sure
>	rhs1 of conversion is a SSA_NAME before using SSA_NAME_DEF_STMT on it.
>
>	* gcc.c-torture/compile/pr61684.c: New test.
>
>--- gcc/tree-ssa-ifcombine.c.jj	2014-06-06 09:19:22.000000000 +0200
>+++ gcc/tree-ssa-ifcombine.c	2014-07-03 11:46:25.868335148 +0200
>@@ -233,7 +233,8 @@ recognize_single_bit_test (gimple cond,
>       while (is_gimple_assign (stmt)
> 	     && ((CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
> 		  && (TYPE_PRECISION (TREE_TYPE (gimple_assign_lhs (stmt)))
>-		      <= TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt)))))
>+		      <= TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt))))
>+		  && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME)
> 		 || gimple_assign_ssa_name_copy_p (stmt)))
> 	stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
> 
>--- gcc/testsuite/gcc.c-torture/compile/pr61684.c.jj	2014-07-03
>12:06:46.654858358 +0200
>+++ gcc/testsuite/gcc.c-torture/compile/pr61684.c	2014-07-03
>12:09:05.016123771 +0200
>@@ -0,0 +1,15 @@
>+/* PR tree-optimization/61684 */
>+
>+int a, c;
>+static int *b = 0;
>+short d;
>+static short **e = 0;
>+
>+void
>+foo ()
>+{
>+  for (; c < 1; c++)
>+    ;
>+  *e = &d;
>+  a = d && (c && 1) & *b;
>+}
>
>	Jakub
diff mbox

Patch

--- gcc/tree-ssa-ifcombine.c.jj	2014-06-06 09:19:22.000000000 +0200
+++ gcc/tree-ssa-ifcombine.c	2014-07-03 11:46:25.868335148 +0200
@@ -233,7 +233,8 @@  recognize_single_bit_test (gimple cond,
       while (is_gimple_assign (stmt)
 	     && ((CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
 		  && (TYPE_PRECISION (TREE_TYPE (gimple_assign_lhs (stmt)))
-		      <= TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt)))))
+		      <= TYPE_PRECISION (TREE_TYPE (gimple_assign_rhs1 (stmt))))
+		  && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME)
 		 || gimple_assign_ssa_name_copy_p (stmt)))
 	stmt = SSA_NAME_DEF_STMT (gimple_assign_rhs1 (stmt));
 
--- gcc/testsuite/gcc.c-torture/compile/pr61684.c.jj	2014-07-03 12:06:46.654858358 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr61684.c	2014-07-03 12:09:05.016123771 +0200
@@ -0,0 +1,15 @@ 
+/* PR tree-optimization/61684 */
+
+int a, c;
+static int *b = 0;
+short d;
+static short **e = 0;
+
+void
+foo ()
+{
+  for (; c < 1; c++)
+    ;
+  *e = &d;
+  a = d && (c && 1) & *b;
+}