From patchwork Thu Sep 29 12:23:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 676617 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 3slDJl02clz9s8x for ; Thu, 29 Sep 2016 22:24:05 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=XyNkaQiu; 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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=V3MCBkbsbO2hFUC/ the86jEHPKVAfQV7SiVgzglo1Rt/EunVYGFYRb+MASCSvsQhO1C8/KiElyaDXVGb oDqQJah5axmGHhPtGKxvs6JOufROdzMpfPaf9ffHV6CsrN85Z6BfDQjOhXD0n4zB tFkAhC4TySK0aUkIeFqW/3jVLoY= 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:date :from:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=9VdaSlBQI9NncdAJY0KzOp vgawk=; b=XyNkaQiuH5SGJwy3A+hc1urncLzDaaaXQ188loVD36WkrYONucTUKI sehnC8Svi0sMRmA1LSPkHl6SpMrjhjVE0K2a20E7kHvfLGdNTFef6tgBTpTLJx+e 4SbdrBbXulNCSyfwW9fXeEvH6NwDRDA/gp2hbpBIsn9XyzbPDSO1E= Received: (qmail 62827 invoked by alias); 29 Sep 2016 12:23:53 -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 62722 invoked by uid 89); 29 Sep 2016 12:23:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Sep 2016 12:23:41 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C6DC5ABE4; Thu, 29 Sep 2016 12:23:39 +0000 (UTC) Date: Thu, 29 Sep 2016 14:23:39 +0200 (CEST) From: Richard Biener To: Joseph Myers cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix PR55152 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 On Thu, 29 Sep 2016, Richard Biener wrote: > On Wed, 28 Sep 2016, Joseph Myers wrote: > > > On Wed, 28 Sep 2016, Richard Biener wrote: > > > > > Index: gcc/testsuite/gcc.dg/pr55152.c > > > =================================================================== > > > --- gcc/testsuite/gcc.dg/pr55152.c (revision 0) > > > +++ gcc/testsuite/gcc.dg/pr55152.c (working copy) > > > @@ -0,0 +1,13 @@ > > > +/* { dg-do compile } */ > > > +/* { dg-options "-O -ffinite-math-only -fstrict-overflow -fdump-tree-optimized" } */ > > > + > > > +double g (double a) > > > +{ > > > + return (a>=-a)?a:-a; > > > > You should need -fno-signed-zeros for this (that is, for the > > transformation to MAX_EXPR), not -ffinite-math-only. For a == -0, that > > function should return -0, but abs would produce +0. > > This means that tree-ssa-phiopt.c has a bug: > > static bool > minmax_replacement (basic_block cond_bb, basic_block middle_bb, > edge e0, edge e1, gimple *phi, > tree arg0, tree arg1) > { > ... > /* The optimization may be unsafe due to NaNs. */ > if (HONOR_NANS (type)) > return false; > > and it should check HONOR_SIGNED_ZEROS as well. > > I'll fix that as a followup. Committed as follows. Bootstrapped / tested on x86_64-unknown-linux-gnu. Richard. 2016-09-29 Richard Biener PR middle-end/55152 * match.pd: Add max(a,-a) -> abs(a) pattern. * tree-ssa-phiopt.c (minmax_replacement): Disable for HONOR_SIGNED_ZEROS types. * gcc.dg/pr55152.c: New testcase. * gcc.dg/tree-ssa/phi-opt-5.c: Adjust. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 240565) +++ gcc/match.pd (working copy) @@ -1271,6 +1284,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (max:c (min:c @0 @1) @1) @1) +/* max(a,-a) -> abs(a). */ +(simplify + (max:c @0 (negate @0)) + (if (TREE_CODE (type) != COMPLEX_TYPE + && (! ANY_INTEGRAL_TYPE_P (type) + || TYPE_OVERFLOW_UNDEFINED (type))) + (abs @0))) (simplify (min @0 @1) (switch Index: gcc/tree-ssa-phiopt.c =================================================================== --- gcc/tree-ssa-phiopt.c (revision 240565) +++ gcc/tree-ssa-phiopt.c (working copy) @@ -1075,7 +1075,7 @@ minmax_replacement (basic_block cond_bb, type = TREE_TYPE (PHI_RESULT (phi)); /* The optimization may be unsafe due to NaNs. */ - if (HONOR_NANS (type)) + if (HONOR_NANS (type) || HONOR_SIGNED_ZEROS (type)) return false; cond = as_a (last_stmt (cond_bb)); Index: gcc/testsuite/gcc.dg/pr55152.c =================================================================== --- gcc/testsuite/gcc.dg/pr55152.c (revision 0) +++ gcc/testsuite/gcc.dg/pr55152.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O -ffinite-math-only -fno-signed-zeros -fstrict-overflow -fdump-tree-optimized" } */ + +double g (double a) +{ + return (a>=-a)?a:-a; +} +int f(int a) +{ + return (a>=-a)?a:-a; +} + +/* { dg-final { scan-tree-dump-times "ABS_EXPR" 2 "optimized" } } */ Index: gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c (revision 240612) +++ gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c (working copy) @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -ffinite-math-only -fdump-tree-phiopt1" } */ +/* { dg-options "-O1 -ffinite-math-only -fno-signed-zeros -fdump-tree-phiopt1" } */ float repl1 (float varx) {