From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path:
Received: (qmail 43678 invoked by alias); 24 Jun 2017 06:50:21 -0000
Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id:
List-Archive:
List-Post:
List-Help:
Sender: gcc-patches-owner@gcc.gnu.org
Received: (qmail 43652 invoked by uid 89); 24 Jun 2017 06:50:20 -0000
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=PRE, site
X-HELO: mail2-relais-roc.national.inria.fr
Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 24 Jun 2017 06:50:18 +0000
Received: from 91.70.140.77.rev.sfr.net (HELO stedding) ([77.140.70.91]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jun 2017 08:50:12 +0200
Date: Sat, 24 Jun 2017 06:50:00 -0000
From: Marc Glisse
Reply-To: GCC Patches
To: Andrew Pinski
cc: GCC Patches
Subject: Re: [PATCH] fold a * (a > 0 ? 1 : -1) to abs(a) and related optimizations
In-Reply-To:
Message-ID:
References:
User-Agent: Alpine 2.20 (DEB 67 2015-01-07)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII; format=flowed
X-SW-Source: 2017-06/txt/msg01840.txt.bz2
On Fri, 23 Jun 2017, Andrew Pinski wrote:
> Hi,
> I saw this on llvm's review site (https://reviews.llvm.org/D34579)
> and I thought why not add it to GCC. I expanded more than what was
> done on the LLVM patch.
>
> I added the following optimizations:
> Transform X * (X > 0 ? 1 : -1) into ABS(X).
> Transform X * (X >= 0 ? 1 : -1) into ABS(X).
> Transform X * (X > 0.0 ? 1.0 : -1.0) into ABS(X).
> Transform X * (X >= 0.0 ? 1.0 : -1.0) into ABS(X).
> Transform X * (X > 0 ? -1 : 1) into -ABS(X).
> Transform X * (X >= 0 ? -1 : 1) into -ABS(X).
> Transform X * (X > 0.0 ? -1.0 : 1.0) into -ABS(X).
> Transform X * (X >= 0.0 ? -1.0 : 1.0) into -ABS(X).
> Transform X * (X < 0 ? 1 : -1) into -ABS(X).
> Transform X * (X <= 0 ? 1 : -1) into -ABS(X).
> Transform X * (X < 0.0 ? 1.0 : -1.0) into -ABS(X).
> Transform X * (X <= 0.0 ? 1.0 : -1.0) into -ABS(X).
> Transform X * (X < 0 ? -1 : 1) into ABS(X).
> Transform X * (X <= 0 ? -1 : 1) into ABS(X).
> Transform X * (X < 0.0 ? -1.0 : 1.0) into ABS(X).
> Transform X * (X <= 0.0 ? -1.0 : 1.0) into ABS(X).
>
> The floating points ones only happen when not honoring SNANS and not
> honoring signed zeros.
Some random comments (not a review):
* if X is NaN, we may get a qNaN with the wrong sign bit. We probably
don't care much though...
* I am surprised (X<0.?-1.:1.) and copysign(1., X) remain different for
the whole optimization pipeline with -ffast-math. X*copysign(1., X) is
another candidate to become fabs(X).
* Whenever you get -ABS(X) for integers, what about the case where X is
INT_MIN?
* I guess we can't get there with an unsigned type because X>0 would have
become X!=0 .
* I wonder if we could use something like
(for cmp (gt ge lt le)
outp (convert convert negate negate)
outn (negate negate convert convert)
[...]
(outp (abs @0))
to reduce duplication or if that would be less readable.
* Some of the cases are handled by PRE turning
# iftmp.0_1 = PHI <1.0e+0(5), -1.0e+0(3)>
_3 = iftmp.0_1 * a_2(D);
into
_5 = -a_2(D);
[...]
# iftmp.0_1 = PHI <1.0e+0(2), -1.0e+0(3)>
# prephitmp_6 = PHI
which phiopt3 can handle (quite late).
* With cond, this currently (?) only affects generic, so I am not sure it
will hit very often... But it will be there if someone later writes a
match.pd->phiopt generator ;-)
--
Marc Glisse