From patchwork Mon Sep 7 16:29:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 53247 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id BC9E422B05 for ; Mon, 7 Sep 2015 16:30:01 +0000 (UTC) Received: by wicmn1 with SMTP id mn1sf27852036wic.1 for ; Mon, 07 Sep 2015 09:30:01 -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=TwLzg3Zy92BZHz8tI0Y1dO903GSy2r3BQuQP5OMkFbA=; b=RWrCCpDAQ1JAU/G9DVByUcqDSQPfgYZMqA3+fMF0hcNe9LBmkOJlvgAAYCCTYYbxvO qrqdscArjBjtOd5EaEhif3pgoWsrESIb3cHeLXGdR0pwLCjDafPg6OOQR8iMlfldKoEQ rL7eWSwJVCQ2RG5b+06d4ncsc662fdghzGgo/MgzOt/+YboW5SDlRfKNJvFFeoeBti9/ VJAFZYDjsRQPy5JFVSZn+EfIQYzle9qQaOy3kTbUwt4nSDFuOLoZnuGJJkvwjxL4TmUD fCL6/RyljUk08bEvaNwWmJOnYzxoygUUN9LX+KVL7LT+er7JaUbKyXVCtzYq68Ss6aRA Eixg== X-Gm-Message-State: ALoCoQnHQ+XhDtjdkrQ/XIlOcW6ZSrpE8MfuQ72JXmcoYifD3tJ30sUcz24iTOx8E+66iqaceL8E X-Received: by 10.112.198.33 with SMTP id iz1mr4969437lbc.8.1441643401051; Mon, 07 Sep 2015 09:30:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.39 with SMTP id p7ls582416lap.104.gmail; Mon, 07 Sep 2015 09:30:00 -0700 (PDT) X-Received: by 10.112.13.136 with SMTP id h8mr5839848lbc.23.1441643400894; Mon, 07 Sep 2015 09:30:00 -0700 (PDT) Received: from mail-lb0-x236.google.com (mail-lb0-x236.google.com. [2a00:1450:4010:c04::236]) by mx.google.com with ESMTPS id dk7si423157lad.58.2015.09.07.09.30.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2015 09:30:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::236 as permitted sender) client-ip=2a00:1450:4010:c04::236; Received: by lbbmp1 with SMTP id mp1so41564652lbb.1 for ; Mon, 07 Sep 2015 09:30:00 -0700 (PDT) X-Received: by 10.112.77.10 with SMTP id o10mr17747734lbw.73.1441643400789; Mon, 07 Sep 2015 09:30:00 -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 w3csp468632lbq; Mon, 7 Sep 2015 09:29:59 -0700 (PDT) X-Received: by 10.66.147.68 with SMTP id ti4mr47579988pab.90.1441643399216; Mon, 07 Sep 2015 09:29:59 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id pm1si523584pbb.183.2015.09.07.09.29.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2015 09:29:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-406825-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 130596 invoked by alias); 7 Sep 2015 16:29:47 -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 130581 invoked by uid 89); 7 Sep 2015 16:29:46 -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; Mon, 07 Sep 2015 16:29:44 +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-25-Sum0FIq8QDCbJ7TqrXC11A-1; Mon, 07 Sep 2015 17:29:40 +0100 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 7 Sep 2015 17:29:39 +0100 Message-ID: <55EDBB73.5080900@arm.com> Date: Mon, 07 Sep 2015 17:29:39 +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: Jeff Law , Rainer Orth Subject: [PATCH][RTL-ifcvt] PR rtl-optimization/67465: Do not ifcvt complex blocks if the else block is empty X-MC-Unique: Sum0FIq8QDCbJ7TqrXC11A-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:c04::236 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 patch fixes the PRs in the ChangeLog that have been reported against my if-conversion patch. The problem occurs when the 'then' block is complex but the else block is empty. In this case the calling code in noce_process_if_block takes the 'else' move (x := b) from the test block. However, we have not checked whether the test block is valid for complex-block if-conversion with bb_valid_for_noce_process_p. Also, that's a case I wasn't particularly targeting when writing the initial patch. This patch bails out of noce_try_cmove_arith when one of the blocks is complex and the other is empty. I've checked that if-conversion still happens in the cases of interest from the original patch. I've added the testcase from PR 67465 since that one uses __builtin_abort and triggers the problem nicely. The others show the miscompilation using printf seems to go away if I replace it with an abort. I have confirmed manually that the miscompilation goes away on those testcases. PR rtl-optimization/67481 is a testsuite regression on sparc-solaris that Rainer reported. I haven't tested that this patch fixes that, but I suspect that the root cause is the same. Rainer, could you please check that this fixes the regression for you? Bootstrapped and tested on aarch64 and x86_64. Ok for trunk if sparc testing comes ok? Thanks, Kyrill 2015-09-07 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 one of the blocks is complex and the other is empty. 2015-09-07 Kyrylo Tkachov * gcc.dg/pr67465.c: New test. commit 2305f7deed793315f04221f718880676cd62474d 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..5716dcc 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -2079,7 +2079,14 @@ noce_try_cmove_arith (struct noce_if_info *if_info) } } - if (!a_simple && then_bb && !b_simple && else_bb + /* When one of the blocks is really empty and the other is a complex block + don't do anything. The value 'b' may have come from the test block that + we did not check for if-conversion validity in noce_process_if_block. */ + if ((!a_simple && !else_bb) + || (!b_simple && !then_bb)) + return FALSE; + + if (then_bb && else_bb && (!bbs_ok_for_cmove_arith (then_bb, else_bb) || !bbs_ok_for_cmove_arith (else_bb, then_bb))) return FALSE; 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; +} +