From patchwork Thu Apr 20 17:22:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1771566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=aGBOmWMi; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q2PcF0LDyz1ybF for ; Fri, 21 Apr 2023 03:22:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B9D03858401 for ; Thu, 20 Apr 2023 17:22:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B9D03858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682011355; bh=PPSRAMSmR4f4hUmggpSJztuT62UrFBq8wNMRLcYLvsM=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=aGBOmWMiAwhCqGsulO3fy3MMxcqaZYQG4+DBp3cr7uaUQYbRal8th6ZE0Zik7q3Gn xFPfxRI1RZ6Y51oXBRaxOe9wNUWpXdfO9DGHuF+a7U772mvQHjlcNr2lPEO5X87FyR AbjXkI/pw2Zq4N2heLSXB0Z1Bel80YH7EUaIj78g= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 180383858D37 for ; Thu, 20 Apr 2023 17:22:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 180383858D37 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-195-YnwJUqgyOQyLKS3XtEWCvw-1; Thu, 20 Apr 2023 13:22:14 -0400 X-MC-Unique: YnwJUqgyOQyLKS3XtEWCvw-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-3ed00bf8455so6073461cf.3 for ; Thu, 20 Apr 2023 10:22:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682011333; x=1684603333; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4vMBmzzjvbhfEQAsNIzlIMhNmjx/rD3kNQ9Gdwx00oo=; b=SmuIWeu8vI4suXer9wzLp3tPLpDsW6QTABFa+b7Uyr0b4eXA/KD4tIXLyMnqpcJ/B3 I+4UaG2zZG9m3QplznFsBxME0Cy1kQLXJSdZ1O3Ae5YJMExDBT7fL4k3PN/dIzIhuZy2 1fxYS4V8udHD49BKEpU+AI0+TKoIDWPl2+YdmDTwopAZ74o+ssd5SfOX4FERRPqhGtdQ LAVUDP7XBeS5MR6QO4bUw1nNBiNihXMfWWkrUQ2c4DgkqhSDcu1L6087MGOoxSS0rJpy rinuMPHNEKy7mH2LEltBIzhDv5ujeJPV9DKo9vTrNpfg27skgZ6optAsKwblQlB2s/ew iZxw== X-Gm-Message-State: AAQBX9czLOr3eiZqzyUSQogNWRixYVYGGW2o/ijF3axBaFSfOYo4YxDF zrebKo1LDIdfKDXwWRMET+pv+0A5O5tkLLKC0BDWN2pXXolaFJRiiokdzcZor7f2ui50hGGskdM kBE81r1yhhvMzdjDIJbV1CQtcq3qVzvr2Mlu16ze17EqKnHpuweDOvPK0vmQEOdUmcrPo3DLiMC Fk8w== X-Received: by 2002:ac8:598a:0:b0:3e6:941b:47e0 with SMTP id e10-20020ac8598a000000b003e6941b47e0mr3835080qte.11.1682011333369; Thu, 20 Apr 2023 10:22:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZZamtHpLWngRMXDoN55vJix0lWlgUS24evgA93RqRFqAScII6IleWFzOq//7DYGotRzEO17w== X-Received: by 2002:ac8:598a:0:b0:3e6:941b:47e0 with SMTP id e10-20020ac8598a000000b003e6941b47e0mr3835051qte.11.1682011333063; Thu, 20 Apr 2023 10:22:13 -0700 (PDT) Received: from ?IPV6:2605:8d80:5e1:ade0:2cfa:5f99:c6ab:f670? ([2605:8d80:5e1:ade0:2cfa:5f99:c6ab:f670]) by smtp.gmail.com with ESMTPSA id a13-20020ac8720d000000b003ef1586721dsm629291qtp.26.2023.04.20.10.22.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Apr 2023 10:22:12 -0700 (PDT) Message-ID: <1c7831e6-2591-5bdf-cb02-4f851a7fe02f@redhat.com> Date: Thu, 20 Apr 2023 13:22:11 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 To: gcc-patches Cc: Richard Biener , Jakub Jelinek Subject: [PATCH] PR tee-optimization/109564 - Do not ignore UNDEFINED ranges when determining PHI equivalences. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.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, 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" This removes specal casing UNDEFINED ranges when we are checking to see if all arguments are the same and registering an equivalence. previously if there were 2 different names, and one was undefined, we ignored it an created an equivaence with the other one.  as observed, this is not a 2 way relationship, and as such, we souldnt do it this way.   This removes the bypass for undefined ranges in chekcing if arguments are the same symbol. Bootstrapped/regtested successfully on x86_64-linux and i686-linux.  OK for trunk? Andrew commit 26f20f4446531225b362b9ec7b473ce4f0822a0a Author: Andrew MacLeod Date: Thu Apr 20 13:10:40 2023 -0400 Do not ignore UNDEFINED ranges when determining PHI equivalences. Do not ignore UNDEFINED name arguments when registering two-way equivalences from PHIs. PR tree-optimization/109564 gcc/ * gimple-range-fold.cc (fold_using_range::range_of_phi): Do no ignore NUDEFINED range names when deciding if all the names on a PHI are the same, gcc/testsuite/ * gcc.dg/torture/pr109564-1.c: New testcase. * gcc.dg/torture/pr109564-2.c: Likewise. * gcc.dg/tree-ssa/evrp-ignore.c: XFAIL. * gcc.dg/tree-ssa/vrp06.c: Likewise. --- diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 429734f954a..180f349eda9 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -771,16 +771,16 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) if (gimple_range_ssa_p (arg) && src.gori ()) src.gori ()->register_dependency (phi_def, arg); + } - // Track if all arguments are the same. - if (!seen_arg) - { - seen_arg = true; - single_arg = arg; - } - else if (single_arg != arg) - single_arg = NULL_TREE; + // Track if all arguments are the same. + if (!seen_arg) + { + seen_arg = true; + single_arg = arg; } + else if (single_arg != arg) + single_arg = NULL_TREE; // Once the value reaches varying, stop looking. if (r.varying_p () && single_arg == NULL_TREE) diff --git a/gcc/testsuite/gcc.dg/torture/pr109564-1.c b/gcc/testsuite/gcc.dg/torture/pr109564-1.c new file mode 100644 index 00000000000..e7c855f1edf --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr109564-1.c @@ -0,0 +1,74 @@ +/* { dg-do run } */ + +struct libkeccak_spec { + long int bitrate; +}; + +struct libkeccak_generalised_spec { + long int bitrate; + long int state_size; + long int word_size; +}; + +int __attribute__((noipa)) +libkeccak_degeneralise_spec(struct libkeccak_generalised_spec *restrict spec, + struct libkeccak_spec *restrict output_spec) +{ + long int state_size, word_size, bitrate, output; + const int have_state_size = spec->state_size != (-65536L); + const int have_word_size = spec->word_size != (-65536L); + const int have_bitrate = spec->bitrate != (-65536L); + + if (have_state_size) + { + state_size = spec->state_size; + if (state_size <= 0) + return 1; + if (state_size > 1600) + return 2; + } + + if (have_word_size) + { + word_size = spec->word_size; + if (word_size <= 0) + return 4; + if (word_size > 64) + return 5; + if (have_state_size && state_size != word_size * 25) + return 6; + else if (!have_state_size) { + spec->state_size = 1; + state_size = word_size * 25; + } + } + + if (have_bitrate) + bitrate = spec->bitrate; + + if (!have_bitrate) + { + state_size = (have_state_size ? state_size : (1600L)); + output = ((state_size << 5) / 100L + 7L) & ~0x07L; + bitrate = output << 1; + } + + output_spec->bitrate = bitrate; + + return 0; +} + +int main () +{ + struct libkeccak_generalised_spec gspec; + struct libkeccak_spec spec; + spec.bitrate = -1; + gspec.bitrate = -65536; + gspec.state_size = -65536; + gspec.word_size = -65536; + if (libkeccak_degeneralise_spec(&gspec, &spec)) + __builtin_abort (); + if (spec.bitrate != 1024) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr109564-2.c b/gcc/testsuite/gcc.dg/torture/pr109564-2.c new file mode 100644 index 00000000000..eeab437c0b3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr109564-2.c @@ -0,0 +1,33 @@ +/* { dg-do run } */ + +struct libkeccak_generalised_spec { + int state_size; + int word_size; +} main_gspec; + +long gvar; + +int libkeccak_degeneralise_spec(struct libkeccak_generalised_spec *spec) +{ + int state_size; + int have_state_size = spec->state_size != -1; + int have_word_size = spec->word_size; + + if (have_state_size) + state_size = spec->state_size; + if (have_word_size) + gvar = 12345; + if (have_state_size && state_size != spec->word_size) + return 1; + if (spec) + gvar++; + return 0; +} + +int main() +{ + main_gspec.state_size = -1; + if (libkeccak_degeneralise_spec(&main_gspec)) + __builtin_abort(); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/evrp-ignore.c b/gcc/testsuite/gcc.dg/tree-ssa/evrp-ignore.c index 9bfaed6a50a..ee93e5ad9f6 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/evrp-ignore.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/evrp-ignore.c @@ -25,4 +25,4 @@ void foo (int x, int y, int z) kill(); } -/* { dg-final { scan-tree-dump-not "kill" "evrp" } } */ +/* { dg-final { scan-tree-dump-not "kill" "evrp" { xfail *-*-* } } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp06.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp06.c index 898477e42fb..8f5f86021c8 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/vrp06.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp06.c @@ -30,4 +30,4 @@ foo (int i, int j, int a) /* { dg-final { scan-tree-dump-times "Folding predicate \[i|j\]_\[0-9\]+.*0 to 0" 1 "vrp1" } } */ /* { dg-final { scan-tree-dump-times "Folding predicate \[i|j\]_\[0-9\]+.*0 to 1" 1 "vrp1" } } */ -/* { dg-final { scan-tree-dump-times "Folding predicate i_\[0-9]+.*j_\[0-9\]+.* to 0" 1 "vrp1" } } */ +/* { dg-final { scan-tree-dump-times "Folding predicate i_\[0-9]+.*j_\[0-9\]+.* to 0" 1 "vrp1" { xfail *-*-* } } } */