From patchwork Thu Nov 19 10:26:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 56980 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3089746lbb; Thu, 19 Nov 2015 02:26:47 -0800 (PST) X-Received: by 10.66.251.226 with SMTP id zn2mr9492366pac.44.1447928806993; Thu, 19 Nov 2015 02:26:46 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id k8si11356507pbq.49.2015.11.19.02.26.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Nov 2015 02:26:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-414600-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-414600-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-414600-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:cc:subject:content-type; q=dns; s=default; b=NBZZVHJinuvrd4hBaIO7RWEuL4dCCA0L04enDEUsABi J50yQcYjfDHAOpV7R05t90cbQavYMR1UZRtTP4Lx7tmAxCavykM0g3smjOUllYIf 5FSa0O+JBrVbszxQSLRLkP4bb4CsneiFFJ7M1ClMIbqg03G8dyxVWNB+la5JJPxY = 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:cc:subject:content-type; s=default; bh=Z6+1znjlPl84rmIbMfYHF7v3FmY=; b=iCjL5hTKYRWgpF6Eq GODyGWq3QB6u0/iMpr8Arv30jtRBBSKefhZ+IXLv8D7szZ60EWz42o5lGo0eiSG1 0BZsLq1wZitaUs2NQRr9opGoOmB/lIxPmAIPeSwIfYIdOqipb7FCiF74bkOk5Fcx 5P8gVCQalCEbAUlhQiLxwLig7Y= Received: (qmail 2355 invoked by alias); 19 Nov 2015 10:26: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 2342 invoked by uid 89); 19 Nov 2015 10:26:34 -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, 19 Nov 2015 10:26:33 +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-20-ibilrm__SUiyFsykATpj2g-1; Thu, 19 Nov 2015 10:26:26 +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, 19 Nov 2015 10:26:25 +0000 Message-ID: <564DA3D1.10905@arm.com> Date: Thu, 19 Nov 2015 10:26:25 +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 CC: Segher Boessenkool Subject: [PATCH][combine] PR rtl-optimization/68381: Only restrict pure simplification in mult-extend subst case, allow other substitutions X-MC-Unique: ibilrm__SUiyFsykATpj2g-1 X-IsSubscribed: yes Hi all, In this PR we end up removing a widening multiplication. I suspect it's some path in combine that doesn't handle the case where we return clobber of 0 properly. This started with my recent combine patch r230326. Changing the subst hunk from that patch to just return x when handling a no-op substitution fixes the testcase for me and doesn't regress the widening-mult cases that r230326 improved. In fact, with this patch I'm seeing improved codegen for aarch64 with some widening multiplications combined with constant operands and ending up in bitfield move/insert instructions. Bootstrapped and tested on aarch64, arm, x86_64. Ok for trunk? Thanks, Kyrill 2015-11-19 Kyrylo Tkachov PR rtl-optimization/68381 * combine.c (subst): Do not return clobber of zero in widening mult case. Just return x unchanged if it is a no-op substitution. 2015-11-19 Kyrylo Tkachov PR rtl-optimization/68381 * gcc.c-torture/execute/pr68381.c: New test. commit 58ec17169da2bb864d2bcaeb34a33e8c5a93348f Author: Kyrylo Tkachov Date: Tue Nov 17 15:33:58 2015 +0000 [combine] PR rtl-optimization/68381: Only restrict pure simplification in mult-extend subst case, allow other substitutions diff --git a/gcc/combine.c b/gcc/combine.c index 26b14bf..3791abf 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -5286,7 +5286,7 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy) || GET_CODE (SET_DEST (x)) == PC)) fmt = "ie"; - /* Substituting into the operands of a widening MULT is not likely + /* Trying to simplify the operands of a widening MULT is not likely to create RTL matching a machine insn. */ if (code == MULT && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND @@ -5294,13 +5294,10 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy) && (GET_CODE (XEXP (x, 1)) == ZERO_EXTEND || GET_CODE (XEXP (x, 1)) == SIGN_EXTEND) && REG_P (XEXP (XEXP (x, 0), 0)) - && REG_P (XEXP (XEXP (x, 1), 0))) - { - if (from == to) - return x; - else - return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx); - } + && REG_P (XEXP (XEXP (x, 1), 0)) + && from == to) + return x; + /* Get the mode of operand 0 in case X is now a SIGN_EXTEND of a constant. */ diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68381.c b/gcc/testsuite/gcc.c-torture/execute/pr68381.c new file mode 100644 index 0000000..33012a3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr68381.c @@ -0,0 +1,22 @@ +/* { dg-options "-fexpensive-optimizations -fno-tree-bit-ccp" } */ + +__attribute__ ((noinline, noclone)) +int +foo (unsigned short x, unsigned short y) +{ + int r; + if (__builtin_mul_overflow (x, y, &r)) + __builtin_abort (); + return r; +} + +int +main (void) +{ + int x = 1; + int y = 2; + if (foo (x, y) != x * y) + __builtin_abort (); + return 0; +} +