From patchwork Mon Nov 29 17:20:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 48259 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B4DC385781D for ; Mon, 29 Nov 2021 17:20:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B4DC385781D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638206445; bh=RX/cIium2fyFMqbev92gCwdSTNtpfHeOp1MvwsTKmCQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YbfnzY20PfZ7SvTBvyorb0+9jtNNOCh15HnuRQYuchZOFbkNZMW21QiPcVEq8TcRa 1RWFxCawA5PQmQOLLgkOym0/xjQ6MEJ3JNhTQLHkPS2L45c+2+vUNcmY66x/gv47sh XlNj/rBJfi+E00NtOhthpdv678g9hFjPuqHH5mso= 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 DFD61385841C for ; Mon, 29 Nov 2021 17:20:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFD61385841C Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-bx1JVs8WMPSt9f9U4wFxdw-1; Mon, 29 Nov 2021 12:20:13 -0500 X-MC-Unique: bx1JVs8WMPSt9f9U4wFxdw-1 Received: by mail-qt1-f197.google.com with SMTP id s6-20020a05622a018600b002b2d93b9c73so24189113qtw.9 for ; Mon, 29 Nov 2021 09:20:13 -0800 (PST) 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:from:subject; bh=yHCXBoKDy3qUEvxyhWukWp4/JgMUcP3nsDuZL35VEhw=; b=7bjg9aV89wKJyWitAxKoQVYMZhxuVpzSYOOZWnhs7Ty/p5OwfAH8PXZ0wNr540Bo8G 7Y7TUs7GWLfYNyjYcIMX+R7VC5IBkbR53xDK8jFk7ig6k4uWOJdVpCr4iWi7wz2mC6iX 976pJmUaFQvjJVhkXwvsm03E8UeVwxpOEdb7tVXtOnw9eU8yYNTHWplZyb5Go/AyAq5s t+Jj6K+ltYqy7+/sc7XHR/qDQeivbLjsg7556+Mi0ATz5XzFuAeEd+xurDiCyrfC7uaA An4F3IQMz0EYiqwo6idQl/4TlFWQQpTy4FnSYIhkDZgwfLr0Q0vTmoEqb/U0f3QgyYwD FVIQ== X-Gm-Message-State: AOAM532u36hLh6KhqZrT3VlYFbvG+YXXx9VjTuST4/00U9gy/DttkuBJ TnqiIW/QbbovgxbAmHfIofqQPQKo45LGoqcVnXtpUBpsZ2MO53/zZCDb+yXgD6wtLtPocUqx57P ejny1OsUizzr5YW32FNPqCODwk32htHZUt4qlpRJR2qtIc7qVurRv2W8iKNq+aoZTy5q+sQ== X-Received: by 2002:a05:620a:46ac:: with SMTP id bq44mr41404544qkb.414.1638206412166; Mon, 29 Nov 2021 09:20:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJw30B6pX0tlz+9KAqHdhaDWgcfdm+4/tnqanwOU8P40bFd1lb56Ha9+lLYHnpqLPNaYV92Oxw== X-Received: by 2002:a05:620a:46ac:: with SMTP id bq44mr41404465qkb.414.1638206411476; Mon, 29 Nov 2021 09:20:11 -0800 (PST) Received: from [192.168.0.102] ([104.219.122.97]) by smtp.gmail.com with ESMTPSA id u10sm9460302qtx.3.2021.11.29.09.20.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Nov 2021 09:20:10 -0800 (PST) Message-ID: <31e03986-11ba-6c53-7ce0-1636eb25a7e7@redhat.com> Date: Mon, 29 Nov 2021 12:20:09 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 To: gcc-patches Subject: [PATCH] tree-optimization/103440 - Always track arguments, even when ignoring equiv params. 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, RCVD_IN_MSPIKE_H2, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" I need to adjust the original patch, I shouldn't have continued the loop when dealing with equivalences.    An equivalence is not the same as an undefined value...  we might be able to ignore the range from it for calculation purposes, but we cannot ignore the fact that it is a different SSA_NAME and may contain a different value that we do care about. There are other checks in then loop which will allow us to assign an equivalence between the DEF and an argument if we are ignoring the other ssa_names..  such as when there are undefined values. a_3 = PHI if a_2 is undefined, we can create an equivalence between a_3 and a_1 as the value of a_2 is irrelevant and can be whatever we want it to be. if a_2 is instead an equivalence with a_3, we do not want to create an equivalence between a_3 and a_1 in this block as we may then turn it into a copy.. we'd only be able to do this if there was an equivalence between a_1 and a_2, and we are not checking that. Although we are may not be adding the range for a_2 into the cumulative knowledge of a_3's range, we do need to keep the edge to retain the copy as its value is important and could be different than the other argument... and we need to retain the copy when we go out of ssa. This fixes that oversight, bootstrapped on x86_64-pc-linux-gnu with no regressions.  OK? Caveat..  the test case has an infinite loop without this fix, but degagnu doesn't seem to kill it, and my test suite runs go forever.. if there something I am missing?   The gcc.log claims that it timeouts after 300 second, but it doesn't kill the executable. I set the dg-timeout field, but that appears to be a compile time timeout, not runtime anyway. Andrew From 2991aa06aaaf87874df8ed1c93a4650dc85c79ec Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 29 Nov 2021 09:19:34 -0500 Subject: [PATCH 1/2] Always track arguments, even when ignoring equiv params. To "ignore" ranges from equivalences, we should track the range separately, but still do the other name processing which determiens if there is a single name or not for equivalence. Otherwise we mistakently think we can introduce an equivalences. gcc/ PR tree-optimization/103440 * gimple-range-fold.cc (fold_using_range::range_of_phi): Continue normal param processing for equiv params. gcc/testsuite/ * gcc.dg/pr103440.c: New. --- gcc/gimple-range-fold.cc | 21 +++++++++------------ gcc/testsuite/gcc.dg/pr103440.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr103440.c diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index d66ada5bb7c..58122297c0b 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -795,20 +795,17 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src) // Get the range of the argument on its edge. src.get_phi_operand (arg_range, arg, e); - // Likewise, if the incoming PHI argument is equivalent to this - // PHI definition, it provides no new info. Accumulate these ranges - // in case all arguments are equivalences. - if (src.query ()->query_relation (e, arg, phi_def, false) == EQ_EXPR) - { - single_arg = arg; - equiv_range.union_(arg_range); - continue; - } - if (!arg_range.undefined_p ()) { // Register potential dependencies for stale value tracking. - r.union_ (arg_range); + // Likewise, if the incoming PHI argument is equivalent to this + // PHI definition, it provides no new info. Accumulate these ranges + // in case all arguments are equivalences. + if (src.query ()->query_relation (e, arg, phi_def, false) == EQ_EXPR) + equiv_range.union_(arg_range); + else + r.union_ (arg_range); + if (gimple_range_ssa_p (arg) && src.gori ()) src.gori ()->register_dependency (phi_def, arg); @@ -829,7 +826,7 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src) // If all arguments were equivalences, use the equivalence ranges as no // arguments were processed. - if (!seen_arg) + if (r.undefined_p () && !equiv_range.undefined_p ()) r = equiv_range; // If the PHI boils down to a single effective argument, look at it. diff --git a/gcc/testsuite/gcc.dg/pr103440.c b/gcc/testsuite/gcc.dg/pr103440.c new file mode 100644 index 00000000000..b97f45cd3ed --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr103440.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-Os" } */ +/* { dg-timeout 10 } */ + +int a, b, c, d, e; +int main() { + int f = 2, g = 1, h = -3; +L1: + c = b ^ 1; + if (!f) + goto L3; + if (d) + g = e; + f = h; + if (!c) + goto L1; +L2: + if (g) + a = 0; +L3: + if (d == g) + goto L2; + return 0; +} -- 2.17.2