From patchwork Mon Jul 6 20:28:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 50795 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 132CE218EA for ; Mon, 6 Jul 2015 20:29:22 +0000 (UTC) Received: by lagc2 with SMTP id c2sf6134920lag.0 for ; Mon, 06 Jul 2015 13:29:21 -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:mime-version:date:message-id:subject:from:to :content-type:x-original-sender:x-original-authentication-results; bh=SE6/ulrF/LV4ZTumpNBMLhlXki59oCJKXOUe6K53hkA=; b=GuJovlPK9cgTMivNKEtuFoJuB/HKEfy/pHxI5r6tyHJxK7IM8Hl06+awhjQLdAviO6 buLPglWaO/oOHTW6lWYwfeJzWqeA+jR1q1idOo9ELQotkM61d3ySiEW7ps/7JkldAGKN VLxSnK72mww6jZz3M9gZ3U42u+zYnQzzB+GttUT+RfSfTZTNAy6Wy+CymAXV9TqcZyEn 4wl3P5AFKlFt6n+T+oMj2tPEdAGakZCEvsCw/2xYWHx29TPkLuoII+8SkijkB5scK6bh jGiPAYRX3S/NVxvcEc/O7pCfSeYeYDCs6V1YwyUKHChQelUCfzyFh2bmJHzLPWfmqzGT rJlA== X-Gm-Message-State: ALoCoQkVGMgj+Fl8LNO0DNagVP2ql4FHcMcRU2DBD3Zp3UogJHOUljk8MujEogfaS0TJo4hI42JI X-Received: by 10.112.42.236 with SMTP id r12mr341326lbl.2.1436214560994; Mon, 06 Jul 2015 13:29:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.10 with SMTP id p10ls746494lag.29.gmail; Mon, 06 Jul 2015 13:29:20 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr614991lbc.41.1436214560798; Mon, 06 Jul 2015 13:29:20 -0700 (PDT) Received: from mail-la0-x22c.google.com (mail-la0-x22c.google.com. [2a00:1450:4010:c03::22c]) by mx.google.com with ESMTPS id eu8si16144939lbc.171.2015.07.06.13.29.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 13:29:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22c as permitted sender) client-ip=2a00:1450:4010:c03::22c; Received: by lagc2 with SMTP id c2so168846298lag.3 for ; Mon, 06 Jul 2015 13:29:20 -0700 (PDT) X-Received: by 10.152.88.77 with SMTP id be13mr572048lab.112.1436214560576; Mon, 06 Jul 2015 13:29:20 -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.108.230 with SMTP id hn6csp1949160lbb; Mon, 6 Jul 2015 13:29:19 -0700 (PDT) X-Received: by 10.70.101.106 with SMTP id ff10mr1302183pdb.162.1436214558477; Mon, 06 Jul 2015 13:29:18 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id w10si30680012pas.189.2015.07.06.13.29.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 13:29:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-402150-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 88755 invoked by alias); 6 Jul 2015 20:29:02 -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 88694 invoked by uid 89); 6 Jul 2015 20:29:02 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-yk0-f181.google.com Received: from mail-yk0-f181.google.com (HELO mail-yk0-f181.google.com) (209.85.160.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 06 Jul 2015 20:29:01 +0000 Received: by ykeo3 with SMTP id o3so38729131yke.0 for ; Mon, 06 Jul 2015 13:28:58 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.170.62.214 with SMTP id e205mr755867yke.95.1436214538021; Mon, 06 Jul 2015 13:28:58 -0700 (PDT) Received: by 10.37.88.137 with HTTP; Mon, 6 Jul 2015 13:28:57 -0700 (PDT) Date: Tue, 7 Jul 2015 01:58:57 +0530 Message-ID: Subject: move a * (1 << b) -> a << b pattern from fold-const.c to match.pd From: Prathamesh Kulkarni To: Richard Biener , gcc Patches X-IsSubscribed: yes X-Original-Sender: prathamesh.kulkarni@linaro.org 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:c03::22c as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Hi, The attached patch moves pattern a * (1 << b) -> a << b. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. OK for trunk if testing passes ? Thank you, Prathamesh 2015-07-06 Prathamesh Kulkarni * fold-const.c (fold_binary_loc): Remove pattern a * 1 << b -> a << b. * match.pd (a * 1 << b -> a << b): New pattern. testsuite/ * gcc.dg/tree-ssa/fold-shiftmult.c: New test-case. Index: fold-const.c =================================================================== --- fold-const.c (revision 225473) +++ fold-const.c (working copy) @@ -10175,16 +10175,6 @@ negate_expr (arg0)), tem); - /* (a * (1 << b)) is (a << b) */ - if (TREE_CODE (arg1) == LSHIFT_EXPR - && integer_onep (TREE_OPERAND (arg1, 0))) - return fold_build2_loc (loc, LSHIFT_EXPR, type, op0, - TREE_OPERAND (arg1, 1)); - if (TREE_CODE (arg0) == LSHIFT_EXPR - && integer_onep (TREE_OPERAND (arg0, 0))) - return fold_build2_loc (loc, LSHIFT_EXPR, type, op1, - TREE_OPERAND (arg0, 1)); - /* (A + A) * C -> A * 2 * C */ if (TREE_CODE (arg0) == PLUS_EXPR && TREE_CODE (arg1) == INTEGER_CST Index: match.pd =================================================================== --- match.pd (revision 225473) +++ match.pd (working copy) @@ -854,6 +854,12 @@ && tree_expr_nonnegative_p (@1)) @0)) +/* a * (1 << b) -> a << b */ +(simplify + (mult:c @a (lshift integer_onep @b)) + (if (!FLOAT_TYPE_P (type)) + (lshift @a @b))) + (for shiftrotate (lrotate rrotate lshift rshift) (simplify (shiftrotate @0 integer_zerop) Index: testsuite/gcc.dg/tree-ssa/fold-shiftmult.c =================================================================== --- testsuite/gcc.dg/tree-ssa/fold-shiftmult.c (revision 0) +++ testsuite/gcc.dg/tree-ssa/fold-shiftmult.c (working copy) @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-forwprop-details" } */ + +int f1(int a, int b) +{ + int t1 = 1 << b; + int f1_val = a * t1; + return f1_val; +} +/* { dg-final { scan-tree-dump "gimple_simplified to f1_val_\\d\+ = a_\\d\+\\(D\\) << b_\\d\+\\(D\\)" "forwprop1" } } */ + +int f2(int a, int b) +{ + int t1 = 1 << b; + int f2_val = t1 * a; + return f2_val; +} + +/* { dg-final { scan-tree-dump "gimple_simplified to f2_val_\\d\+ = a_\\d\+\\(D\\) << b_\\d\+\\(D\\)" "forwprop1" } } */