From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id D30FA3858D28 for ; Tue, 15 Mar 2022 07:29:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D30FA3858D28 Received: by mail-ed1-x52e.google.com with SMTP id y8so17937455edl.9 for ; Tue, 15 Mar 2022 00:29:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=duw2OEK5DoEOaMob3ow+Qsg3y36aD84gb7C70NzW4rM=; b=cVffyivuElj50sb0HYkW8Q6dSWwBzD0DvXYjhmqvmFJJ2fmQTZ/7YGrMJcfbXzSSH0 LWl7hxJXm91sA2wpsnctMWJZ6RVGy/dqLTw+08mmKZ2+vubKHvZIi23Ixqjx8xf2vYfj yLc8YwqjHpVgCmUZThz08XCycRzEL5FD2RTnMtbGkS+7QBvezBabW9Brwnykyi3263ek ubqlx0kN8Oewd7TANYXN3eRYvIEsglWc/z/Hp5lyZq13oq8gb3MlilyZr+A97lGAx7G2 ny0L6yFGPpZgtYKm6Qq47gzuEEwbUfELGFuVfkFungxRWsHG9zZmGQyVtJ6VtN+vAaRQ XEmw== X-Gm-Message-State: AOAM530PWrTUtQJJ7e7lDjHcqP7b1owLt35ZwNH6X8IfeIFP3eOMzLuc rvQVbmnjaAzAQ8swGRb8d7UG4HY53nt0ramUMi+MElHS X-Google-Smtp-Source: ABdhPJy/cqA+77w0vF9z3F1o2bhB80ciPGmUzql7NcAUbV0EG0i8GrldONsNzk8rhutVHx9vQgp00D7nODlxmkb+YFI= X-Received: by 2002:a05:6402:7cb:b0:415:f059:c817 with SMTP id u11-20020a05640207cb00b00415f059c817mr23794310edy.364.1647329368289; Tue, 15 Mar 2022 00:29:28 -0700 (PDT) MIME-Version: 1.0 References: <001c01d837d9$4c8bf060$e5a3d120$@nextmovesoftware.com> In-Reply-To: <001c01d837d9$4c8bf060$e5a3d120$@nextmovesoftware.com> From: Richard Biener Date: Tue, 15 Mar 2022 08:29:17 +0100 Message-ID: Subject: Re: [PATCH] Ignore (possible) signed zeros in operands of FP comparisons. To: Roger Sayle Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Mar 2022 07:29:31 -0000 On Mon, Mar 14, 2022 at 8:26 PM Roger Sayle wrote: > > > I've been wondering about the possible performance/missed-optimization > impact of my patch for PR middle-end/98420 and similar IEEE correctness > fixes that disable constant folding optimizations when worrying about -0.0. > In the common situation where the floating point result is used by a > FP comparison, there's no distinction between +0.0 and -0.0, so some > HONOR_SIGNED_ZEROS optimizations that we'd usually disable, are safe. > > Consider the following interesting example: > > int foo(int x, double y) { > return (x * 0.0) < y; > } > > Although we know that x (when converted to double) can't be NaN or Inf, > we still worry that for negative values of x that (x * 0.0) may be -0.0 > and so perform the multiplication at run-time. But in this case, the > result of the comparison (-0.0 < y) will be exactly the same as (+0.0 < y) > for any y, hence the above may be safely constant folded to "0.0 < y" > avoiding the multiplication at run-time. > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check with no new failures, and allows GCC to continue to > optimize cases that we optimized in GCC 11 (without regard to correctness). > Ok for mainline? Isn't that something that gimple-ssa-backprop.c is designed to handle? I wonder if you can see whether the signed zero speciality can be retrofitted there? It currently tracks "sign does not matter", so possibly another state, "sign of zero does not matter" could be introduced there. Thanks, Richard. > > 2022-03-14 Roger Sayle > > gcc/ChangeLog > * match.pd (X CMP (Y-Y) -> X CMP 0.0): New transformation. > (X CMP (Y * 0.0) -> X CMP 0.0): Likewise. > (X CMP X -> true): Test tree_expr_maybe_nan_p instead of HONOR_NANS. > (X LTGT X -> false): Enable if X is not tree_expr_maybe_nan_p, as > this can't trap/signal. > > gcc/testsuite/ChangeLog > * gcc.dg/fold-compare-9.c: New test case. > > > Thanks in advance, > Roger > -- >