From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id C2F14385C335; Tue, 30 Aug 2022 09:27:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2F14385C335 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661851662; bh=wNSIRg6BMB27H5muD6Z/ChJvVR9eUhCypj1a4lsyHow=; h=From:To:Subject:Date:From; b=JImLAMigT58RVqkc1dSk7W0w14++PpFlay10PF5TcOkoP/j21gf2pi6yoyYFXZalM nzGISYfu9GBYICtUH9YyNfjY4GV3iOrgV6Ly2uFDoPca+236RgPG3KC0LAJgZDf1A0 5tEfMl5KXKx9XYv8Jk5FjjwUvpKceQPtRrHbjiV0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2265] A == 0 ? A : -A same as -A (when A is 0.0) X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 34ad7155fe2a4a5d0b1815c79ce8b2af4c772c9e X-Git-Newrev: df8fe4adb0721ab0e4486bc58482b501fe06287d Message-Id: <20220830092742.C2F14385C335@sourceware.org> Date: Tue, 30 Aug 2022 09:27:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:df8fe4adb0721ab0e4486bc58482b501fe06287d commit r13-2265-gdf8fe4adb0721ab0e4486bc58482b501fe06287d Author: Aldy Hernandez Date: Mon Aug 29 17:52:20 2022 +0200 A == 0 ? A : -A same as -A (when A is 0.0) 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. Changing integger_zerop to zerop fixes the problem. 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. gcc/ChangeLog: * match.pd ((cmp @0 zerop) real_zerop (negate@1 @0)): Add variant for real zero. Diff: --- gcc/match.pd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/match.pd b/gcc/match.pd index 1bb936fc401..f5fec634279 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4804,7 +4804,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (!HONOR_SIGNED_ZEROS (type)) @1)) (simplify - (cnd (cmp @0 zerop) integer_zerop (negate@1 @0)) + (cnd (cmp @0 zerop) zerop (negate@1 @0)) (if (!HONOR_SIGNED_ZEROS (type)) @1)) )