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: 48241 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp411915wrn; Wed, 25 Jan 2023 10:05:59 -0800 (PST) X-Google-Smtp-Source: AK7set98w5cPXtZHS31tqG8/3A9YrhVnjvsMA9uRxgRxOoZnX+08o6m0X39YFpuuaClFEiSjLlRm X-Received: by 2002:aa7:db4c:0:b0:49f:28ff:124e with SMTP id n12-20020aa7db4c000000b0049f28ff124emr8508381edt.35.1674669958962; Wed, 25 Jan 2023 10:05:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674669958; cv=none; d=google.com; s=arc-20160816; b=MdfGJwfGbmBa3037FlmpIiTKtO2KIuSmyy1ednfEwk+JB7rWsn+VUadB0DzooVaHpe TGzaHFhRyasOw61UJ+b/uPoypTROarfomlv/B/jADAaojr18Q2ISxKZRRHEzhFAbucvv aFs/yw/C3OAUzVGNVVMFJfkUEt3EOo2PZIeRdMiVjGsBHVr03wjo+p9p4Kr+AwlY3Ax/ G7jjArenn+ut4oi0l8UIvjMs1MCxyT7Qe39kbgndbGNyZpuPk9+h4Nd2qhDOokTM5cbP hDDbCliLnPM2MfIaAdxKJ5yEw4jyJvKPp7+cy1ox8I8K3+vkbNAsey1JI0wLaRqVAPtA 1MCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=CbC3jsQXCoQ7ES+yRtRmgxUi67pfjSfqPg0bvCuWmBU=; b=OKvLa1uCFCA9xVQT+R7ZSbVsRgxkFbevhz36UuD3BbRvp9ssaXeIzTbbU0/Pllr/0C xxOgmm4VpWyYryQK3H915GHW+iHbR/nSdGbmBKdtWGk4vZaclndhp3sqVnY5Km28NnBF UXegiVcqM5K5cITJ8hkx7xvkZtnypRqlQms0T4599VQDE8EKi9AbLfu+7KdXkmQ6DOAx zw/LoCybv584Cj+rMnKyiGR0BDD/1IA5ycR53Z56DYbYsnk4oJmugVEih32Zqj6Tvps2 fxqTKkGkzTf8MDdnjRcmyMLE0Ia037vQn+hXGT9IHfycmOoKUYKpFlLq5QihTlTHSuVF G2yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nD1GV0Kb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id co22-20020a0564020c1600b0049e078ff8c8si6300714edb.333.2023.01.25.10.05.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 10:05:58 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nD1GV0Kb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 617A03858C39 for ; Wed, 25 Jan 2023 18:05:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 617A03858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674669957; 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=nD1GV0KbhSohzqcbXK59bqVdddmszNIpyj9+gGdtsR57l3m+2w3X2GEmNLS56tur2 hP4CCc3jK/oRbPoUIY3g7ImZiejXfZQZcjuVOYj/DneVwDSvSS9P3nVoARTjexCgnn Wtd44BsJ7PiX+Xr5WXROdrHtrVip3riDCUHgDAzA= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756018726737187358?= X-GMAIL-MSGID: =?utf-8?q?1756018726737187358?= 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; +} +