From patchwork Thu Sep 10 14:47:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 53383 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id A893422B26 for ; Thu, 10 Sep 2015 14:47:36 +0000 (UTC) Received: by lbcjc2 with SMTP id jc2sf14754251lbc.0 for ; Thu, 10 Sep 2015 07:47:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type:x-original-sender :x-original-authentication-results; bh=G7lova4VkqTAdzwQwwADWdqmJbARXF6w8fuP+NtUtAY=; b=kj31C3rCTMjSNyFB64/US76E+tY/MmxDGiXmB8iMDDF9LVpFfEi80GC4EPkchDsOn1 azFm7UvWCKUIjlMVNrm40aHbnanfXtbHURYm49PYu7nWHhzBpjh+lvJJrRqkaokkAxwG OdbMhzK50fTeapF2MHWf99WK00A1jR/CCWH+NoAAylkQrg1IxTvy7PIAHyRvNbK7fnMW LbD6PbaeGVxkxd7JjKUMmh3S2n9O0OQhzYkSNclA7K2AKHuIcU7ArTzms4+J+jkGHaI3 yKNfgTJ+cbU0yGmblYtAqLpQdrKB6o8rIqM1ZpJQjen+d9LN4c+R5fNlTOew2zIJSyUb FCGA== X-Gm-Message-State: ALoCoQli0v7Vy+8FJuGHqLrQUGbkZGB3UuNp/cWxWDsWJFQ0Q9B5kWFl8bmGc4vYhxioXuJAmlkN X-Received: by 10.112.199.5 with SMTP id jg5mr9733882lbc.14.1441896455644; Thu, 10 Sep 2015 07:47:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.100 with SMTP id s4ls208263lag.83.gmail; Thu, 10 Sep 2015 07:47:35 -0700 (PDT) X-Received: by 10.112.125.134 with SMTP id mq6mr25306331lbb.19.1441896455490; Thu, 10 Sep 2015 07:47:35 -0700 (PDT) Received: from mail-la0-x22e.google.com (mail-la0-x22e.google.com. [2a00:1450:4010:c03::22e]) by mx.google.com with ESMTPS id de10si10637877lac.117.2015.09.10.07.47.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2015 07:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) client-ip=2a00:1450:4010:c03::22e; Received: by lagj9 with SMTP id j9so29955958lag.2 for ; Thu, 10 Sep 2015 07:47:35 -0700 (PDT) X-Received: by 10.152.43.137 with SMTP id w9mr11970440lal.56.1441896455349; Thu, 10 Sep 2015 07:47:35 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1022524lbq; Thu, 10 Sep 2015 07:47:33 -0700 (PDT) X-Received: by 10.68.200.40 with SMTP id jp8mr85686522pbc.16.1441896450258; Thu, 10 Sep 2015 07:47:30 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id vz4si19874028pbc.51.2015.09.10.07.47.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2015 07:47:30 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-407065-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 70600 invoked by alias); 10 Sep 2015 14:47:16 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 70588 invoked by uid 89); 10 Sep 2015 14:47:15 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Sep 2015 14:47:13 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-37-_ZPYmYBpRBmAivlkTRsVdA-1; Thu, 10 Sep 2015 15:47:08 +0100 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 10 Sep 2015 15:47:08 +0100 Message-ID: <55F197EB.3010404@arm.com> Date: Thu, 10 Sep 2015 15:47:07 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Rainer Orth CC: GCC Patches , Jeff Law Subject: Re: [PATCH][RTL-ifcvt] PR rtl-optimization/67465: Handle pairs of complex+simple blocks and empty blocks more gracefully References: <55F13D66.9010207@arm.com> In-Reply-To: X-MC-Unique: _ZPYmYBpRBmAivlkTRsVdA-1 X-IsSubscribed: yes X-Original-Sender: kyrylo.tkachov@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 On 10/09/15 12:43, Rainer Orth wrote: > Hi Kyrill, > >> Rainer, could you please check that this patch still fixes the SPARC >> regressions? > unfortunately, it breaks sparc-sun-solaris2.10 bootstrap: compiling > stage2 libiberty/regex.c FAILs: > > Thanks for providing the preprocessed file. I've reproduced and fixed the ICE in this version of the patch. The problem was that I was taking the mode of x before the check of whether a and b are MEMs, after which we would change x to an address_mode reg, thus confusing emit_move_insn. The fix is to take the mode of x and perform the can_conditionally_move_p check after that transformation. Bootstrapped and tested on aarch64 and x86_64. The preprocessed regex.i that Rainer provided now compiles successfully for me on a sparc-sun-solaris2.10 stage-1 cross-compiler. Rainer, thanks for your help so far, could you please try out this patch? Thanks, Kyrill 2015-09-10 Kyrylo Tkachov PR rtl-optimization/67456 PR rtl-optimization/67464 PR rtl-optimization/67465 PR rtl-optimization/67481 * ifcvt.c (noce_try_cmove_arith): Bail out if cannot conditionally move in the mode of x. Handle combination of complex and simple block pairs as well as the case when one is empty. 2015-09-10 Kyrylo Tkachov * gcc.dg/pr67465.c: New test. commit 90c12de20cdc8a8a5e81c25accc640ab517a3f7c Author: Kyrylo Tkachov Date: Mon Sep 7 14:58:01 2015 +0100 [RTL-ifcvt] PR rtl-optimization/67465: Do not ifcvt complex blocks if the else block is empty diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index d2f5b66..e708ac4 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -2043,6 +2043,11 @@ noce_try_cmove_arith (struct noce_if_info *if_info) insn_a = if_info->insn_a; insn_b = if_info->insn_b; + machine_mode x_mode = GET_MODE (x); + + if (!can_conditionally_move_p (x_mode)) + return FALSE; + unsigned int then_cost; unsigned int else_cost; if (insn_a) @@ -2079,13 +2084,32 @@ noce_try_cmove_arith (struct noce_if_info *if_info) } } - if (!a_simple && then_bb && !b_simple && else_bb + if (then_bb && else_bb && !a_simple && !b_simple && (!bbs_ok_for_cmove_arith (then_bb, else_bb) || !bbs_ok_for_cmove_arith (else_bb, then_bb))) return FALSE; start_sequence (); + /* If one of the blocks is empty then the corresponding B or A value + came from the test block. The non-empty complex block that we will + emit might clobber the register used by B or A, so move it to a pseudo + first. */ + + if (b_simple || !else_bb) + { + rtx tmp_b = gen_reg_rtx (x_mode); + noce_emit_move_insn (tmp_b, b); + b = tmp_b; + } + + if (a_simple || !then_bb) + { + rtx tmp_a = gen_reg_rtx (x_mode); + noce_emit_move_insn (tmp_a, a); + a = tmp_a; + } + orig_a = a; orig_b = b; diff --git a/gcc/testsuite/gcc.dg/pr67465.c b/gcc/testsuite/gcc.dg/pr67465.c new file mode 100644 index 0000000..321fd38 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr67465.c @@ -0,0 +1,53 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -std=gnu99" } */ + +int a, b, c, d, e, h; + +int +fn1 (int p1) +{ + { + int g[2]; + for (int i = 0; i < 1; i++) + g[i] = 0; + if (g[0] < c) + { + a = (unsigned) (1 ^ p1) % 2; + return 0; + } + } + return 0; +} + +void +fn2 () +{ + for (h = 0; h < 1; h++) + { + for (int j = 0; j < 2; j++) + { + for (b = 1; b; b = 0) + a = 1; + for (; b < 1; b++) + ; + if (e) + continue; + a = 2; + } + fn1 (h); + short k = -16; + d = k > a; + } +} + +int +main () +{ + fn2 (); + + if (a != 2) + __builtin_abort (); + + return 0; +} +