From patchwork Wed Jan 25 18:05:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1731784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Uff09FPL; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P2Bb51s9jz23gM for ; Thu, 26 Jan 2023 05:05:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FFE83858C36 for ; Wed, 25 Jan 2023 18:05:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FFE83858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674669933; bh=CbC3jsQXCoQ7ES+yRtRmgxUi67pfjSfqPg0bvCuWmBU=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Uff09FPLWKlrQcFjw2bwg8GQiu3pJi2Ivj8diD+oyrFnb0nGflXQD4e5hWtmgsHK/ QwVh5pLAlzAqOnLYn4yQEWEYQ5CQ3ccrdkRpifxr4ulywxQXcaRfXWm59UQUiC5aAc a36STiojPRpWr123Iw/P+tQ4g4/DY1lBg9QUQGMk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1BC453858D28 for ; Wed, 25 Jan 2023 18:05:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BC453858D28 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-475-X0BeZsh1Mca0gAhywii9XQ-1; Wed, 25 Jan 2023 13:05:12 -0500 X-MC-Unique: X0BeZsh1Mca0gAhywii9XQ-1 Received: by mail-qv1-f72.google.com with SMTP id ep11-20020a05621418eb00b0053776e632b9so988160qvb.16 for ; Wed, 25 Jan 2023 10:05:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=T4UkOY++y+ONhlYpHHKNttKOU7VER/210Lkj3HIjO1Q=; b=f+nh7g7qthgG9S8uXeFyDlvcqPocpRSkT6ptZME0lWuJb3Gn8v+fTimhcJWDEZuI0l HzjI6NCVKAwySBW0Brgx8J+XwmCdb+/qhXuCQS5zPT1L200y/E4QMF74vm6fYaep0wQj wdQ4QmomEufb1j3LStJTr+iGT/eCpKq21mjfYyHA0clkrmJFCC4Ee13VgITkVjbYwfwN xRAaeZcVRQobScquzJCPrJmwT1k0Ps02n5UPxFD22U8A+3+LyLEJEmW7yzqYjSMN9Y2/ XQ7z8Xh1RK3Kdlq9uMccOOqN9dsewulXVwV1iYC9/SKO3SnHGcTQfkRi+GdEOXlwBiyZ w7gQ== X-Gm-Message-State: AFqh2kr9K6gOIzSGb9+S0ese1tuMss6DnnuTLdRhMOrBK+5RxxLRAcdn y1Db+7l8jPEhpSHfVfywwnZYMRZj2EV4QWSmfC3TTnCB+xf4yBoo8fy3uLkA6vLHd1mKCcJfZeu gKWhq/ZXoHIXziA5970BeLKQtkXr3aYbGynoPo/1lESVA4hJbCb+itGLWk6u9ixhQ7vBnWQ== X-Received: by 2002:ac8:730a:0:b0:3b6:3a71:e939 with SMTP id x10-20020ac8730a000000b003b63a71e939mr49639032qto.7.1674669911643; Wed, 25 Jan 2023 10:05:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXvskC6TIVZsHF4f9sU3w7+VmCqrLgKHomtYEpGbKVg335fvr2tyw+jbDliNuEzsp4JjSlx9ng== X-Received: by 2002:ac8:730a:0:b0:3b6:3a71:e939 with SMTP id x10-20020ac8730a000000b003b63a71e939mr49638993qto.7.1674669911335; Wed, 25 Jan 2023 10:05:11 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::fa90? ([2607:fea8:a263:f600::fa90]) by smtp.gmail.com with ESMTPSA id o3-20020ac80243000000b003a6a19ee4f0sm3740522qtg.33.2023.01.25.10.05.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Jan 2023 10:05:10 -0800 (PST) Message-ID: <0780922f-99b5-96fc-b921-9e00652f9741@redhat.com> Date: Wed, 25 Jan 2023 13:05:09 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: gcc-patches Cc: Jakub Jelinek , "hernandez, aldy" , Richard Biener Subject: [PATCH] PR tree-optimization/108447 - Do not try to logical fold floating point relations. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This boils down to a single place where we are trying to do things with relations in ranger that are simply not safe when we need to honor NANs. I think we can avoid all the other shuffling of relations, and simply not perform this optimization when it comes to floats. The case the routine handles is: c_2 = a_6 > b_7 c_3 = a_6 < b_7 c_4 = c_2 && c_3 c_2 and c_3 can never be true at the same time, Therefore c_4 can always resolve to false based purely on the relations. Range-ops is unable to do this optimization directly as it requires examining things from outside the statement, and is not easily communicated a simple relation to operator_logical_and. This routine proceeds to look at the definitions of c_2 and c_3, tries to determine if there are common operands, and queries for any relations between them.   If it turns out there is something, depending on whether its && or || , we use intersection or union to determine if the result of the logical operation can be folded.  If HONOR_NANS is true for the float type, then we cannot do this optimization, and bail early. At this point I do not think we need to do any of the other things proposed to relations, so we don't need either of the other 2 patches this release. Bootstraps on x86_64-pc-linux-gnu with no regressions.  OK for trunk? Andrew commit 0b080e9579045dd054e9b3289d123d6b66567e3e Author: Andrew MacLeod Date: Wed Jan 25 11:13:23 2023 -0500 Do not try to logical fold floating point relations. relation_fold_and_or looks for relations among common operands feeding logical ands and ors. With no knowledge of NANs, it should not attempt to do this with floating point ssa names. PR tree-optimization/108447 gcc/ * gimple-range-fold.cc (old_using_range::relation_fold_and_or): Do not attempt to fold HONOR_NAN types. gcc/testsuite/ * gcc.dg/pr108447.c: New. diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 91eb6298254..9c5359a3fc6 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1039,6 +1039,9 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, if (!ssa1_dep1 || !ssa1_dep2 || !ssa2_dep1 || !ssa2_dep2) return; + if (HONOR_NANS (TREE_TYPE (ssa1_dep1))) + return; + // Make sure they are the same dependencies, and detect the order of the // relationship. bool reverse_op2 = true; diff --git a/gcc/testsuite/gcc.dg/pr108447.c b/gcc/testsuite/gcc.dg/pr108447.c new file mode 100644 index 00000000000..cfbaba6d0aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108447.c @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +__attribute__((noipa)) int +foo (float x, float y) +{ + _Bool cmp1 = x <= y; + _Bool cmp2 = x >= y; + if (cmp1 && cmp2) + return 1; + else if (!cmp1 && !cmp2) + return -1; + return 0; +} + +int +main () +{ + if (foo (0.0f, __builtin_nanf ("")) != -1) + __builtin_abort (); + if (foo (__builtin_nanf (""), -42.0f) != -1) + __builtin_abort (); + if (foo (0.0f, -0.0f) != 1) + __builtin_abort (); + if (foo (42.0f, 42.0f) != 1) + __builtin_abort (); + if (foo (42.0f, -0.0f) != 0) + __builtin_abort (); + if (foo (0.0f, -42.0f) != 0) + __builtin_abort (); + return 0; +} +