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: 500201 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 56FAD140326 for ; Mon, 27 Jul 2015 13:42:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LI0Rp5b+; 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:content-type :content-transfer-encoding; q=dns; s=default; b=xGhy9mrO8HriLf+j 0aH5cZpZJShUYKXg5E1b7myi+NeV49Qz3mRZsPhtSLR6ZU58XB5kjk8vkPhX2mtG fprBlnirV8o7P8ypQ5Wt3XxxIWuAnogIW68Bpo+d1/BTQ4Eo9SyricrRBFHqhwjj XY0LfbWp1rPPAZis/QxafoZ8PNo= 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 :content-transfer-encoding; s=default; bh=wW/dRF0DR2X4XTwALulGVR i+kfw=; b=LI0Rp5b+qvI68gi51gaJeXVUQmPqyl+CvXG8J0eZPJ3aVJiz1iHtzZ jVaZiSXBfc+/yLGXVjuK/uonRneruqk6c9rU4+wW5WREBifxmuDEWZ6VpGcSEXut wZ94JSsTGhjX5DLb9rUDsCmhI8aUJ6OLSPdCYQfES+eqVGOzGUEsE= Received: (qmail 21468 invoked by alias); 27 Jul 2015 03:42:04 -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 21458 invoked by uid 89); 27 Jul 2015 03:42:03 -0000 Authentication-Results: sourceware.org; auth=none 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-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:subject:content-type:content-transfer-encoding; bh=dgo4lMpIk/8VnWMoKncKyqtbemPaiKkt8v6vOtTlXjg=; b=TyFiazoLSGRyqhkk9PhuFQg0LlsIWQ6wMOemXgV+9lvxh5C4mPAZWG3GAdefxZiiRX JgritP7xSiTHNeNPc33TyoH+VtiF8oiwN1Bvw9rh+HdaIEscAWx4dy/ItqITbS136HUx G+pe6ENOqylhf3cr6iKJlhfB6PwoMXp9+MxAyp/iAzogOnPPniwdDmHLUixQhBbefxpn jXUIyKWGvuWnmp2szY7G/lRPiuhxV8Hp/54L4T4mDKrJ+SAmeR3MRYvwZ8yinb50mOGE V0byFNyO/knqGyJa0i0WufPqzTbQ4wSBW9fVi+QgAMP5vZmiL08nefaD06Ea269HlSl7 tFVw== X-Gm-Message-State: ALoCoQlYIqkamlmiSifWXSXpl9YYO7scSYTwHz5xUkuMy8KsZuDvmJWcIK+G+aRBpM0EUS6+I0A6 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 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)))))