From: Jakub Jelinek <jakub@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Subject: [committed] Fix infinite recursion in combine_simplify_rtx (PR target/84700)
Date: Tue, 06 Mar 2018 01:13:00 -0000 [thread overview]
Message-ID: <20180305221848.GT5867@tucnak> (raw)
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.
--- 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);
+}
Jakub
reply other threads:[~2018-03-06 1:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180305221848.GT5867@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=segher@kernel.crashing.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).