From patchwork Thu Sep 10 08:20:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 53370 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id 24A8C22B19 for ; Thu, 10 Sep 2015 08:21:19 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf11174136lbc.1 for ; Thu, 10 Sep 2015 01:21:18 -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:content-type:x-original-sender :x-original-authentication-results; bh=UCn39TuaUydfVZzVUlCgYb4oXI0PZw8RPbQalFaHFXs=; b=mUs5m/80LamcXeTIOLA6E2479Z50OS5UOR70NR5Q6NclLT7UKURR/O8esQBtoftHYm 3qs5rIJrwndyRj/srjOVtBe1EAIdrWFqFCwLJzFfZXXgKcNyp4a61+F+20maiPpN81ai Wj0FgCKLrOMw2SNuP3gukS+EDOGMmu3aDlR8wLeXCe2g2MV153DuSVd1+q8RPkTOrGnV sHnDNiZaGySEY4HqNTWNjhp8f0DaWLeo/4foswvXuZwo631T51FPtQKKaQZX4Jt13TzP jMs1j8oXw1vZeqAY/78JI0cAvJvCBX3MAK0WF6FLRYDCZXtWKJVw+gRepYee21YdqJaZ b1vg== X-Gm-Message-State: ALoCoQk0BqO9zuMx9NJPSipqbAQlOWiaO9ybUKThKzr76YQeWjVFCwG8wlqtLM7wa+POjrEON/A0 X-Received: by 10.152.21.233 with SMTP id y9mr9363215lae.5.1441873278047; Thu, 10 Sep 2015 01:21:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.9 with SMTP id j9ls160932lae.39.gmail; Thu, 10 Sep 2015 01:21:17 -0700 (PDT) X-Received: by 10.112.87.69 with SMTP id v5mr15828627lbz.70.1441873277871; Thu, 10 Sep 2015 01:21:17 -0700 (PDT) Received: from mail-la0-x22f.google.com (mail-la0-x22f.google.com. [2a00:1450:4010:c03::22f]) by mx.google.com with ESMTPS id h10si1536748laa.147.2015.09.10.01.21.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2015 01:21:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22f as permitted sender) client-ip=2a00:1450:4010:c03::22f; Received: by lagj9 with SMTP id j9so23127953lag.2 for ; Thu, 10 Sep 2015 01:21:17 -0700 (PDT) X-Received: by 10.152.18.194 with SMTP id y2mr34685201lad.88.1441873277725; Thu, 10 Sep 2015 01:21:17 -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 w3csp804121lbq; Thu, 10 Sep 2015 01:21:16 -0700 (PDT) X-Received: by 10.50.98.39 with SMTP id ef7mr3928530igb.2.1441873276365; Thu, 10 Sep 2015 01:21:16 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p10si9604968ioi.209.2015.09.10.01.21.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2015 01:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-407022-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 14205 invoked by alias); 10 Sep 2015 08:21:04 -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 14183 invoked by uid 89); 10 Sep 2015 08:21:03 -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) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 Sep 2015 08:21:00 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-10-FUG9jnKbRMmoX6KLdUOjWw-1; Thu, 10 Sep 2015 09:20:55 +0100 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 10 Sep 2015 09:20:54 +0100 Message-ID: <55F13D66.9010207@arm.com> Date: Thu, 10 Sep 2015 09:20:54 +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: GCC Patches CC: Rainer Orth , Jeff Law Subject: [PATCH][RTL-ifcvt] PR rtl-optimization/67465: Handle pairs of complex+simple blocks and empty blocks more gracefully X-MC-Unique: FUG9jnKbRMmoX6KLdUOjWw-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::22f 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 Hi all, This is the second attempt to fix the PRs. The first one at https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00449.html does the trick, but is overly restrictive. This one allows for cases when one block is complex and the other one is simple or empty. Earlier, this case would bypass the bbs_ok_for_cmove_arith and we would end up if-converting cases where the 'else' part (x := b) was pulled from the test block earlier in the call chain. If the reg 'b' in this case was also written to by the 'then' block, then we would miscompile. With this patch we move the original 'b' value into a pseudo before potentially clobbering it, so all is wired up properly. With this patch the PRs work for me and the restriction on if-conversion is not overly aggressive. Rainer, could you please check that this patch still fixes the SPARC regressions? I've bootstrapped and tested this on x86_64 and aarch64. Ok for trunk if SPARC testing is fine? 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 ca25fa7000dd9d086b78bf9a02126f83fbab8073 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..9adce60 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -1997,6 +1997,7 @@ noce_try_cmove_arith (struct noce_if_info *if_info) rtx a = if_info->a; rtx b = if_info->b; rtx x = if_info->x; + machine_mode x_mode = GET_MODE (x); rtx orig_a, orig_b; rtx_insn *insn_a, *insn_b; bool a_simple = if_info->then_simple; @@ -2008,6 +2009,9 @@ noce_try_cmove_arith (struct noce_if_info *if_info) enum rtx_code code; rtx_insn *ifcvt_seq; + if (!can_conditionally_move_p (x_mode)) + return FALSE; + /* A conditional move from two memory sources is equivalent to a conditional on their addresses followed by a load. Don't do this early because it'll screw alias analysis. Note that we've @@ -2079,13 +2083,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; +} +