From patchwork Wed Oct 11 20:48:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1846991 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=Z1pCsIeq; 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 4S5PxF06tfz1yqZ for ; Thu, 12 Oct 2023 07:48:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C31273856DE8 for ; Wed, 11 Oct 2023 20:48:12 +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 ADD433858C3A for ; Wed, 11 Oct 2023 20:48:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADD433858C3A 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=1697057281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=2TilkzaSk8vAtLncOY1KMixswBG13rzyT2SNgTlEzMs=; b=Z1pCsIeqN2fxxNNiEkFIhC0OuUuiqz2fCfrt+Ux2THKXdkDpJmm8xWeoy2nXU8vJdCdFE4 sCSs4N/7onCKF1RPDCnguvpOfaNmHc5yoeqKOiz0zRwdoQ3jS9Z0n/gZ7xb46bvSQm+hxa s339r6kSHW10C4M4XcUC6yyx6W5Kk6E= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156--3ZuXyojNXu6f__j_FnkZQ-1; Wed, 11 Oct 2023 16:47:59 -0400 X-MC-Unique: -3ZuXyojNXu6f__j_FnkZQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7742eeceeacso26159285a.3 for ; Wed, 11 Oct 2023 13:47:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697057278; x=1697662078; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tkcBc432XLGYTO73Ayqn4V/IdO8nyXefNntGC55uYcY=; b=a/M7suKe/IWj3KogGefwFjX+MBXmKKtePpSomx3NpXo2hCulP4iTaQzdyFSqIR8KM7 iO+9WxenMJujDUjFXjkcPNEeXxAUsKibxV1MH95kzxpfkTG8CLnUfbZiMPdMHnFQ1MFd RmuNdw0HXhekhTnf5k32LkKuZQfvHqI/Pz0QUN/huN7rdU+o+TmkNkSyZEkUbovDLRbn 7md+5Jfspjux+x72upiAGSr21iLziEEHB+fxaoE4Rt2OLMe8yOAsubatTUqy4ozEX2gl chBWuxHfxGLCQu9fxCDZu+NH9t92ZM/uYfkA62W41y8HfwuPa+9OTFLuqSo/55yj5TbY bNQA== X-Gm-Message-State: AOJu0YzZz/BwM7K68Ydz4HopUh6cp2xhdsFNnJGvej4PrQOOqGRTVNgA bJZ/uFmRdf3BVfVOuDz1pIQQLMIvsFpN36B8r9KGdx7/3pMKqVk2nH/EyBgNF3OHjCRVtpfSo2E wKHMUxdjjEqNbFCGaQ0KnHCSOaxLn+9orZABczPmOEMd45sq3WivokjrppS5Cq/YqZADta1UgXX g4Wg== X-Received: by 2002:a05:620a:1990:b0:775:72b7:9300 with SMTP id bm16-20020a05620a199000b0077572b79300mr28123114qkb.20.1697057278761; Wed, 11 Oct 2023 13:47:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEuNxWdaZsvV2UYj5v4U1rMBLmDZua8YkWP9X4ss3toEPDHZ3Vr5fp/2CnOxA7oSvAYA45yw== X-Received: by 2002:a05:620a:1990:b0:775:72b7:9300 with SMTP id bm16-20020a05620a199000b0077572b79300mr28123102qkb.20.1697057278413; Wed, 11 Oct 2023 13:47:58 -0700 (PDT) Received: from [192.168.0.174] ([104.219.124.252]) by smtp.gmail.com with ESMTPSA id c28-20020a05620a135c00b0076f21383b6csm5485135qkl.112.2023.10.11.13.47.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 13:47:57 -0700 (PDT) Message-ID: Date: Wed, 11 Oct 2023 16:48:02 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: gcc-patches From: Andrew MacLeod Subject: [COMMITTED][GCC13] PR tree-optimization/111694 - Ensure float equivalences include + and - zero. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.8 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, 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 Similar patch which was checked into trunk last week.   slight tweak needed as dconstm0 was not exported in gcc 13, otherwise functionally the same Bootstrapped on x86_64-pc-linux-gnu.  pushed. Andrew commit f0efc4b25cba1bd35b08b7dfbab0f8fc81b55c66 Author: Andrew MacLeod Date: Mon Oct 9 13:40:15 2023 -0400 Ensure float equivalences include + and - zero. A floating point equivalence may not properly reflect both signs of zero, so be pessimsitic and ensure both signs are included. PR tree-optimization/111694 gcc/ * gimple-range-cache.cc (ranger_cache::fill_block_cache): Adjust equivalence range. * value-relation.cc (adjust_equivalence_range): New. * value-relation.h (adjust_equivalence_range): New prototype. gcc/testsuite/ * gcc.dg/pr111694.c: New. diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 2314478d558..e4e75943632 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1258,6 +1258,9 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) { if (rel != VREL_EQ) range_cast (equiv_range, type); + else + adjust_equivalence_range (equiv_range); + if (block_result.intersect (equiv_range)) { if (DEBUG_RANGE_CACHE) diff --git a/gcc/testsuite/gcc.dg/pr111694.c b/gcc/testsuite/gcc.dg/pr111694.c new file mode 100644 index 00000000000..a70b03069dc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr111694.c @@ -0,0 +1,19 @@ +/* PR tree-optimization/111009 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +#define signbit(x) __builtin_signbit(x) + +static void test(double l, double r) +{ + if (l == r && (signbit(l) || signbit(r))) + ; + else + __builtin_abort(); +} + +int main() +{ + test(0.0, -0.0); +} + diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index 30a02d3c9d3..fc792a4d5bc 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -183,6 +183,25 @@ relation_transitive (relation_kind r1, relation_kind r2) return relation_kind (rr_transitive_table[r1][r2]); } +// When one name is an equivalence of another, ensure the equivalence +// range is correct. Specifically for floating point, a +0 is also +// equivalent to a -0 which may not be reflected. See PR 111694. + +void +adjust_equivalence_range (vrange &range) +{ + if (range.undefined_p () || !is_a (range)) + return; + + frange fr = as_a (range); + REAL_VALUE_TYPE dconstm0 = dconst0; + dconstm0.sign = 1; + frange zeros (range.type (), dconstm0, dconst0); + // If range includes a 0 make sure both signs of zero are included. + if (fr.intersect (zeros) && !fr.undefined_p ()) + range.union_ (zeros); + } + // This vector maps a relation to the equivalent tree code. static const tree_code relation_to_code [VREL_LAST] = { diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 3177ecb1ad0..6412cbbe98b 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -91,6 +91,9 @@ inline bool relation_equiv_p (relation_kind r) void print_relation (FILE *f, relation_kind rel); +// Adjust range as an equivalence. +void adjust_equivalence_range (vrange &range); + class relation_oracle { public: