From patchwork Mon Nov 23 15:35:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 57165 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1506116lbb; Mon, 23 Nov 2015 07:35:49 -0800 (PST) X-Received: by 10.98.15.67 with SMTP id x64mr16740704pfi.67.1448292949027; Mon, 23 Nov 2015 07:35:49 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 74si20205486pfm.47.2015.11.23.07.35.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Nov 2015 07:35:49 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-415031-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-415031-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-415031-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=C3UEQcjO2HwElwUpF/3R60IW7MsLcz7ylypyFhi0YqX/Nf 23cxvKItOnf8QYJhuudZwj7Te6wTVg7+tBPZsrsYoM5jp2Nir6s0ob24CkFp5ZRr 9V3R0x1oyWMNsVvG3WyN39X+8FO+rd7mbTv+2f6Y9XGjkjsMZiPLhi9ZLY5g0= 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=F154LF3juP808kRwDXfWjgqWI8s=; b=O7nX70QR6xofY5TrxKSK Ss6jXF24UkJnDw0wh+Bf0m8JDudOXZ/7HW3jajddOYYibbR0+4wCHOF90313rDea 48ID6SprVSVmVpqOca44NNLhximVVg6vEtwVdh3M7zK1uwDfe0j9rm1JONL9eTKB lMgcjBNxW1Bw0XohUK4dfkk= Received: (qmail 27256 invoked by alias); 23 Nov 2015 15:35:35 -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 27245 invoked by uid 89); 23 Nov 2015 15:35:35 -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; Mon, 23 Nov 2015 15:35:33 +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-30-Ubkapp5mRI2DHXIIA588oQ-1; Mon, 23 Nov 2015 15:35:27 +0000 Received: from [10.2.206.200] ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 23 Nov 2015 15:35:27 +0000 Message-ID: <5653323E.4080708@arm.com> Date: Mon, 23 Nov 2015 15:35:26 +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/68435 Allow (c ? x++ : x--) form X-MC-Unique: Ubkapp5mRI2DHXIIA588oQ-1 X-IsSubscribed: yes Hi all, In this PR we fail to if-convert a case where in the expression x = c ? a : b; 'a' and 'b' are something like x + 1 and x - 1. So x appears in a and b. The code that checks that nothing from the else block modifies the registers used in a rejects this case. It should accept when the modification is in the last insn of the block i.e. insn_a or insn_b in the language of noce_try_cmove_arith because we will not be emitting insn_a and insn_b verbatim, but rather their modified versions emit_a and emit_b that have had their destinations modified to fresh pseudos, so no conflicts will arise. Bootstrapped and tested on arm, aarch64, x86_64. This improved if-conversion opportunities a bit across SPEC2006, not so much as to make a difference, but definitely a small improvement. Ok for trunk? Thanks, Kyrill 2015-11-23 Kyrylo Tkachov PR rtl-optimization/68435 * ifcvt.c (noce_try_cmove_arith): Skip final insn when checking for clonflicts between a, b and the set destinations. 2015-11-23 Kyrylo Tkachov PR rtl-optimization/68435 * gcc.dg/pr68435.c: New test. commit c890c68e2862980731e95cb4b7982f10b29109b7 Author: Kyrylo Tkachov Date: Fri Nov 20 09:13:04 2015 +0000 [ifcvt] PR rtl-optimization/68435 Allow (c ? x++ : x--) form diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index d721ec7..af7a3b9 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -2210,7 +2210,10 @@ noce_try_cmove_arith (struct noce_if_info *if_info) if (tmp_b && then_bb) { FOR_BB_INSNS (then_bb, tmp_insn) - if (modified_in_p (orig_b, tmp_insn)) + /* Don't check inside insn_a. We will have changed it to emit_a + with a destination that doesn't conflict. */ + if (!(insn_a && tmp_insn == insn_a) + && modified_in_p (orig_b, tmp_insn)) { modified_in_a = true; break; @@ -2223,7 +2226,10 @@ noce_try_cmove_arith (struct noce_if_info *if_info) if (tmp_b && else_bb) { FOR_BB_INSNS (else_bb, tmp_insn) - if (modified_in_p (orig_a, tmp_insn)) + /* Don't check inside insn_b. We will have changed it to emit_b + with a destination that doesn't conflict. */ + if (!(insn_b && tmp_insn == insn_b) + && modified_in_p (orig_a, tmp_insn)) { modified_in_b = true; break; diff --git a/gcc/testsuite/gcc.dg/pr68435.c b/gcc/testsuite/gcc.dg/pr68435.c new file mode 100644 index 0000000..765699a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr68435.c @@ -0,0 +1,52 @@ +/* { dg-do compile { target aarch64*-*-* x86_64-*-* } } */ +/* { dg-options "-fdump-rtl-ce1 -O2 -w" } */ + +typedef struct cpp_reader cpp_reader; +enum cpp_ttype +{ + CPP_EQ = + 0, CPP_NOT, CPP_GREATER, CPP_LESS, CPP_PLUS, CPP_MINUS, CPP_MULT, CPP_DIV, + CPP_MOD, CPP_AND, CPP_OR, CPP_XOR, CPP_RSHIFT, CPP_LSHIFT, CPP_MIN, + CPP_MAX, CPP_COMPL, CPP_AND_AND, CPP_OR_OR, CPP_QUERY, CPP_COLON, + CPP_COMMA, CPP_OPEN_PAREN, CPP_CLOSE_PAREN, CPP_EQ_EQ, CPP_NOT_EQ, + CPP_GREATER_EQ, CPP_LESS_EQ, CPP_PLUS_EQ, CPP_MINUS_EQ, CPP_MULT_EQ, + CPP_DIV_EQ, CPP_MOD_EQ, CPP_AND_EQ, CPP_OR_EQ, CPP_XOR_EQ, CPP_RSHIFT_EQ, + CPP_LSHIFT_EQ, CPP_MIN_EQ, CPP_MAX_EQ, CPP_HASH, CPP_PASTE, + CPP_OPEN_SQUARE, CPP_CLOSE_SQUARE, CPP_OPEN_BRACE, CPP_CLOSE_BRACE, + CPP_SEMICOLON, CPP_ELLIPSIS, CPP_PLUS_PLUS, CPP_MINUS_MINUS, CPP_DEREF, + CPP_DOT, CPP_SCOPE, CPP_DEREF_STAR, CPP_DOT_STAR, CPP_ATSIGN, CPP_NAME, + CPP_NUMBER, CPP_CHAR, CPP_WCHAR, CPP_OTHER, CPP_STRING, CPP_WSTRING, + CPP_HEADER_NAME, CPP_COMMENT, CPP_MACRO_ARG, CPP_PADDING, CPP_EOF, +}; + +static struct op lex (cpp_reader *, int); + +struct op +{ + enum cpp_ttype op; + long value; +}; + +int +_cpp_parse_expr (pfile) +{ + struct op init_stack[20]; + struct op *stack = init_stack; + struct op *top = stack + 1; + int skip_evaluation = 0; + for (;;) + { + struct op op; + op = lex (pfile, skip_evaluation); + switch (op.op) + { + case CPP_OR_OR: + if (top->value) + skip_evaluation++; + else + skip_evaluation--; + } + } +} + +/* { dg-final { scan-rtl-dump "2 true changes made" "ce1" } } */