From patchwork Tue May 17 15:45:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1632429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=k1Hjygdz; dkim-atps=neutral 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=) 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L2gT51Sm0z9s1l for ; Wed, 18 May 2022 01:46:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EEA37385840C for ; Tue, 17 May 2022 15:46:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEA37385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652802373; bh=YeXex1uPFV0Wo8tUOYLAmCt2GgbRnaLY0LVOVTR0dNs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=k1HjygdzrGVdhzxX9qmUtSUjjpN1xl+8DLWJCQUep2O1lLd/Aj5UPXoYkt2ixFJnV 5krgqIXqc1kAelVcdrXrjLBFTHM9ymoL5Kjwr72FoqLS9RwEU/yFNZ4N02PZQK4sAd HvkaMzMy/2mVieHFMpoj7XLb326s0iL2n25/GHSI= 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 21989385740B for ; Tue, 17 May 2022 15:45:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 21989385740B Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594-Iddc9tD0PyCF6RNoOMCJAA-1; Tue, 17 May 2022 11:45:14 -0400 X-MC-Unique: Iddc9tD0PyCF6RNoOMCJAA-1 Received: by mail-qv1-f71.google.com with SMTP id t15-20020ad45bcf000000b0045a8cfef66bso15072346qvt.11 for ; Tue, 17 May 2022 08:45:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=4SQjiH7kJc0Krpn217Cwu6PvKAjOEPhF893ZJVtcPyo=; b=cDnlQJNZrfPoIBmzKEAPr1IFvVKG7x2iWX22C1ySHNxLPEE1RTpqzkEwgFzwhcS5/k yzRwizndCJlzzMO6ess/qg+yLfo/ZJZSI1bHONvLKyInIO1xZiLllcKYifx8z0Mv+gwy MHg8EsOwpQefju9qxxylpM/sHY7diTTpajjGXn6RBm5MxoCTaPboFZoBmwOM6V+ySpCu gQHexZWmeQOFOGLkOOxh9d7TU6HW2gSOwGOBByQo7eRLGnCcGKGt+R8M72hAYuZirBGj rpBJ8pvZl/atY9KlndWL4V/jM9KO3nwKlxXYWDjk9pAZnOocnRpNpinzF623VT9ke6gR 2KOw== X-Gm-Message-State: AOAM530kshpE1Fyp5XrURVaqdt2THXn9RJCxtLuurauvUSnAx35NFCqL bzZwMFlv2D8OHIT0q76RyJ7VzsieefIHxMm9/CddnlzhyQr0aKxiwu+RKk4D9fr4phG+iuCvRMr 8O5Mtq6yTSEy0evYz7wJlMcXiLLy+NVuBX/hCb5EtBE0TGjKPb/QTMbtgStida3bluKn2MQ== X-Received: by 2002:a05:620a:280d:b0:67d:2480:fdea with SMTP id f13-20020a05620a280d00b0067d2480fdeamr16609939qkp.157.1652802313465; Tue, 17 May 2022 08:45:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZDWyOVKZROSJCfpu7pBRDoPfSrKhu0ptwmo1MNK9CB14HvH02BN2VsqQxWt5oyg4BrOQ/uA== X-Received: by 2002:a05:620a:280d:b0:67d:2480:fdea with SMTP id f13-20020a05620a280d00b0067d2480fdeamr16609921qkp.157.1652802313120; Tue, 17 May 2022 08:45:13 -0700 (PDT) Received: from ?IPV6:2607:fea8:a261:5e00::94b0? ([2607:fea8:a261:5e00::94b0]) by smtp.gmail.com with ESMTPSA id i9-20020ae9ee09000000b006a0ba4b8f48sm7705654qkg.49.2022.05.17.08.45.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 May 2022 08:45:12 -0700 (PDT) Message-ID: Date: Tue, 17 May 2022 11:45:11 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: gcc-patches Subject: [PATCH] PR tree-optimization/105458 - Check for equivalence after merging relations. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.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" Sorry, missed this one earlier. When we register a relation, such as LE_EXPR,  we first check if there is an existing relation that applies, and if so they are combined. We were checking if the relation being registered was an EQ_EXPR, and if so, invoked the equivalence oracle.  I was doing the check for EQ_EXPR first, then merging with any existing relation.   In this case, the merge resulted in transforming the LE_EXPR into an EQ_EXPR, but the check to invoke the equivalence_oracle had already been done, and we got to a place we shouldn't have. doh! The fix is to do the merge first, then check for EQ_EXPR. The patch is a hair different (due to VREL_*  renames in gcc13), so I've attached both patches. bootstraps on gcc12 and gcc13 with no regressions.  pushed on trunk. OK for GCC12? Andrew commit c48fe8d3430e81ddea621c24e9b66d55aadfb316 Author: Andrew MacLeod Date: Tue May 17 09:36:39 2022 -0400 Check for equivalence after merging relations. When registering a relation, we need to merge with any existing relation before checking if it was an equivalence... otherwise it was not being handled properly. gcc/ PR tree-optimization/105458 * value-relation.cc (path_oracle::register_relation): Merge, then check for equivalence. gcc/testsuite/ * gcc.dg/pr105458.c: New. diff --git a/gcc/testsuite/gcc.dg/pr105458.c b/gcc/testsuite/gcc.dg/pr105458.c new file mode 100644 index 00000000000..eb58bf21f32 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105458.c @@ -0,0 +1,20 @@ +/* PR tree-optimization/105458 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fexpensive-optimizations -fno-tree-dominator-opts " } */ + +void +yj (int j4) +{ + int t3; + + for (t3 = 0; t3 < 6; ++t3) + { + short int v4 = t3; + + if (v4 == j4 || v4 > t3) + for (;;) + { + } + } +} + diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index 077ab4230a7..a69ad080e47 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -1388,16 +1388,16 @@ path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, fprintf (dump_file, " (root: bb%d)\n", bb->index); } + relation_kind curr = query_relation (bb, ssa1, ssa2); + if (curr != VREL_NONE) + k = relation_intersect (curr, k); + if (k == EQ_EXPR) { register_equiv (bb, ssa1, ssa2); return; } - relation_kind curr = query_relation (bb, ssa1, ssa2); - if (curr != VREL_NONE) - k = relation_intersect (curr, k); - bitmap_set_bit (m_relations.m_names, SSA_NAME_VERSION (ssa1)); bitmap_set_bit (m_relations.m_names, SSA_NAME_VERSION (ssa2)); relation_chain *ptr = (relation_chain *) obstack_alloc (&m_chain_obstack,