From patchwork Thu Jul 22 12:54:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1508708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LR7BoZC5; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GVswh3XN1z9s5R for ; Thu, 22 Jul 2021 22:59:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6996E3857807 for ; Thu, 22 Jul 2021 12:59:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6996E3857807 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626958768; bh=z9mimxQo6xz4k2oUSOlWkNiomeLGrlT7IzX1HihZzSs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LR7BoZC5yi/ienZzDNZO9XvUuqErcKzpjgeIsgzsqcx5csJ2TssTRV+PSGd8dOT9r pF87tT/AMO9eSVd4LmZC1y5m1zGr5aEeASwC5DP8eV+agWh8S403UrunEzFspVGAKO KdBolBSfZ2tPJ/rBQlkLAfZN+sZDTRYbZAs/F13U= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 28BDF383F41B for ; Thu, 22 Jul 2021 12:54:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 28BDF383F41B Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-6KTh6WokP8moRx7PR5ST3w-1; Thu, 22 Jul 2021 08:54:31 -0400 X-MC-Unique: 6KTh6WokP8moRx7PR5ST3w-1 Received: by mail-qk1-f198.google.com with SMTP id t144-20020a3746960000b02903ad9c5e94baso4017853qka.16 for ; Thu, 22 Jul 2021 05:54:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=z9mimxQo6xz4k2oUSOlWkNiomeLGrlT7IzX1HihZzSs=; b=pXvgGULxgHUKpr70UmHHieV4BSqiapCBSJdLmListqC3L52QkzDPImFXs75K+x8x4z Gbtrvybc8x8uelaPZwciyNcAJmPtB6m5tmJLdZxGyXOS6/91+kiscmxVaTrkK7otOW4l ETCBjcaY9FOoWNhXyIFDMFGvTZ6R3M3oSbVDwZrjD+wX8pfw4eq4bJgIQd5JlccfPya4 JO3/C3j7C1Rcx4y1fDR74/TzvvZveorORye3yv+8GfExojfE5deJgYkswTTvzt1xKhe2 wPiKE+DB5bSd4DUS/oLng8Mdl92h1ODS9OfOW5Z2jJf3BoUZamYeOkImbAoNF06OFW5M OWZA== X-Gm-Message-State: AOAM530MaSya1pv9QCdWHytnEiDNuHdFBviTX1E+SGY3fVIi77Ruie1M b3UyzN2Q30EY4104iUWeFPbW+sqikyQ059BzT/kJ6+zhvRF40ji2sesdmOaMHLt2kQBTNXzApC9 PN0L7PfWuqEGHxeFxbQ== X-Received: by 2002:a0c:f48d:: with SMTP id i13mr40386731qvm.24.1626958470890; Thu, 22 Jul 2021 05:54:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJythFWmoKVZ63P48H4xF11ZzvFIKESJ4W6ug9hUeiToH+QKKvCH5lC+k413pMIXDjJgJTQvOw== X-Received: by 2002:a0c:f48d:: with SMTP id i13mr40386719qvm.24.1626958470714; Thu, 22 Jul 2021 05:54:30 -0700 (PDT) Received: from ?IPv6:2607:fea8:a241:4600::74d4? ([2607:fea8:a241:4600::74d4]) by smtp.gmail.com with ESMTPSA id a16sm12564692qkn.107.2021.07.22.05.54.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Jul 2021 05:54:30 -0700 (PDT) To: gcc-patches Subject: [COMMITTED] PR tree-optimization/101511 - Allow non-symmetrical equivalences. Message-ID: <9f5ba5d9-b656-3be9-c715-36c995ba79bc@redhat.com> Date: Thu, 22 Jul 2021 08:54:29 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-13.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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Equivalences and relations are stored in dominator order.  If they are registered in non-dominator order, we sometimes get a little out of sync. This may miss the occasional optimization opportunity, but is not incorrect. When transitive relations are added, the intent is to "beef-up" the Implementation and we can put the assert back in to make sure things are always symmetrical. Until then, don't trap if we encounter non-symmetry, just use what is found. Bootstrapped on x86_64 & powerpc64-unknown-linux-gnu with no regressions.  Pushed. Andrew From d3fa77472b78c5ddada03a1052b229bea11cb76f Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 19 Jul 2021 15:54:57 -0400 Subject: [PATCH 3/3] Allow non-symmetrical equivalences. Don't trap if equivalences are processed out of DOM order, and aren't completely symmetrical. We will eventually resolve this, but its OK for now. gcc/ PR tree-optimization/101511 * value-relation.cc (relation_oracle::query_relation): Check if ssa1 is in ssa2's equiv set, and don't trap if so. gcc/testsuite/ * g++.dg/pr101511.C: New. --- gcc/testsuite/g++.dg/pr101511.C | 22 ++++++++++++++++++++++ gcc/value-relation.cc | 8 ++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr101511.C diff --git a/gcc/testsuite/g++.dg/pr101511.C b/gcc/testsuite/g++.dg/pr101511.C new file mode 100644 index 00000000000..ee2c7fdbc02 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr101511.C @@ -0,0 +1,22 @@ +// { dg-do compile } +// { dg-options "-O2 -Wno-div-by-zero" } + +void __assert_fail(const char *, const char *, int, const char *) + __attribute__((__noreturn__)); +template void test_uint() { + long __trans_tmp_3, __trans_tmp_1; + int Error; + for (;;) { + { + unsigned long Tmp = -1; + __trans_tmp_3 = Tmp - Tmp % 0; + } + Error += 0 == __trans_tmp_3 ? 0 : 1; + !Error ? void() : __assert_fail("", "", 3, __PRETTY_FUNCTION__); + T Tmp = -1; + __trans_tmp_1 = Tmp - Tmp % 0; + Error += 0 == __trans_tmp_1 ? 0 : 1; + !Error ? void() : __assert_fail("", "", 7, __PRETTY_FUNCTION__); + } +} +void test() { test_uint(); } diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index 43fcab7995a..bcfe388acf1 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -873,11 +873,15 @@ relation_oracle::query_relation (basic_block bb, tree ssa1, tree ssa2) if (kind != VREL_NONE) return kind; - // If one is not found, see if there is a relationship between equivalences. // If v2 isn't in v1s equiv set, then v1 shouldn't be in v2's set either. + // It is possible for out-of-order dominator processing to have an out of + // sync set of equivalences.. Down the road, when we do full updates, + // change this to an assert to ensure everything is in sync. const_bitmap equiv2 = equiv_set (ssa2, bb); - gcc_checking_assert (!equiv2 || !bitmap_bit_p (equiv2, v1)); + if (equiv2 && bitmap_bit_p (equiv2, v1)) + return EQ_EXPR; + // If not equal, see if there is a relationship between equivalences. if (!equiv1 && !equiv2) kind = VREL_NONE; else if (!equiv1) -- 2.17.2