From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47060 invoked by alias); 6 Mar 2018 01:13:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 47046 invoked by uid 89); 6 Mar 2018 01:13:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Mar 2018 01:13:49 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32955402314E for ; Tue, 6 Mar 2018 01:13:44 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-35.brq.redhat.com [10.40.204.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91C0E202660C for ; Tue, 6 Mar 2018 01:13:34 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w25MIngN018264; Mon, 5 Mar 2018 23:18:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w25MImw5018263; Mon, 5 Mar 2018 23:18:48 +0100 Date: Tue, 06 Mar 2018 01:13:00 -0000 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [committed] Fix infinite recursion in combine_simplify_rtx (PR target/84700) Message-ID: <20180305221848.GT5867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00244.txt.bz2 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 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