From patchwork Fri Sep 15 11:00:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 112721 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp473506qgf; Fri, 15 Sep 2017 04:01:06 -0700 (PDT) X-Received: by 10.99.96.23 with SMTP id u23mr24308831pgb.257.1505473266348; Fri, 15 Sep 2017 04:01:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505473266; cv=none; d=google.com; s=arc-20160816; b=zCAZFeiU7BtbmxSkIupm/U7TmLrDnDLNjJ5rbDdUuWC91lX0lp9Dfb3kHFa11D8PZR HaFFIV+rcaZR2vyYBQIYb2GqCLJ3sG7ZDVZs+yOj9u9GoeD1/m41/7Np7ojIlTFmSEw1 NMoONYodvdo4I1hm86uOH0YFSOXjOdqUtH7qsgNwov6jlzlAJz43m9qFOcz1vq4nEwy5 EiZIMe+8JTNGHEjlrfzCm9WP0PSde/r1Br/+LmCzJy2MhgonlUl3ZUCkKGx8b3qyrheg Z42kRQk88/fdx3UKatxS9mvmmrih8ysykEnaKhim9db4MOD/I3dwd/00/U0ZjC/u0mei 7Ixw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=OTOabqdaVvMZe3itDlCSXi3fjpuV7JSTvHLEmLYYheg=; b=vk+6/d33qIBsG7Ae5cVCIXwEQ1MyF96DzjZbWcjifY8391NjMzKfHPWS/3x4TrA7nr 82HgOUzCOjlQRKks9o3ZfAsENO3gwF5o0c8tIpZIt7UuaiZDrPQDe27Oy8FeGinax9XW lYk5S0WH7JutW9fK/Y7i4w6IakbIHCPiBLJEWstH5R6bKMdTpRYG56KQccbtUJV7Uu/Z gvR1tUYbadLe5muaDFoESF61EzvUUnzRynd5XbPQKKiQj2LNCOLZRT+qM26Wilg4qkph FUjczAdATgMBYfrLrEP4ZvjgsgLm49DT6ISq/BhZzyHqP3njI/FA7Mn9Pu61FlVhd3g8 rkYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rELpElMC; spf=pass (google.com: domain of gcc-patches-return-462225-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462225-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id r88si471691pfj.213.2017.09.15.04.01.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 04:01:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-462225-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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rELpElMC; spf=pass (google.com: domain of gcc-patches-return-462225-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462225-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=Fvr1beg8+A3/u7iK5mBLEHHJMO9G81lOnf3Wx64C+Htln7 ETCGKKxA3EJWPkktJZfbklVIRszVeHHXqQLCxBT4jJETt2Zc6UOT3wQ9EKD+bYwe VLXIRQmq1oyRmtg6ZYRJ+4Kvq2IYIW2T8BlmqOU71S0VPqiTWEy0rX+SVVThk= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=7jPpZofupc1SWQkIy1x5rSq9+8Q=; b=rELpElMCikZ59+z6P4lb GPGVK9oHv6KW7s3L2rTcpZRWokPNUAj3oypEXxBA7cwjOKj9IGtCetU0V7/ZTKFf WOaBQsnz6vv06rH/vxHyw+O2DRiZ6DanydQmJcXDp0XfJAOK25I2nMmwaayJzTus fvyWqYyUMA6/2OwGy59q8LI= Received: (qmail 88235 invoked by alias); 15 Sep 2017 11:00:52 -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 83058 invoked by uid 89); 15 Sep 2017 11:00:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f179.google.com Received: from mail-wr0-f179.google.com (HELO mail-wr0-f179.google.com) (209.85.128.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Sep 2017 11:00:47 +0000 Received: by mail-wr0-f179.google.com with SMTP id 108so1518959wra.5 for ; Fri, 15 Sep 2017 04:00:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=zyrKqFbTen29kqBicyduGKm9OVz788re/XP5FADCC3g=; b=EBYVOY2waUJTBy08P5664n2qO104w6TKO50w0R1S/JXWPUzBQ5RsRNY64ocqwX/q8w LVW+zLEofH7ngzWqFN8+Zq02I9VsJB5bNwJcrlTTtzG0pbRtA0gviuvwlpttO8rnuZ3R /89UoUH13EwFyq/i5ywAZLfzly3paVwcM1n9n+ewl2gegJTXXHVeighlmO3YimiHKP0x fzM//wJedIWYZ6vFXxFKLP9grJ0QSBopprbe7tiB4qLfmokfSFHa9A11MejuXXRpj/J1 Zf4mpD+Va9GK+8+Rv70XjSHmxWEyLo2U2EHnclE1dk3aYo9xA0HPuRg2z4LIH4DS34AT yTQQ== X-Gm-Message-State: AHPjjUgKXWPhae7TSV0F1mAT0IY/ND09iDeTegxg8bgTL/pj6CX2dfcA VH/OUMchamgzoLsRkl2QOYGDCqfjarHXrdmeQTvbOlI4LGI= X-Google-Smtp-Source: ADKCNb6RSmTduDQrLpOIwNqVvfwnPZB6tfsc3JN8bylKcM5aEyJ7bNyFs+dMtwPe9fCw+UcPnQDVNvlY9v3z04gjF3Q= X-Received: by 10.223.157.203 with SMTP id q11mr19102481wre.96.1505473244914; Fri, 15 Sep 2017 04:00:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.130.110 with HTTP; Fri, 15 Sep 2017 04:00:43 -0700 (PDT) From: Prathamesh Kulkarni Date: Fri, 15 Sep 2017 16:30:43 +0530 Message-ID: Subject: Transform (x / y) != 0 to x >=y and (x / y) == 0 to x < y if x, y are unsigned To: gcc Patches , Richard Biener X-IsSubscribed: yes Hi, This patch adds the transforms mentioned in $subject. Bootstrap+test in progress on x86_64-unknown-linux-gnu. OK to commit if passes ? Thanks, Prathamesh 2017-09-15 Prathamesh Kulkarni * match.pd ((X / Y) == 0 -> X < Y): New pattern. ((X / Y) != 0 -> X >= Y): Likewise. testsuite/ * gcc.dg/tree-ssa/cmpdiv.c: New test. diff --git a/gcc/match.pd b/gcc/match.pd index dbfceaf10a5..0e1b59c9c10 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1266,6 +1266,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))) (op @1 @0)))) +/* (X / Y) == 0 -> X < Y if X, Y are unsigned. */ +(simplify + (eq (trunc_div @0 @1) integer_zerop) + (if (TYPE_UNSIGNED (TREE_TYPE(@0)) && TYPE_UNSIGNED (TREE_TYPE (@1))) + (lt @0 @1))) + +/* (X / Y) != 0 -> X >= Y, if X, Y are unsigned. */ +(simplify + (ne (trunc_div @0 @1) integer_zerop) + (if (TYPE_UNSIGNED (TREE_TYPE(@0)) && TYPE_UNSIGNED (TREE_TYPE (@1))) + (ge @0 @1))) + /* X == C - X can never be true if C is odd. */ (for cmp (eq ne) (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c new file mode 100644 index 00000000000..14161f5ea6f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ + +_Bool f1(unsigned x, unsigned y) +{ + unsigned t1 = x / y; + _Bool t2 = (t1 != 0); + return t2; +} + +_Bool f2(unsigned x, unsigned y) +{ + unsigned t1 = x / y; + _Bool t2 = (t1 == 0); + return t2; +} + +/* { dg-final { scan-tree-dump-not "trunc_div_expr" "optimized" } } */