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 A02083858D1E for ; Thu, 18 Aug 2022 14:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A02083858D1E Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id A61CD3F16F for ; Thu, 18 Aug 2022 14:03:27 +0000 (UTC) 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 94A582C184 for ; Thu, 18 Aug 2022 14:03:27 +0000 (UTC) Date: Thu, 18 Aug 2022 14:03:27 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/106617 - fix fold_binary_op_with_conditional_arg pattern issue 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 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-List-Received-Date: Thu, 18 Aug 2022 14:03:30 -0000 Message-ID: <20220818140327.s5oJJICnNKvwgftj6fdI3fW_LfGbX9VhGib8Yt_umlA@z> Now that we have parts of fold_binary_op_with_conditional_arg duplicated in match.pd and are using ! to take or throw away the result we have to be careful to not have both implementations play games which each other, causing quadratic behavior. In particular the match.pd implementation requires both arms to simplify while the fold-const.cc is happy with just one arm simplifying (something we cannot express in match.pd). The fix is to simply not enable the match.pd pattern for GENERIC. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/106617 * match.pd ((a ? b : c) > d -> a ? (b > d) : (c > d)): Fix guard, disable on GENERIC to not cause quadratic behavior with the fold-const.cc implementation and the use of ! * gcc.dg/pr106617.c: New testcase. --- gcc/match.pd | 4 +++- gcc/testsuite/gcc.dg/pr106617.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr106617.c diff --git a/gcc/match.pd b/gcc/match.pd index 07d0a61fc3a..1bb936fc401 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5796,6 +5796,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (cmp (bit_and@2 @0 integer_pow2p@1) @1) (icmp @2 { build_zero_cst (TREE_TYPE (@0)); }))) +#if GIMPLE /* From fold_binary_op_with_conditional_arg handle the case of rewriting (a ? b : c) > d to a ? (b > d) : (c > d) when the compares simplify. */ @@ -5805,8 +5806,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Do not move possibly trapping operations into the conditional as this pessimizes code and causes gimplification issues when applied late. */ (if (!FLOAT_TYPE_P (TREE_TYPE (@3)) - || operation_could_trap_p (cmp, true, false, @3)) + || !operation_could_trap_p (cmp, true, false, @3)) (cond @0 (cmp! @1 @3) (cmp! @2 @3))))) +#endif (for cmp (ge lt) /* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */ diff --git a/gcc/testsuite/gcc.dg/pr106617.c b/gcc/testsuite/gcc.dg/pr106617.c new file mode 100644 index 00000000000..4274b55f80d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr106617.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ + +int nr_cpu_ids; +void fc_setup_exch_mgr() { + (((((((1UL << (((0, 0) + ? ((1) + ? (((nr_cpu_ids)) ? 0 + : ((nr_cpu_ids)) & (21) ? 21 + : ((nr_cpu_ids)) ? 20 + : ((nr_cpu_ids)) & (19) ? 19 + : ((nr_cpu_ids)) ? 18 + : ((nr_cpu_ids)) & (17) ? 17 + : ((nr_cpu_ids)) ? 16 + : ((nr_cpu_ids)) & (15) ? 15 + : ((nr_cpu_ids)) ? 14 + : ((nr_cpu_ids)) & (13) ? 13 + : ((nr_cpu_ids)) ? 12 + : ((nr_cpu_ids)) & (11) ? 11 + : ((nr_cpu_ids)) ? 10 + : ((nr_cpu_ids)) & (9) ? 9 + : ((nr_cpu_ids)) ? 8 + : ((nr_cpu_ids)) & (7) ? 7 + : ((nr_cpu_ids)) ? 6 + : ((nr_cpu_ids)) & (5) ? 5 + : ((nr_cpu_ids)) ? 4 + : ((nr_cpu_ids)) & (3) + ? 3 + : ((nr_cpu_ids)-1) & 1) + : 1) + : 0) + + 1))))) & + (1UL << 2) + ? 2 + : 1)) + ); +} -- 2.35.3