From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 2FC533858D37 for ; Tue, 1 Nov 2022 18:25:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2FC533858D37 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=1667327145; 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=msipgsJ5CwzFMTI4EjTl2fK+elKXvImXXlE/jyLujio=; b=TA9VJ/n5sfcFaLhaHrjsVZpRt6RgAvjG2lp/wB3QFxjOSXQXkN7ANnzfgd+4MNbI0j13MR 2Lcj5lgB6u+UokeJiJAQwCFOKjUWIqUAKE+KBlj8fT/RPZRktGEwvo+l8uIR8a6Qe/9xoa +vZ7rJOKJ/dFXH6lvPo8v4NBsa6UmC4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.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-193-VMu5AROwO-m-PUbXPGZycA-1; Tue, 01 Nov 2022 14:25:44 -0400 X-MC-Unique: VMu5AROwO-m-PUbXPGZycA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7506E29AB416 for ; Tue, 1 Nov 2022 18:25:44 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.166]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1024042220; Tue, 1 Nov 2022 18:25:43 +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 2A1IPfZk050433 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 1 Nov 2022 19:25:41 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 2A1IPfPx050432; Tue, 1 Nov 2022 19:25:41 +0100 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] [PR tree-optimization/107490] Handle NANs in op[12]_range. Date: Tue, 1 Nov 2022 19:25:37 +0100 Message-Id: <20221101182537.50407-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.3 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 List-Id: None of the build_ functions in range-op handle NANs. This is by design in order to force us to handle NANs specially, because "x relop NAN" makes no sense. This patch fixes a handful of op[12]_range entries that weren't handling NANs. PR tree-optimization/107490 gcc/ChangeLog: * range-op-float.cc (foperator_unordered_lt::op1_range): Handle NANs. (foperator_unordered_lt::op2_range): Same. (foperator_unordered_le::op1_range): Same. (foperator_unordered_le::op2_range): Same. (foperator_unordered_gt::op1_range): Same. (foperator_unordered_gt::op2_range): Same. (foperator_unordered_ge::op1_range): Same. (foperator_unordered_ge::op2_range): Same. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107490.c: New test. --- gcc/range-op-float.cc | 40 +++++++++++++++++++----- gcc/testsuite/gcc.dg/tree-ssa/pr107490.c | 28 +++++++++++++++++ 2 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107490.c diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 04208c88dd1..a1f372997bf 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1332,7 +1332,10 @@ foperator_unordered_lt::op1_range (frange &r, tree type, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_lt (r, type, op2); + if (op2.known_isnan ()) + r.set_varying (type); + else + build_lt (r, type, op2); break; case BRS_FALSE: @@ -1359,7 +1362,10 @@ foperator_unordered_lt::op2_range (frange &r, tree type, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_gt (r, type, op1); + if (op1.known_isnan ()) + r.set_varying (type); + else + build_gt (r, type, op1); break; case BRS_FALSE: @@ -1420,7 +1426,10 @@ foperator_unordered_le::op1_range (frange &r, tree type, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_le (r, type, op2); + if (op2.known_isnan ()) + r.set_varying (type); + else + build_le (r, type, op2); break; case BRS_FALSE: @@ -1448,7 +1457,10 @@ foperator_unordered_le::op2_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_ge (r, type, op1); + if (op1.known_isnan ()) + r.set_varying (type); + else + build_ge (r, type, op1); break; case BRS_FALSE: @@ -1511,7 +1523,10 @@ foperator_unordered_gt::op1_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_gt (r, type, op2); + if (op2.known_isnan ()) + r.set_varying (type); + else + build_gt (r, type, op2); break; case BRS_FALSE: @@ -1539,7 +1554,10 @@ foperator_unordered_gt::op2_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_lt (r, type, op1); + if (op1.known_isnan ()) + r.set_varying (type); + else + build_lt (r, type, op1); break; case BRS_FALSE: @@ -1602,7 +1620,10 @@ foperator_unordered_ge::op1_range (frange &r, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_ge (r, type, op2); + if (op2.known_isnan ()) + r.set_varying (type); + else + build_ge (r, type, op2); break; case BRS_FALSE: @@ -1629,7 +1650,10 @@ foperator_unordered_ge::op2_range (frange &r, tree type, switch (get_bool_state (r, lhs, type)) { case BRS_TRUE: - build_le (r, type, op1); + if (op1.known_isnan ()) + r.set_varying (type); + else + build_le (r, type, op1); break; case BRS_FALSE: diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107490.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107490.c new file mode 100644 index 00000000000..87c7f0aacdd --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107490.c @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-Os -fno-trapping-math -w" } + +extern void abort (void); + +#define MIN2(a,b) (((a)<(b)) ? (a) : (b)) +#define MAX2(a,b) (((a)>(b)) ? (a) : (b)) + +double p[2] = { 4.f, 5.f }; + +int main() +{ + long j; + double R, n, x; + n = 1.e300f; + x = -1.e300f; + for( j=0; j < 2; j++ ) + { + x = MAX2(x,p[j]); + n = MIN2(n,p[j]); + } + R = x-n; + + if( R < 0.1 ) + abort (); + + return 0; +} -- 2.38.1