From patchwork Wed Sep 25 10:48:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1167121 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509543-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="map0U5wW"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46dZYr2ClXz9sP3 for ; Wed, 25 Sep 2019 20:49:17 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=W0aR/F6qWp7Wc1JoBzad/t4jJ5Bt27Cvhzma3BrA+sB5/PhaGnO/E VoFZacNAYFvAvXP2LFwctBWrU8j9fZsiw+vI28qCLkNePqX00qVrXuHCm79/udjm HQPB58fB8WPjrULiqJ3434TllvP2IC8dDXCt+TkH+kUeEQ12QAKE+4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=ZXp0rqJh+zypoNetGrR1bnO464M=; b=map0U5wWHEvgA9bX0DbS 6CnL+SPfW6Q8LSg8+AAnK+uKzh3SPoD68JsIBzxvRB6gpuJAnXjexzBVLCOIz8Ug 2iGp6Gep87hfiX44zHZqgooYnRccXiwB1BKOjpfjG1dUkxFy/P1OP6TRBgswHk+Z zM7lWf6216QpY41Gr6/uNPg= Received: (qmail 81702 invoked by alias); 25 Sep 2019 10:49:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 81694 invoked by uid 89); 25 Sep 2019 10:49:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.1 spammy=recognition X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Sep 2019 10:49:08 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3A193AFDB for ; Wed, 25 Sep 2019 10:49:05 +0000 (UTC) Date: Wed, 25 Sep 2019 12:48:09 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR91896 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Removing operand swapping for reduction vectorization has enabled more pattern recognition which in turn triggers a latent bug in reduction vectorization. Bootstrap and regtest running on x86_64-unknown-linux-gnu. Richard. 2019-09-25 Richard Biener PR tree-optimization/91896 * tree-vect-loop.c (vectorizable_reduction): The single def-use cycle optimization cannot apply when there's more than one pattern stmt involved. * gcc.dg/torture/pr91896.c: New testcase. Index: gcc/testsuite/gcc.dg/torture/pr91896.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr91896.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr91896.c (working copy) @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-vectorize" } */ + +unsigned int +zj (unsigned int et) +{ + signed char jr = 0; + + do { + et *= 3; + jr += 2; + } while (jr >= 0); + + if (et == (unsigned int) jr) + et = 0; + + return et; +} Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 276120) +++ gcc/tree-vect-loop.c (working copy) @@ -6101,6 +6101,8 @@ vectorizable_reduction (stmt_vec_info st if (ncopies > 1 && STMT_VINFO_RELEVANT (reduc_stmt_info) <= vect_used_only_live && (use_stmt_info = loop_vinfo->lookup_single_use (phi_result)) + && (!STMT_VINFO_IN_PATTERN_P (use_stmt_info) + || !STMT_VINFO_PATTERN_DEF_SEQ (use_stmt_info)) && vect_stmt_to_vectorize (use_stmt_info) == reduc_stmt_info) single_defuse_cycle = true; @@ -6868,6 +6870,8 @@ vectorizable_reduction (stmt_vec_info st if (ncopies > 1 && (STMT_VINFO_RELEVANT (stmt_info) <= vect_used_only_live) && (use_stmt_info = loop_vinfo->lookup_single_use (reduc_phi_result)) + && (!STMT_VINFO_IN_PATTERN_P (use_stmt_info) + || !STMT_VINFO_PATTERN_DEF_SEQ (use_stmt_info)) && vect_stmt_to_vectorize (use_stmt_info) == stmt_info) { single_defuse_cycle = true;