From patchwork Wed Aug 3 07:53:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 73193 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp638108qga; Wed, 3 Aug 2016 00:54:13 -0700 (PDT) X-Received: by 10.98.147.156 with SMTP id r28mr92095534pfk.154.1470210853852; Wed, 03 Aug 2016 00:54:13 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id n28si7631861pfa.263.2016.08.03.00.54.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Aug 2016 00:54:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-433034-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; spf=pass (google.com: domain of gcc-patches-return-433034-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-433034-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=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=CtJHVZcOO/zzQuhekcMxwFj05cSBbW9FblMIbAhIcLc14r uvfxIZeF/G6jzK5hcDRYW6xz4IUDhMsBz391LA4GhTqOX22y6gwfpMuVdKGFmguw WtvzPo1Ojcqr7ITFJ+km1vAmVp1fxI3bQJ1l0q++NR0gsVquQZCahWYwphC9E= 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=1NrcSeKNAziOyVljPsrDgb9OGZg=; b=fNxEIchK6Ek7EmxvuLdi p8YaYVnk0KqMpZpeB20zQ6Lsc8OspwIEkEi/n7UAhx9C1AUL+WRAmqNUSqjmvLLj sDopSD0JwXE65hiYyhU1/3XSy+rTD8/OybMf5xamilyqTzdw1FbbnGRPNQqjMcGp aoWkvqbmkM+J80mOR375ACM= Received: (qmail 16634 invoked by alias); 3 Aug 2016 07:54:02 -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 16623 invoked by uid 89); 3 Aug 2016 07:54:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=D*1, HX-Received:Wed, 2016-08-03, 20160803 X-HELO: mail-it0-f50.google.com Received: from mail-it0-f50.google.com (HELO mail-it0-f50.google.com) (209.85.214.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 03 Aug 2016 07:53:51 +0000 Received: by mail-it0-f50.google.com with SMTP id f6so224124273ith.0 for ; Wed, 03 Aug 2016 00:53:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=k9+iJA1m5hfjZFLfugwQoDSZ6Mj0m/iOtgt9qeijA6Y=; b=P/54v17p/Wa+b4Mta0g4/OC/VeCbBzm0Ff9rGt56pNmbhTjbpAQXodAAE534ZXPljb n6MBcOf2ojIKZxBdlIGQwwTgTkc9UOneKiuFMFUNiFcqc1snwJpHRh1yxvVcUun4Oqc2 j6lkx2hWGI0t3wadhu8uu034ECXpZajGb7VxeITESLjUrlAe78IRdE6Gmk/KD8dXcvlm yUO/y0xBGrMLU9scc3kRxjNN8kkykJYSrBWFxoBHPOhpDgMS/2fHwNfu9/tYznWV/HUE SnYpbTeeC4DOIS7REICarXTkKcORAZ9PrfgCKikJZ/YePFVAjf01pSCbo4BmB0WjGSRq Qr8w== X-Gm-Message-State: AEkooutm9eYjYMKxEP7Fqh2f5OSWP3RUGXZOr3Ljz3KCPhbCmLOWuyGsrfhkOID/sH4eHtQR8buoUHbTo9U7dO0t X-Received: by 10.36.130.135 with SMTP id t129mr21239979itd.31.1470210828327; Wed, 03 Aug 2016 00:53:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.208.18 with HTTP; Wed, 3 Aug 2016 00:53:47 -0700 (PDT) From: Prathamesh Kulkarni Date: Wed, 3 Aug 2016 13:23:47 +0530 Message-ID: Subject: [PR57371] transform (double)i eq/ne 0 to i eq/ne 0 To: Richard Biener , "Joseph S. Myers" , gcc Patches X-IsSubscribed: yes Hi, The attached patch tries to transform (double)i eq/ne 0 to i eq/ne 0 AFAIU from Joseph's comment 1 in PR, the transform should be safe with -fno-trapping-math ? Bootstrap+tested on x86_64-unknown-linux-gnu in progress. Thanks, Prathamesh 2016-08-03 Prathamesh Kulkarni PR tree-optimization/57371 * match.pd ((double) i eq/ne 0 -> i eq/ne 0): New pattern. testsuite/ * gcc.dg/pr57371-1.c: New test-case. * gcc.dg/pr57371-2.c: Likewise. diff --git a/gcc/match.pd b/gcc/match.pd index 2380d90..63be2e9 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2611,6 +2611,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) { constant_boolean_node (cmp == ORDERED_EXPR || cmp == LTGT_EXPR ? false : true, type); }))) +/* PR57371: Transform (double)i eq/ne 0 to i eq/ne 0. */ +(for cmp (ne eq) + (simplify + (cmp (float @0) real_zerop@1) + (if (!flag_trapping_math && INTEGRAL_TYPE_P (TREE_TYPE (@0))) + (cmp @0 { build_zero_cst (TREE_TYPE (@0)); })))) + /* bool_var != 0 becomes bool_var. */ (simplify (ne @0 integer_zerop) diff --git a/gcc/testsuite/gcc.dg/pr57371-1.c b/gcc/testsuite/gcc.dg/pr57371-1.c new file mode 100644 index 0000000..fd15509 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr57371-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-trapping-math -fdump-tree-gimple" } */ + +int f1(int i) +{ + return (double)i != 0; +} + +int f2(int i) +{ + return (double)i == 0; +} + +/* { dg-final { scan-tree-dump-times "double" 0 "gimple" } } */ diff --git a/gcc/testsuite/gcc.dg/pr57371-2.c b/gcc/testsuite/gcc.dg/pr57371-2.c new file mode 100644 index 0000000..e19d054 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr57371-2.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-trapping-math -fdump-tree-forwprop-details" } */ + +int f1(int i) +{ + double x = (double) i; + return x != 0.0; +} + +int f2(int i) +{ + double x = (double) i; + return x == 0.0; +} + +/* { dg-final { scan-tree-dump "i_\[0-9\]*\\(D\\) != 0" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "i_\[0-9\]*\\(D\\) == 0" "forwprop1" } } */