From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28584 invoked by alias); 14 Jan 2017 13:36:46 -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 28568 invoked by uid 89); 14 Jan 2017 13:36:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=powerpc***, sk:host_wi, sk:HOST_WI, powerpc*-*-* X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 14 Jan 2017 13:36:43 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4207D61B95; Sat, 14 Jan 2017 13:36:43 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-250.ams2.redhat.com [10.36.116.250]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0EDafxP015618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 14 Jan 2017 08:36:42 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v0EDabfv001242; Sat, 14 Jan 2017 14:36:38 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v0EDaYuI001241; Sat, 14 Jan 2017 14:36:34 +0100 Date: Sat, 14 Jan 2017 13:36:00 -0000 From: Jakub Jelinek To: Richard Biener , Jeff Law , Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix RTL sharing bug in loop-doloop.c (PR target/79080) Message-ID: <20170114133634.GE1867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg01024.txt.bz2 Hi! The force_operand on complex count expression in doloop_modify can invoke various expander routines that are assuming there is rtl unsharing after them (which is the case for expansion). When later optimizations invoke the expander (e.g. expand_mult in this case), they use unshare_all_rtl_in_chain on the sequence. The following patch does that for doloop. The count expression is already known not to be shared with anything else (we do copy_rtx on it first and then create new rtls around it if needed), so for that if it occurs just once in the sequence, we don't need to unshare it. For subexpression of condition I'm not sure, which is why I've forced unsharing even if it occurs just once and is not shareable part of the condition like REG. Bootstrapped/regtested on powerpc64-linux, ok for trunk? 2017-01-14 Jakub Jelinek PR target/79080 * loop-doloop.c (doloop_modify): Call unshare_all_rtl_in_chain on sequence. Formatting fixes. (doloop_optimize): Formatting fixes. * gcc.dg/pr79080.c: New test. --- gcc/loop-doloop.c.jj 2017-01-01 12:45:37.000000000 +0100 +++ gcc/loop-doloop.c 2017-01-13 09:55:36.918702356 +0100 @@ -479,9 +479,13 @@ doloop_modify (struct loop *loop, struct /* Insert initialization of the count register into the loop header. */ start_sequence (); + /* count has been already copied through copy_rtx. */ + reset_used_flags (count); + set_used_flags (condition); tmp = force_operand (count, counter_reg); convert_move (counter_reg, tmp, 1); sequence = get_insns (); + unshare_all_rtl_in_chain (sequence); end_sequence (); emit_insn_after (sequence, BB_END (loop_preheader_edge (loop)->src)); @@ -489,10 +493,8 @@ doloop_modify (struct loop *loop, struct { rtx ass = copy_rtx (desc->noloop_assumptions); basic_block preheader = loop_preheader_edge (loop)->src; - basic_block set_zero - = split_edge (loop_preheader_edge (loop)); - basic_block new_preheader - = split_edge (loop_preheader_edge (loop)); + basic_block set_zero = split_edge (loop_preheader_edge (loop)); + basic_block new_preheader = split_edge (loop_preheader_edge (loop)); edge te; /* Expand the condition testing the assumptions and if it does not pass, @@ -688,8 +690,7 @@ doloop_optimize (struct loop *loop) rtx_insn *doloop_seq = targetm.gen_doloop_end (doloop_reg, start_label); word_mode_size = GET_MODE_PRECISION (word_mode); - word_mode_max - = (HOST_WIDE_INT_1U << (word_mode_size - 1) << 1) - 1; + word_mode_max = (HOST_WIDE_INT_1U << (word_mode_size - 1) << 1) - 1; if (! doloop_seq && mode != word_mode /* Before trying mode different from the one in that # of iterations is --- gcc/testsuite/gcc.dg/pr79080.c.jj 2017-01-13 10:03:54.518423577 +0100 +++ gcc/testsuite/gcc.dg/pr79080.c 2017-01-13 10:07:37.610608570 +0100 @@ -0,0 +1,19 @@ +/* PR target/79080 */ +/* { dg-do compile } */ +/* { dg-options "-O1" } */ +/* { dg-additional-options "-mcpu=8548" { target { powerpc*-*-* && ilp32 } } } */ + +int +foo (char x) +{ + int a; + + for (;;) + { + x += 59; + if (x != 0) + a = 0; + else + return 0; + } +} Jakub