From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 454203857732 for ; Wed, 24 May 2023 11:18:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 454203857732 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6B9ED2225E for ; Wed, 24 May 2023 11:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684927127; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=/Khi0u9WGai8zTgBRKAzASdMSvWrKUl3sCYbgepavUs=; b=Dp8Rp1Xnb63SnxfkErA8XEE+dApFhodeCF4jrxdB22KlPGsMUKjzkjYcS71fZCvTcLmpB9 /ieX2yXaZK/v31YElyh2dn09oxvUcTKAzHWXFvuYOQd/5yPmPuAmhPApmJttbfEvp2deTI b+GuHCgUPuUCHI8B+OeWzYqe44GGo/8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684927127; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=/Khi0u9WGai8zTgBRKAzASdMSvWrKUl3sCYbgepavUs=; b=djHt45P8MFOjlEF5SgYMvVErZxBdx/FxsWKyt/7FnNIIEfCmW5DEHIKbGVr12yQt5dpqPR R/zVF6cHfVhWpxAA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 5FD6B2C15A for ; Wed, 24 May 2023 11:18:47 +0000 (UTC) Date: Wed, 24 May 2023 11:18:47 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109849 - fix fallout of PRE hoisting change User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,MISSING_MID,SPF_HELO_NONE,SPF_PASS,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 List-Id: Message-ID: <20230524111847.uU9_6Yueeh14WiEvTyy6B1J8J4AzHdPDqZAxFarZuB0@z> The PR109849 fix made us no longer hoist some memory loads because of the expression set intersection. We can still avoid to compute the union by simply taking the first sets expressions and leave the pruning of expressions with values not suitable for hoisting to sorted_array_from_bitmap_set. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/109849 * tree-ssa-pre.cc (do_hoist_insertion): Do not intersect expressions but take the first sets. * gcc.dg/tree-ssa/ssa-hoist-9.c: New testcase. --- gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c | 20 ++++++++++++++++++++ gcc/tree-ssa-pre.cc | 12 ++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c new file mode 100644 index 00000000000..388f79fd80f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-hoist-9.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-pre-stats" } */ + +int foo (int flag, int * __restrict a, int * __restrict b) +{ + int res; + if (flag) + res = *a + *b; + else + { + res = *a; + *a = 1; + res += *b; + } + return res; +} + +/* { dg-final { scan-tree-dump "HOIST inserted: 3" "pre" } } */ +/* { dg-final { scan-tree-dump-times " = \\\*" 2 "pre" } } */ +/* { dg-final { scan-tree-dump-times " = \[^\r\n\]* \\\+ \[^\r\n\]*;" 1 "pre" } } */ diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index b1ceea90a8e..7bbfa5ac43d 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -3625,8 +3625,9 @@ do_hoist_insertion (basic_block block) /* We have multiple successors, compute ANTIC_OUT by taking the intersection of all of ANTIC_IN translating through PHI nodes. Note we do not have to - worry about iteration stability here so just intersect the expression sets - as well. This is a simplification of what we do in compute_antic_aux. */ + worry about iteration stability here so just use the expression set + from the first set and prune that by sorted_array_from_bitmap_set. + This is a simplification of what we do in compute_antic_aux. */ bitmap_set_t ANTIC_OUT = bitmap_set_new (); bool first = true; FOR_EACH_EDGE (e, ei, block->succs) @@ -3641,15 +3642,10 @@ do_hoist_insertion (basic_block block) bitmap_set_t tmp = bitmap_set_new (); phi_translate_set (tmp, ANTIC_IN (e->dest), e); bitmap_and_into (&ANTIC_OUT->values, &tmp->values); - bitmap_and_into (&ANTIC_OUT->expressions, &tmp->expressions); bitmap_set_free (tmp); } else - { - bitmap_and_into (&ANTIC_OUT->values, &ANTIC_IN (e->dest)->values); - bitmap_and_into (&ANTIC_OUT->expressions, - &ANTIC_IN (e->dest)->expressions); - } + bitmap_and_into (&ANTIC_OUT->values, &ANTIC_IN (e->dest)->values); } /* Compute the set of hoistable expressions from ANTIC_OUT. First compute -- 2.35.3