diff mbox series

[committed] Fix infinite recursion in combine_simplify_rtx (PR target/84700)

Message ID 20180305221848.GT5867@tucnak
State New
Headers show
Series [committed] Fix infinite recursion in combine_simplify_rtx (PR target/84700) | expand

Commit Message

Jakub Jelinek March 5, 2018, 10:18 p.m. UTC
Hi!

On the following testcase on powerpc64-linux -m32 we end up calling
combine_simplify_rtx on
(plus:SI (ltu:SI (plus:SI (if_then_else:SI (eq (reg:CC 147)
                    (const_int 0 [0]))
                (subreg:SI (reg:DI 126) 4)
                (reg:SI 146))
            (subreg:SI (reg:DI 126) 4))
        (if_then_else:SI (eq (reg:CC 147)
                (const_int 0 [0]))
            (subreg:SI (reg:DI 126) 4)
            (reg:SI 146)))
    (reg:SI 133 [ iftmp.0_2 ]))
and if_then_else_cond returns non-NULL on it, but neither false_rtx nor
true_rtx are comparisons and false_rtx is identical to x, so we subst
the false_rtx again with pc_rtx, pc_rtx and call combine_simplify_rtx with
different copy of the same expression and recurse that way forever.

Fixed thusly, bootstrapped/regtested on {x86_64,i686,powerpc64{,le}}-linux,
on powerpc64-linux including -m32, preapproved by Segher in the PR,
committed to trunk.

2018-03-05  Jakub Jelinek  <jakub@redhat.com>

	PR target/84700
	* combine.c (combine_simplify_rtx): Don't try to simplify if
	if_then_else_cond returned non-NULL, but either true_rtx or false_rtx
	are equal to x.

	* gcc.target/powerpc/pr84700.c: New test.


	Jakub
diff mbox series

Patch

--- gcc/combine.c.jj	2018-03-02 10:15:05.000000000 +0100
+++ gcc/combine.c	2018-03-05 18:34:31.135061249 +0100
@@ -5734,7 +5734,11 @@  combine_simplify_rtx (rtx x, machine_mod
 	  /* If everything is a comparison, what we have is highly unlikely
 	     to be simpler, so don't use it.  */
 	  && ! (COMPARISON_P (x)
-		&& (COMPARISON_P (true_rtx) || COMPARISON_P (false_rtx))))
+		&& (COMPARISON_P (true_rtx) || COMPARISON_P (false_rtx)))
+	  /* Similarly, if we end up with one of the expressions the same
+	     as the original, it is certainly not simpler.  */
+	  && ! rtx_equal_p (x, true_rtx)
+	  && ! rtx_equal_p (x, false_rtx))
 	{
 	  rtx cop1 = const0_rtx;
 	  enum rtx_code cond_code = simplify_comparison (NE, &cond, &cop1);
--- gcc/testsuite/gcc.target/powerpc/pr84700.c.jj	2018-03-05 18:39:48.075184332 +0100
+++ gcc/testsuite/gcc.target/powerpc/pr84700.c	2018-03-05 18:40:37.065205545 +0100
@@ -0,0 +1,12 @@ 
+/* PR target/84700 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -misel" } */
+
+long long int
+foo (long long int x)
+{
+  long long int a = x < 2;
+  int b = a >= 0;
+
+  return a + ((x == 0) ? a : b);
+}