From patchwork Mon Sep 19 14:43:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 671769 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sd7tW4fH0z9sC4 for ; Tue, 20 Sep 2016 00:43:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=m1P7OLdx; dkim-atps=neutral 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:references :in-reply-to:content-type; q=dns; s=default; b=uoSNAf6i9HaxzX5HW b0xoWyysWFH5woeaXxwp0fmowaa4Jzl5LjszBwQc51EzYN6ECcF2MENYah+6Gi6s T5pAuLzx/+S6ylE7/RqRW/DuNTUML72zyDE9dJyOBHlb7eW38EgxGEBeB6FAEO72 dkfkD4XsZ1Vgibvhx9pqZTPGas= 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:references :in-reply-to:content-type; s=default; bh=gWbHdS2QIHigtN3hp5dPbFW L1VE=; b=m1P7OLdxJ0S/VrQIJ8pzM0D7yXKNSbsVODAZMUioZwKYBsdb6fAVMQS P4RZb+lOiNdiJ6LimTnEJGDWtaUHGZQB1h+5ZV0B704MgZVQeYvBWkssFC5rEZ4+ QdZDMvAq9qyjh4EwY4R35UdEX3WEC6go06sGyeMBY2meiJ0XGK9U= Received: (qmail 34374 invoked by alias); 19 Sep 2016 14:43:37 -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 34360 invoked by uid 89); 19 Sep 2016 14:43:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=PLUS X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Sep 2016 14:43:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BFF0380D; Mon, 19 Sep 2016 07:43:24 -0700 (PDT) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4CF623F251; Mon, 19 Sep 2016 07:43:24 -0700 (PDT) Message-ID: <57DFF98A.4030602@foss.arm.com> Date: Mon, 19 Sep 2016 15:43:22 +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: Bernd Schmidt , GCC Patches Subject: Re: [PATCH][simplify-rtx] (GTU (PLUS a C) (C - 1)) --> (LTU a -C) References: <57DBB001.9070803@foss.arm.com> <2253d596-ba6f-7d80-b322-b3a03359ff7c@redhat.com> <57DBD39B.7030505@foss.arm.com> In-Reply-To: <57DBD39B.7030505@foss.arm.com> On 16/09/16 12:12, Kyrill Tkachov wrote: > > On 16/09/16 11:45, Bernd Schmidt wrote: >> On 09/16/2016 10:40 AM, Kyrill Tkachov wrote: >>> >>> 2016-09-16 Kyrylo Tkachov >>> >>> * simplify-rtx.c (simplify_relational_operation_1): Add transformation >>> (GTU (PLUS a C) (C - 1)) --> (LTU a -C). >>> >>> 2016-09-16 Kyrylo Tkachov >>> >>> * gcc.target/aarch64/gtu_to_ltu_cmp_1.c: New test. >> >> Ok. Don't know if you want to add more variants of the input code to the testcase to make sure they're all covered. >> > > Thanks. > I'm having trouble writing testcases for variations of the original testcase as GCC really really wants to convert > everything to a comparison against 1 at RTL level, so only the x == -2 || x == -1 condition seems to trigger this. > However, testcases of the form: > unsigned int > foo (unsigned int a, unsigned int b) > { > return (a + 10) > 9; > } > > seem to trigger it, so I can add some of this form. However, these will be optimised by a match.pd version > of this transformation that I'm working on. > Here's the patch with that test added as well. The simplify-rtx transformation catches it, but if we end up adding the match.pd form, it will get caught earlier at the GIMPLE level. The test will pass regardless of where this transformation is done. Ok? Thanks, Kyrill 2016-09-16 Kyrylo Tkachov * simplify-rtx.c (simplify_relational_operation_1): Add transformation (GTU (PLUS a C) (C - 1)) --> (LTU a -C). 2016-09-16 Kyrylo Tkachov * gcc.target/aarch64/gtu_to_ltu_cmp_1.c: New test. * gcc.target/aarch64/gtu_to_ltu_cmp_2.c: New test. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 054c0f9d41664f8a4d11765dfb501647cfbc728f..63e864a237a05d250e3d8a3510775585fe8002db 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -4663,6 +4663,19 @@ simplify_relational_operation_1 (enum rtx_code code, machine_mode mode, cmp_mode, XEXP (op0, 0), new_cmp); } + /* (GTU (PLUS a C) (C - 1)) where C is a non-zero constant can be + transformed into (LTU a -C). */ + if (code == GTU && GET_CODE (op0) == PLUS && CONST_INT_P (op1) + && CONST_INT_P (XEXP (op0, 1)) + && (UINTVAL (op1) == UINTVAL (XEXP (op0, 1)) - 1) + && XEXP (op0, 1) != const0_rtx) + { + rtx new_cmp + = simplify_gen_unary (NEG, cmp_mode, XEXP (op0, 1), cmp_mode); + return simplify_gen_relational (LTU, mode, cmp_mode, + XEXP (op0, 0), new_cmp); + } + /* Canonicalize (LTU/GEU (PLUS a b) b) as (LTU/GEU (PLUS a b) a). */ if ((code == LTU || code == GEU) && GET_CODE (op0) == PLUS diff --git a/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c new file mode 100644 index 0000000000000000000000000000000000000000..81c536c90afe38932c48ed0af24f55e73eeff80e --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int +f1 (int x, int t) +{ + if (x == -1 || x == -2) + t = 1; + + return t; +} + +/* { dg-final { scan-assembler-times "cmn\\tw\[0-9\]+, #2" 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_2.c b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_2.c new file mode 100644 index 0000000000000000000000000000000000000000..e0e999f9df39c29bb79d8a8f7d9a17f213bd115b --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/gtu_to_ltu_cmp_2.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +unsigned int +foo (unsigned int a, unsigned int b) +{ + return (a + 10) > 9; +} + +/* { dg-final { scan-assembler-times "cmn\\tw\[0-9\]+" 1 } } */ +/* { dg-final { scan-assembler-not "add\\tw\[0-9\]+" } } */