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 ABC98385696A for ; Thu, 24 Aug 2023 08:59:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ABC98385696A 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 E924A22A06 for ; Thu, 24 Aug 2023 08:59:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692867593; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=iPsnfdax0tx4UE29EtqwBSh0lo8lSpmjzSTc0/JaSi4=; b=nPdwkrM3dIyiNVNDGYPxBROwNKqKhrOZjncuGgM13QEz2PHxpLJeF/a6BGqZUk8COj3w45 +hSyQw0BRp3lTln7Jtd+q64vcOR3cSTU3ECVMjJ5wr2Y8o1Oq6aUZBVrfTp8xoO/5V7hQG 0xpmujk5KwycVN8Uww3SfEtpeXrVL7o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692867593; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=iPsnfdax0tx4UE29EtqwBSh0lo8lSpmjzSTc0/JaSi4=; b=G98JDWiFhF7hPoRaqps5Mm8CcoKJvqPVot+Iwi2RqNQWaVuONUmLBaIq5jvjwvZR7kkxyS cluWFkOgC9EhicBQ== 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 E36102C276 for ; Thu, 24 Aug 2023 08:59:53 +0000 (UTC) Date: Thu, 24 Aug 2023 08:59:53 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/111128 - fix shift pattern recog 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: <20230824085953.534pI2ViNtT_BpULgzz7QKzwyFu8Q5t6-roYDCT2CyE@z> The following fixes placement of shift operand sanitization with MIN when the original shift operand was external but the actual one is not. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/111128 * tree-vect-patterns.cc (vect_recog_over_widening_pattern): Emit external shift operand inline if we promoted it with another pattern stmt. * gcc.dg/torture/pr111128.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr111128.c | 16 ++++++++++++++++ gcc/tree-vect-patterns.cc | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr111128.c diff --git a/gcc/testsuite/gcc.dg/torture/pr111128.c b/gcc/testsuite/gcc.dg/torture/pr111128.c new file mode 100644 index 00000000000..aa623b0d045 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr111128.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +int a, b, c, e, g; +short *d; +unsigned char f; +int h() { + f &= g; + for (; b; b++) { + a = 2; + for (; a; a--) + c = 0; + if (c) + continue; + e = (unsigned short)*d >> f; + } +} diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index cda27fed95b..a2ed0365b18 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -3121,7 +3121,7 @@ vect_recog_over_widening_pattern (vec_info *vinfo, = gimple_build_assign (new_var, MIN_EXPR, ops[1], build_int_cst (op_type, new_precision - 1)); gimple_set_location (pattern_stmt, gimple_location (last_stmt)); - if (unprom[1].dt == vect_external_def) + if (ops[1] == unprom[1].op && unprom[1].dt == vect_external_def) { if (edge e = vect_get_external_def_edge (vinfo, ops[1])) { -- 2.35.3