From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id C337E3857C72 for ; Tue, 30 Aug 2022 07:03:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C337E3857C72 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x635.google.com with SMTP id u9so20229803ejy.5 for ; Tue, 30 Aug 2022 00:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=N8HGO859XWFikPZZ19ipL85npwMRJfMI+8cXZLPOSC0=; b=Q1hNGnGiJMXILO4I2GtZ71pKnaBbed/FF89W844hXHUTszJKIU7351t3fE1g+YgEdZ AtWInmzg3BmE//yxoMOQj+CkGpqOkZvKlRhjKS5I1y6jBwpoKRNOG19wX8eeYXBNkAQW 2T6OpRFIVL5q6ZitAvYE4jqTsYYyXmku9DHgEtNvhTwkHrLBxx2v94Alf694OOP1ZPw6 iqyKfDRrFZQSm1iABSIRArbJtSyyDgB6nK9L9+9Jekk5tvf2YI2L9z9CQvx0A+JkOt2l DmtPWY5NUaZowrqfbez2OlxlVAqsBcrPGFUReTa6VrDEX6v2xMBUGhpBwVw0tB395w0/ vBOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=N8HGO859XWFikPZZ19ipL85npwMRJfMI+8cXZLPOSC0=; b=DKn6SMyhwrfA/pTWwt7lYXImKLIZSyEJYINR8mu4i+jSbKjEtFC+H+/gkPVMD3s1fG 8KPBaBdzdOLR6+BTOUXqlNzQdH+SHDzAHtNP8CPGh3EdBTItcTSRMTZA4SPr5e82/h5J toD6NCOJQWPE68KSKPA0lhprWXBrwWKhhpKqAu7JCdaU00oyoeXW7aUrQlgpJ0EzkDNr rqT3KqXYgqWjhpHx73ERhqzNdJx2B4/w4VRqwCVThlw5RDxtQf4HvD/hBBbM/Nu/I5ox 5d/Uy/J1r522YoriNZmrEN0inNujBV7YJwhk8STCUzWnfiFq5ATfAP2/P9YK3kpE6NtB yviA== X-Gm-Message-State: ACgBeo1zi/DcuSCcQbS/9yIiVWJUz6ZCQbR9xz9oIHknP1kR1l1PjLjV OIClB5j5Sz925q/nQXh5L3fFl+mizNUcy/PjZj4= X-Google-Smtp-Source: AA6agR6VCd0FNgswFhZ9aIAZUqU11eaPR+JkFQ/Z+dGRs0MPNdVKtjhyH353/0Hpu5iNr7h4G70vXW4Kl0CzD7Thotg= X-Received: by 2002:a17:907:7613:b0:73d:ca26:1ec7 with SMTP id jx19-20020a170907761300b0073dca261ec7mr15553374ejc.511.1661843006472; Tue, 30 Aug 2022 00:03:26 -0700 (PDT) MIME-Version: 1.0 References: <20220829204439.1749727-1-aldyh@redhat.com> In-Reply-To: <20220829204439.1749727-1-aldyh@redhat.com> From: Richard Biener Date: Tue, 30 Aug 2022 09:03:14 +0200 Message-ID: Subject: Re: [PATCH] A == 0 ? A : -A same as -A (when A is 0.0) To: Aldy Hernandez Cc: GCC patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Aug 29, 2022 at 10:45 PM Aldy Hernandez via Gcc-patches wrote: > > The upcoming work for frange triggers a regression in > gcc.dg/tree-ssa/phi-opt-24.c. > > For -O2 -fno-signed-zeros, we fail to transform the following into -A: > > float f0(float A) > { > // A == 0? A : -A same as -A > if (A == 0) return A; > return -A; > } > > This is because the abs/negative match.pd pattern here: > > /* abs/negative simplifications moved from fold_cond_expr_with_comparison, > Need to handle (A - B) case as fold_cond_expr_with_comparison does. > Need to handle UN* comparisons. > ... > ... > > Sees IL that has the 0.0 propagated. > > Instead of: > > [local count: 1073741824]: > if (A_2(D) == 0.0) > goto ; [34.00%] > else > goto ; [66.00%] > > [local count: 708669601]: > _3 = -A_2(D); > > [local count: 1073741824]: > # _1 = PHI > > It now sees: > > [local count: 1073741824]: > # _1 = PHI <0.0(2), _3(3)> > > which it leaves untouched, causing the if conditional to survive. > > Adding a variant to the pattern that for real_zerop fixes the problem. > > I am a match.pd weenie, and am avoiding touching more patterns that > may also benefit from handling real constants. So please use simple > words if what I'm doing isn't correct ;-). > > I did not include a testcase, as it's just phi-opt-24.c which will get > triggered when I commit the frange with endpoints work. > > Tested on x86-64 & ppc64le Linux. > > OK? > > gcc/ChangeLog: > > * match.pd ((cmp @0 zerop) real_zerop (negate@1 @0)): Add variant > for real zero. > --- > gcc/match.pd | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/gcc/match.pd b/gcc/match.pd > index 1bb936fc401..5bdea300f94 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -4803,6 +4803,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (cnd (cmp @0 zerop) @0 (negate@1 @0)) > (if (!HONOR_SIGNED_ZEROS (type)) > @1)) > + (simplify > + (cnd (cmp @0 zerop) real_zerop (negate@1 @0)) > + (if (!HONOR_SIGNED_ZEROS (type)) > + @1)) > (simplify > (cnd (cmp @0 zerop) integer_zerop (negate@1 @0)) > (if (!HONOR_SIGNED_ZEROS (type)) Looking at zerop: bool zerop (const_tree expr) { return (integer_zerop (expr) || real_zerop (expr) || fixed_zerop (expr)); } your patch is equivalent to changing the integer_zerop one to use zerop? (well, with the exception of also covering fixed_zerop). OK if doing it that way. Thanks, Richard. > -- > 2.37.1 >