From patchwork Thu Aug 24 08:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 136774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp983341vqm; Thu, 24 Aug 2023 02:00:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjDxqjzM7smo/VhDTXDon1fcLOiYCDqY9Jr5alO7O1kVyX0Q+BCaf6+uoPXVwOR/87cCdO X-Received: by 2002:a17:906:200a:b0:99c:5056:4e2e with SMTP id 10-20020a170906200a00b0099c50564e2emr10397985ejo.31.1692867642021; Thu, 24 Aug 2023 02:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692867642; cv=none; d=google.com; s=arc-20160816; b=zP076zf86ON4Iy0qiugAA4S3A7uU16UBAU93uiHvgbia7QAMhofEtnFk5DV14Lkj+P KABUbsKJoRD6I44fBzj8eKJuSLLoHtfPBHkK2fXX5WWx0TQSzde+NQwX5fG2l32pTC4H IOwzOGropnbJGpuMRZGBzKaO7f27voYfsnkbPkP/ev4XLWoS2O50YH2Z/fP5K5na1a60 OmqKN4hB/vQiuWMIYPU+V1LhCEhDg4ALRS0EOgNeP/xVfUSbTPLRfiSlBgAsaKzlMtBf xXm6iyMT9dibjhDoHusrB+qfsZkrfQ1KvgB4lBvZzyhHv30ABgECqjGY7PPMAcUK8l3a 5k1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=iPsnfdax0tx4UE29EtqwBSh0lo8lSpmjzSTc0/JaSi4=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=APuui1Mf5X6eSeBhAx9iv0/FjPOE5bM/s/sL9L3dG7I6OBL06r0qInrUkGtRzsb9On FfFaG8pOBb7Y6a+Ze66Vz/giVvnDxYX68rfTwSTyeAFR6CZNdEttUCdMmSdKeojPHO1X dRbqVAkhXaqC9UqU/tFmWsLgLBJ7uMJHQ9A6gS3D/B6JOKRucfabm2ZLu8oI+uyOuIlT C1sbwqOhtsQ046bXJAFZf/RL9RMg3vjPIFYT+C2pzU9wfIh7qYx0yMgZq4Ag4qYM6jnd 6Pmmkjglmuy3wjK6T+NZSnaJlpVLak4X4MD/uRGp0tdyJmeQXry1Ow3/AIEdvoY/LUo4 fzNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=koKlTOY8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z8-20020a170906240800b00986432cf57csi9542466eja.942.2023.08.24.02.00.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 02:00:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=koKlTOY8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD4F6385C422 for ; Thu, 24 Aug 2023 09:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD4F6385C422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692867640; bh=iPsnfdax0tx4UE29EtqwBSh0lo8lSpmjzSTc0/JaSi4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=koKlTOY8tYHGEWhw/myZfbvjtFw/tE10W+vTNqv6F7eqgjsBAKeOjjQPcRO9O1yUd R6fGm3dldZPCADXIWk3mDG5K5neA0e9F82mX8bybqL1a10nYOZGQQ9qxDmTPjSV/4k pAPv69vqGGIpPK4zi4/L43GUwTO9gvEahXwJp6As= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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) 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) 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 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 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230824090040.CD4F6385C422@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775100380780236009 X-GMAIL-MSGID: 1775100380780236009 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])) {