From patchwork Thu Nov 26 11:12:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 57325 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp446737lbb; Thu, 26 Nov 2015 03:13:00 -0800 (PST) X-Received: by 10.67.7.101 with SMTP id db5mr14631993pad.53.1448536380370; Thu, 26 Nov 2015 03:13:00 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id xy7si8143786pab.6.2015.11.26.03.12.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2015 03:13:00 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-415490-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-415490-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-415490-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=SDyyBKm/HEaOI9X8fB2C0UJGliHJh5pRHG6i8Ud+EMJODr j8wMtIgEcU9nz2A2Il0+XfxbLQR9SpZJWuSoVzoWomfqmz9T4b1wTJuNeaHTpsTm Zfem36k1Qgcq8cRO8qDorbDAajKMSejbHcApn6Czut/dKxENtYIVVwfas7gr8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=DFUCA19r4d3xer+phpGaG2FM268=; b=Dnws3EKADmRF69oZ7eAJ Mbu9U93PuFwAqmzn4QcfRrL4Y6DWyGUIUnjvte0MsK52645pbbjvmCFUwy/t652B r1k3F8/vC2JoCR6F5fPVe4U/6f5Pp3RZpFA2lbTyf54J5sdf1ZwFueu4HfDYbjla PrKdP9Hf9snNGUlCXuptdOc= Received: (qmail 108099 invoked by alias); 26 Nov 2015 11:12:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk 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 108087 invoked by uid 89); 26 Nov 2015 11:12:45 -0000 Authentication-Results: sourceware.org; auth=none 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, 26 Nov 2015 11:12:44 +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-6-BiutOMyJRseaJNlm0k2CJA-1; Thu, 26 Nov 2015 11:12:37 +0000 Received: from [10.2.206.200] ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 26 Nov 2015 11:12:36 +0000 Message-ID: <5656E924.4030603@arm.com> Date: Thu, 26 Nov 2015 11:12:36 +0000 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 Subject: [PATCH][RTL-ifcvt] PR rtl-optimization/68506: Fix emitting order of insns in IF-THEN-JOIN case X-MC-Unique: BiutOMyJRseaJNlm0k2CJA-1 X-IsSubscribed: yes Hi all, In this PR we have an IF-THEN-JOIN formation i.e. no ELSE block and we have a situation where the THEN block modifies a register used in emit_b, so emit_b must be emitted before the THEN block. However the bug in the logic that performs these checks ends up to us emitting emit_a+then_bb followed by emit_b+else_bb. The fix is pretty simple and involves emitting emit_b (+ else_bb that is empty in this case) if modified_a is true, even if emit_a is NULL. If emit_a is NULL noce_emit_bb will handle it properly and not do anything bad, so we're safe. Bootstrapped and tested on arm, aarch64, x86_64. Ok for trunk? Thanks, Kyrill 2015-11-26 Kyrylo Tkachov PR rtl-optimization/68506 * ifcvt.c (noce_try_cmove_arith): Try emitting the else basic block first if emit_a exists or then_bb modifies 'b'. 2015-11-26 Kyrylo Tkachov PR rtl-optimization/68506 * gcc.c-torture/execute/pr68506.c: New test. commit 08a371d20793bd57e9a68b85beaf2cab0804ed48 Author: Kyrylo Tkachov Date: Tue Nov 24 11:49:30 2015 +0000 PR rtl-optimization/68506: Fix emitting order of insns in IF-THEN-JOIN case diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index af7a3b9..3e3dc8d 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -2220,7 +2220,7 @@ noce_try_cmove_arith (struct noce_if_info *if_info) } } - if (emit_a && modified_in_a) + if (emit_a || modified_in_a) { modified_in_b = emit_b != NULL_RTX && modified_in_p (orig_a, emit_b); if (tmp_b && else_bb) diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68506.c b/gcc/testsuite/gcc.c-torture/execute/pr68506.c new file mode 100644 index 0000000..15984ed --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr68506.c @@ -0,0 +1,63 @@ +/* { dg-options "-fno-builtin-abort" } */ + +int a, b, m, n, o, p, s, u, i; +char c, q, y; +short d; +unsigned char e; +static int f, h; +static short g, r, v; +unsigned t; + +extern void abort (); + +int +fn1 (int p1) +{ + return a ? p1 : p1 + a; +} + +unsigned char +fn2 (unsigned char p1, int p2) +{ + return p2 >= 2 ? p1 : p1 >> p2; +} + +static short +fn3 () +{ + int w, x = 0; + for (; p < 31; p++) + { + s = fn1 (c | ((1 && c) == c)); + t = fn2 (s, x); + c = (unsigned) c > -(unsigned) ((o = (m = d = t) == p) <= 4UL) && n; + v = -c; + y = 1; + for (; y; y++) + e = v == 1; + d = 0; + for (; h != 2;) + { + for (;;) + { + if (!m) + abort (); + r = 7 - f; + x = e = i | r; + q = u * g; + w = b == q; + if (w) + break; + } + break; + } + } + return x; +} + +int +main () +{ + fn3 (); + return 0; +}