From patchwork Wed Sep 20 15:12:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1837325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OtBF45Tv; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RrMTz6xwNz1ynZ for ; Thu, 21 Sep 2023 01:12:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6823F3858407 for ; Wed, 20 Sep 2023 15:12:53 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 105233858D39 for ; Wed, 20 Sep 2023 15:12:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 105233858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695222761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jm7X83eRCGvtcnsTBRfdGcYjzlqg7B7BPS2GgUPn7Oo=; b=OtBF45TvhfGjm4K5AULSXimXYtF5oHZQH3GwNaMjSfhIkUoGGPrLaTxxh65/kK+w8fZvBq ElRLeXRG/wq7jkLXihX06S14fbmFyq/USrYgVmMT1KiGmjWPAc9o3S10hzm9vdNvhuM7Hn Qel7JOJN7kLqV7y7RJdqzxrwm/Akmrg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-660-fuf_xibRN42fk-OwGaPVqw-1; Wed, 20 Sep 2023 11:12:40 -0400 X-MC-Unique: fuf_xibRN42fk-OwGaPVqw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BDB8D3801EF0 for ; Wed, 20 Sep 2023 15:12:39 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.22.34.141]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DDC3C15BB8; Wed, 20 Sep 2023 15:12:39 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 38KFCcmO1015355 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 20 Sep 2023 11:12:38 -0400 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 38KFCcWV1015354; Wed, 20 Sep 2023 11:12:38 -0400 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [PATCH] [frange] Remove special casing from unordered operators. Date: Wed, 20 Sep 2023 11:12:21 -0400 Message-ID: <20230920151234.1015328-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.1 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_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org In coming up with testcases for the unordered folders, I realized that we were already handling them correctly, even in the absence of my work in this area lately. All of the unordered fold_range() methods try to fold with the ordered variants first, and if they return TRUE, we are guaranteed to be able to fold, even in the presence of NANs. For example: if (x_5 >= y_8) if (x_5 __UNLE y_8) On the true side of the first conditional we know that either x_5 < y_8 or that one or more operands is a NAN. Since UNLE_EXPR returns true for precisely this scenario, we can fold as true. This is handled in the fold_range() methods as follows: if (!range_op_handler (LE_EXPR).fold_range (r, type, op1_no_nan, op2_no_nan, trio)) return false; // The result is the same as the ordered version when the // comparison is true or when the operands cannot be NANs. if (!maybe_isnan (op1, op2) || r == range_true (type)) return true; This code has been there since the last release, and makes the special casing I am deleting obsolete. I have added tests to make sure we keep track of this behavior. I will commit this pending tests. gcc/ChangeLog: * range-op-float.cc (foperator_unordered_ge::fold_range): Remove special casing. (foperator_unordered_gt::fold_range): Same. (foperator_unordered_lt::fold_range): Same. (foperator_unordered_le::fold_range): Same. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/vrp-float-relations-5.c: New test. * gcc.dg/tree-ssa/vrp-float-relations-6.c: New test. --- gcc/range-op-float.cc | 20 ++----- .../gcc.dg/tree-ssa/vrp-float-relations-5.c | 54 +++++++++++++++++++ .../gcc.dg/tree-ssa/vrp-float-relations-6.c | 54 +++++++++++++++++++ 3 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-5.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-6.c diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 399deee5d8a..0951bd385a9 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1644,10 +1644,7 @@ public: const frange &op1, const frange &op2, relation_trio trio = TRIO_VARYING) const final override { - relation_kind rel = trio.op1_op2 (); - - if (op1.known_isnan () || op2.known_isnan () - || rel == VREL_LT) + if (op1.known_isnan () || op2.known_isnan ()) { r = range_true (type); return true; @@ -1759,10 +1756,7 @@ public: const frange &op1, const frange &op2, relation_trio trio = TRIO_VARYING) const final override { - relation_kind rel = trio.op1_op2 (); - - if (op1.known_isnan () || op2.known_isnan () - || rel == VREL_LE) + if (op1.known_isnan () || op2.known_isnan ()) { r = range_true (type); return true; @@ -1870,10 +1864,7 @@ public: const frange &op1, const frange &op2, relation_trio trio = TRIO_VARYING) const final override { - relation_kind rel = trio.op1_op2 (); - - if (op1.known_isnan () || op2.known_isnan () - || rel == VREL_GT) + if (op1.known_isnan () || op2.known_isnan ()) { r = range_true (type); return true; @@ -1985,10 +1976,7 @@ public: const frange &op1, const frange &op2, relation_trio trio = TRIO_VARYING) const final override { - relation_kind rel = trio.op1_op2 (); - - if (op1.known_isnan () || op2.known_isnan () - || rel == VREL_GE) + if (op1.known_isnan () || op2.known_isnan ()) { r = range_true (type); return true; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-5.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-5.c new file mode 100644 index 00000000000..2bd06c6fbf7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-5.c @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-O2 -fgimple -fdump-tree-evrp" } + +void link_error(); + +void __GIMPLE (ssa,startwith("evrp")) +foo1 (float x, float y) +{ + __BB(2): + if (x_4(D) <= y_5(D)) + goto __BB5; + else + goto __BB3; + + __BB(3): + // Relation at this point is VREL_GT. + if (x_4(D) __UNGE y_5(D)) + goto __BB5; + else + goto __BB4; + + __BB(4): + link_error (); + goto __BB5; + + __BB(5): + return; +} + +void __GIMPLE (ssa,startwith("evrp")) +foo2 (float x, float y) +{ + __BB(2): + if (x_4(D) <= y_5(D)) + goto __BB5; + else + goto __BB3; + + __BB(3): + // Relation at this point is VREL_GT. + if (x_4(D) __UNGT y_5(D)) + goto __BB5; + else + goto __BB4; + + __BB(4): + link_error (); + goto __BB5; + + __BB(5): + return; +} + +// { dg-final { scan-tree-dump-not "link_error" "evrp" } } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-6.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-6.c new file mode 100644 index 00000000000..a75ae5d64ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-relations-6.c @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-O2 -fgimple -fdump-tree-evrp" } + +void link_error(); + +void __GIMPLE (ssa,startwith("evrp")) +foo1 (float x, float y) +{ + __BB(2): + if (x_4(D) >= y_5(D)) + goto __BB5; + else + goto __BB3; + + __BB(3): + // Relation at this point is VREL_LT. + if (x_4(D) __UNLT y_5(D)) + goto __BB5; + else + goto __BB4; + + __BB(4): + link_error (); + goto __BB5; + + __BB(5): + return; +} + +void __GIMPLE (ssa,startwith("evrp")) +foo2 (float x, float y) +{ + __BB(2): + if (x_4(D) >= y_5(D)) + goto __BB5; + else + goto __BB3; + + __BB(3): + // Relation at this point is VREL_LT. + if (x_4(D) __UNLE y_5(D)) + goto __BB5; + else + goto __BB4; + + __BB(4): + link_error (); + goto __BB5; + + __BB(5): + return; +} + +// { dg-final { scan-tree-dump-not "link_error" "evrp" } }