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 7AE403854563 for ; Thu, 17 Nov 2022 17:44:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7AE403854563 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=1668707098; 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=/k+ZVrUo1ort5tJrjbDisuUYK+Ws4cNiE6md/4UuX7E=; b=QJbu9Gr19jg7i64dkFlpS/0dzianEZTBVRydbM0tGAdhlSVcI93rrguHcmDqsLrWo8ZT+z U/83fgdTyEwaBZDtxRq5KGsVl43N31HXjSlFcA5kodLvqAkD0A9aVdnEgLXpvlSzyHKvQh VDRGFPKbRnstxKJ7N9lups8Nfx27WT8= 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-110-iqGUgqxMNu-lIcS_e9FJcw-1; Thu, 17 Nov 2022 12:44:56 -0500 X-MC-Unique: iqGUgqxMNu-lIcS_e9FJcw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 64ADB85A59D for ; Thu, 17 Nov 2022 17:44:56 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.101]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1633492B04; Thu, 17 Nov 2022 17:44:55 +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 2AHHip4w825348 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 17 Nov 2022 18:44:51 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 2AHHipOf825347; Thu, 17 Nov 2022 18:44:51 +0100 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] [PR tree-optimization/107732] [range-ops] Handle attempt to abs() negatives. Date: Thu, 17 Nov 2022 18:44:49 +0100 Message-Id: <20221117174449.825329-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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.4 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 threader is creating a scenario where we are trying to solve: [NEGATIVES] = abs(x) While solving this we have an intermediate value of UNDEFINED because we have no positive numbers. But then we try to union the negative pair to the final result by querying the bounds. Since neither UNDEFINED nor NAN have bounds, they need to be specially handled. PR tree-optimization/107732 gcc/ChangeLog: * range-op-float.cc (foperator_abs::op1_range): Early exit when result is undefined. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107732.c: New test. --- gcc/range-op-float.cc | 2 +- gcc/testsuite/gcc.dg/tree-ssa/pr107732.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107732.c diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc index adb0cbaa6d5..ee88511eba0 100644 --- a/gcc/range-op-float.cc +++ b/gcc/range-op-float.cc @@ -1407,7 +1407,7 @@ foperator_abs::op1_range (frange &r, tree type, neg_nan.set_nan (type, true); r.union_ (neg_nan); } - if (r.known_isnan ()) + if (r.known_isnan () || r.undefined_p ()) return true; // Then add the negative of each pair: // ABS(op1) = [5,20] would yield op1 => [-20,-5][5,20]. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107732.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107732.c new file mode 100644 index 00000000000..b216f38db0e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107732.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2" } + +double sqrt(double); +double a, b, c; +void d() { + for (;;) { + c = __builtin_fabs(a); + sqrt(c); + if (a) + a = b; + } +} -- 2.38.1