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.133.124]) by sourceware.org (Postfix) with ESMTPS id BD0BB3858412 for ; Mon, 24 Oct 2022 13:33:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD0BB3858412 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=1666618407; 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=BiP0VnpR4sVd19yHKRnvnG3I3U/tvpTp21MhI2Qrn2I=; b=Ob+LGimDLa0E23b1em6rtptC21Ix2OCcJ+cs7rHVt+FRGly5gGQ171HX/qf5IoE5a+k0Ou Tkp8fb3YWFnShawGrwDfAnzehngEMc1SmTWVLWyZe3zzE/+SEul9mZEyh3VJ6q9kcAbyow t4w9aIPU4k2hos3hhK+wJUAWi/3tVJs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-322-jVx9bilMM8-9adIiUd1DEQ-1; Mon, 24 Oct 2022 09:33:26 -0400 X-MC-Unique: jVx9bilMM8-9adIiUd1DEQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B271C8279A6 for ; Mon, 24 Oct 2022 13:33:25 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.177]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E9CE1121330; Mon, 24 Oct 2022 13:33:22 +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 29ODXJtW033070 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 24 Oct 2022 15:33:19 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 29ODXJkZ033069; Mon, 24 Oct 2022 15:33:19 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [PATCH] [PR tree-optimization/107355] Handle NANs in abs range-op entry. Date: Mon, 24 Oct 2022 15:33:16 +0200 Message-Id: <20221024133316.33026-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=-11.6 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: The problem here is that the threader is coming up with a path where the only valid result is a NAN. When the abs op1_range entry is trying to add the negative posibility, it attempts to get the bounds of the working range. NANs don't have bounds so they need to be special cased. PR tree-optimization/107355 gcc/ChangeLog: * range-op-float.cc (foperator_abs::op1_range): Handle NAN. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107355.c: New test. --- gcc/range-op-float.cc | 9 +++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr107355.c | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107355.c diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index 8777bc70d71..04208c88dd1 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1269,6 +1269,15 @@ foperator_abs::op1_range (frange &r, tree type, positives.update_nan (/*sign=*/false); positives.intersect (lhs); r = positives; + // Add -NAN if relevant. + if (r.maybe_isnan ()) + { + frange neg_nan; + neg_nan.set_nan (type, true); + r.union_ (neg_nan); + } + if (r.known_isnan ()) + return true; // Then add the negative of each pair: // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20]. r.union_ (frange (type, diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c new file mode 100644 index 00000000000..40796344bfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107355.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2 -fno-guess-branch-probability -fsanitize=float-cast-overflow --param=max-jump-thread-duplication-stmts=240" } + +float f; + +void +foo (double d) +{ + (char) f; + long l = __builtin_fabs (d); + (char) f; + (long) d; +} -- 2.37.3