From patchwork Mon Jul 27 03:41:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Collison X-Patchwork-Id: 51479 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by patches.linaro.org (Postfix) with ESMTPS id 9DB6922DA5 for ; Mon, 27 Jul 2015 03:42:19 +0000 (UTC) Received: by wicmv11 with SMTP id mv11sf23164105wic.1 for ; Sun, 26 Jul 2015 20:42:18 -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:message-id:date:from:user-agent:mime-version:to :subject:content-type:content-transfer-encoding:x-original-sender :x-original-authentication-results; bh=dgo4lMpIk/8VnWMoKncKyqtbemPaiKkt8v6vOtTlXjg=; b=dT1+hgnwZfHe5aVk1mIng/iUMgPhiF99ZHB1BmTEKEv2pY+bqix1IZ5Hhp5MVa0cng QKgL6lVPApblcQjfwaNl9fYecWd6QpNe3CgZdGWHKaedhFdLAuNrbaAfPEND5uSj6nF7 6xCHfcBXptpc/tIBAL0BZV4zo8e9xCbXHnXrCg8Jp9omqGD+W22YRtj50TgP2Hxe8ltG 0s9ZZNRmaGQZ9deH54GV5Q4l8RI9GjnJHrRhBLhsfOPjtVH101g1aC5D9rghKNxRrLsn 5dTLT4YooVsEKX/AonrJQs5wPxDBTr8cCthnHII7n1Ck9kqNVDmGtamtYUhDDONBQhdm Kj0g== X-Gm-Message-State: ALoCoQkBCATXMQDx0NeJBI2U501h6dH3hwnAo7bIJ1/rGDLtq1ZiOP3TglF6PxQ1AGQD0QAdBAUV X-Received: by 10.112.51.177 with SMTP id l17mr11287375lbo.1.1437968538638; Sun, 26 Jul 2015 20:42:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.2 with SMTP id s2ls552975lal.86.gmail; Sun, 26 Jul 2015 20:42:18 -0700 (PDT) X-Received: by 10.152.207.76 with SMTP id lu12mr24923998lac.29.1437968538492; Sun, 26 Jul 2015 20:42:18 -0700 (PDT) Received: from mail-lb0-x236.google.com (mail-lb0-x236.google.com. [2a00:1450:4010:c04::236]) by mx.google.com with ESMTPS id ua6si14204849lbb.136.2015.07.26.20.42.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 20:42:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::236 as permitted sender) client-ip=2a00:1450:4010:c04::236; Received: by lbbzr7 with SMTP id zr7so44985623lbb.1 for ; Sun, 26 Jul 2015 20:42:18 -0700 (PDT) X-Received: by 10.112.126.101 with SMTP id mx5mr25422649lbb.35.1437968538330; Sun, 26 Jul 2015 20:42:18 -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.7.198 with SMTP id l6csp1291556lba; Sun, 26 Jul 2015 20:42:17 -0700 (PDT) X-Received: by 10.70.45.225 with SMTP id q1mr63717185pdm.46.1437968535446; Sun, 26 Jul 2015 20:42:15 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id tl1si40769039pac.65.2015.07.26.20.42.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 20:42:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-403948-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 21468 invoked by alias); 27 Jul 2015 03:42:04 -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 21458 invoked by uid 89); 27 Jul 2015 03:42:03 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f43.google.com Received: from mail-pa0-f43.google.com (HELO mail-pa0-f43.google.com) (209.85.220.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 27 Jul 2015 03:42:02 +0000 Received: by pabkd10 with SMTP id kd10so44051238pab.2 for ; Sun, 26 Jul 2015 20:41:59 -0700 (PDT) X-Received: by 10.66.253.72 with SMTP id zy8mr64409137pac.102.1437968519650; Sun, 26 Jul 2015 20:41:59 -0700 (PDT) Received: from [192.168.1.14] (ip70-176-202-128.ph.ph.cox.net. [70.176.202.128]) by smtp.googlemail.com with ESMTPSA id q5sm26440954pde.56.2015.07.26.20.41.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 20:41:59 -0700 (PDT) Message-ID: <55B5A884.4060105@linaro.org> Date: Sun, 26 Jul 2015 20:41:56 -0700 From: Michael Collison User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: gcc Patches Subject: [PATCH] Optimize certain end of loop conditions into min/max operation X-Original-Sender: michael.collison@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:c04::236 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 This patch is designed to optimize end of loop conditions involving of the form i < x && i < y into i < min (x, y). Loop condition involving '>' are handled similarly using max(x,y). As an example: #define N 1024 int a[N], b[N], c[N]; void add (unsignedint m, unsignedint n) { unsignedint i, bound = (m < n) ? m : n; for (i = 0; i < m && i < n; ++i) a[i] = b[i] + c[i]; } Performed bootstrap and make check on: x86_64_unknown-linux-gnu, arm-linux-gnueabihf, and aarch64-linux-gnu. Okay for trunk? 2015-07-24 Michael Collison Andrew Pinski * match.pd ((x < y) && (x < z) -> x < min (y,z), (x > y) and (x > z) -> x > max (y,z)) diff --git a/gcc/match.pd b/gcc/match.pd index 5e8fd32..8691710 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1793,3 +1793,17 @@ along with GCC; see the file COPYING3. If not see (convert (bit_and (op (convert:utype @0) (convert:utype @1)) (convert:utype @4))))))) + +/* Transform (@0 < @1 and @0 < @2) to use min */ +(for op (lt le) +(simplify +(bit_and:c (op @0 @1) (op @0 @2)) +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) +(op @0 (min @1 @2))))) + +/* Transform (@0 > @1 and @0 > @2) to use max */ +(for op (gt ge) +(simplify +(bit_and:c (op @0 @1) (op @0 @2)) +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) +(op @0 (max @1 @2)))))