From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id CCE693839BD4 for ; Mon, 20 Feb 2023 10:55:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CCE693839BD4 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-out2.suse.de (Postfix) with ESMTP id C22711FFF8 for ; Mon, 20 Feb 2023 10:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1676890543; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=3GADH2uWNsMKifNF5W1XSKCSwMB6IKQ7HJjG/cOHBrU=; b=FtM07bqaIDb7V+Bw3nuQwAvEVMKFTblc/23gucswcyQJXBrP4O+u5djH+E5K8uWiQsF92+ AVFtF3DU2MSl6nD1JSUmp08ADCUP2e8P9NCtuRzskuR2ulOHrdIOaCOT0NoXiyBDs9hZWW pHxuO/86c4GD/aSc+Exc0wled31uR2w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1676890543; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=3GADH2uWNsMKifNF5W1XSKCSwMB6IKQ7HJjG/cOHBrU=; b=AouhmVwrq8Sn7dK55s94QrUbX2u7nCprZT5WUTvpXNfn+KNAmAdqf7vHO2N5F/BcAplMfO e6YCVSzroNquL0DA== 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 B89162C141 for ; Mon, 20 Feb 2023 10:55:43 +0000 (UTC) Date: Mon, 20 Feb 2023 10:55:43 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/108816 - vect versioning check split confusion 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 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: <20230220105543.NcjxEQB_MifS1Er_l7AV-zE0AeX_gEpYIUqqGfxLl70@z> The split of the versioning condition assumes the definition is in the condition block which is ensured by the versioning code. But that only works when we actually have to insert any statements for the versioning condition. The following adjusts the guard accordingly and asserts this condition. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/108816 * tree-vect-loop-manip.cc (vect_loop_versioning): Adjust versioning condition split prerequesite, assert required invariant. * gcc.dg/torture/pr108816.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr108816.c | 18 ++++++++++++++++++ gcc/tree-vect-loop-manip.cc | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr108816.c diff --git a/gcc/testsuite/gcc.dg/torture/pr108816.c b/gcc/testsuite/gcc.dg/torture/pr108816.c new file mode 100644 index 00000000000..4c24d5584c1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108816.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fvect-cost-model=dynamic" } */ + +int m; + +void +foo (int p[][16], unsigned int x) +{ + while (x < 4) + { + int j; + + for (j = x * 4; j < (x + 1) * 4 - 2; j++) + p[0][j] = p[m][j]; + + ++x; + } +} diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index c04fcf40c44..6aa3d2ed0bf 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -3477,7 +3477,7 @@ vect_loop_versioning (loop_vec_info loop_vinfo, tree cost_name = NULL_TREE; profile_probability prob2 = profile_probability::uninitialized (); if (cond_expr - && !integer_truep (cond_expr) + && EXPR_P (cond_expr) && (version_niter || version_align || version_alias @@ -3711,6 +3711,7 @@ vect_loop_versioning (loop_vec_info loop_vinfo, if (cost_name && TREE_CODE (cost_name) == SSA_NAME) { gimple *def = SSA_NAME_DEF_STMT (cost_name); + gcc_assert (gimple_bb (def) == condition_bb); /* All uses of the cost check are 'true' after the check we are going to insert. */ replace_uses_by (cost_name, boolean_true_node); -- 2.35.3