From patchwork Fri Oct 25 10:48:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1184014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-511743-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="azt0DktF"; 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 47017h5VYDz9sPK for ; Fri, 25 Oct 2019 21:49:03 +1100 (AEDT) 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=bGgvcbTN3oFRKC5/ajtttfBD+95vqR3cPi8SbY/19ttvRJmsoyWPb dv8sjQ6lmTSv/Y2n8ka4XAr7wLI60yYWw0N8/+81xa6GOb9RnZBjUjTKqmvIzvGW N85OhT6aYP/rtu8ZB/Z4AAyvFNGPUtYywEafBlRkuQXD3mo9JKcRi8= 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=QIs/jDsBCrAYvj3DHTsp0txtNPA=; b=azt0DktF3Tmz1gOA09Mw mPTWQTbM+yMsxr1xqQl3g3XG9FSbgJxNj3MpapImQtuZxegaZCSxhxBuciWb6xL7 g9tyfX9btceamW3NpecSN0fcDAyTejhpiA3NnuHhiMzi800lAzryep93B5xM9h0b 4NC3DZyEkdxNZII/JxDAm44= Received: (qmail 38436 invoked by alias); 25 Oct 2019 10:48:53 -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 38362 invoked by uid 89); 25 Oct 2019 10:48:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.2 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=UD:quick_push, regtest, scalars, UD:create 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; Fri, 25 Oct 2019 10:48:41 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2C036B2EF for ; Fri, 25 Oct 2019 10:48:39 +0000 (UTC) Date: Fri, 25 Oct 2019 12:48:39 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR92222 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 We have to check each operand for being in a pattern, not just the first when avoiding build from scalars (we could possibly handle the special case of some of them being the pattern stmt root, but that would be a followup improvement). Bootstrap & regtest running on x86-64-unknown-linux-gnu. Richard. 2019-10-25 Richard Biener PR tree-optimization/92222 * tree-vect-slp.c (_slp_oprnd_info::first_pattern): Remove. (_slp_oprnd_info::second_pattern): Likewise. (_slp_oprnd_info::any_pattern): New. (vect_create_oprnd_info): Adjust. (vect_get_and_check_slp_defs): Compute whether any stmt is in a pattern. (vect_build_slp_tree_2): Avoid building up a node from scalars if any of the operand defs, not just the first, is in a pattern. * gcc.dg/torture/pr92222.c: New testcase. Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c (revision 277441) +++ gcc/tree-vect-slp.c (working copy) @@ -177,8 +177,7 @@ typedef struct _slp_oprnd_info stmt. */ tree first_op_type; enum vect_def_type first_dt; - bool first_pattern; - bool second_pattern; + bool any_pattern; } *slp_oprnd_info; @@ -199,8 +198,7 @@ vect_create_oprnd_info (int nops, int gr oprnd_info->ops.create (group_size); oprnd_info->first_dt = vect_uninitialized_def; oprnd_info->first_op_type = NULL_TREE; - oprnd_info->first_pattern = false; - oprnd_info->second_pattern = false; + oprnd_info->any_pattern = false; oprnds_info.quick_push (oprnd_info); } @@ -339,13 +337,11 @@ vect_get_and_check_slp_defs (vec_info *v tree oprnd; unsigned int i, number_of_oprnds; enum vect_def_type dt = vect_uninitialized_def; - bool pattern = false; slp_oprnd_info oprnd_info; int first_op_idx = 1; unsigned int commutative_op = -1U; bool first_op_cond = false; bool first = stmt_num == 0; - bool second = stmt_num == 1; if (gcall *stmt = dyn_cast (stmt_info->stmt)) { @@ -418,13 +414,12 @@ again: return -1; } - if (second) - oprnd_info->second_pattern = pattern; + if (def_stmt_info && is_pattern_stmt_p (def_stmt_info)) + oprnd_info->any_pattern = true; if (first) { oprnd_info->first_dt = dt; - oprnd_info->first_pattern = pattern; oprnd_info->first_op_type = TREE_TYPE (oprnd); } else @@ -1311,7 +1306,7 @@ vect_build_slp_tree_2 (vec_info *vinfo, /* ??? Rejecting patterns this way doesn't work. We'd have to do extra work to cancel the pattern so the uses see the scalar version. */ - && !is_pattern_stmt_p (SLP_TREE_SCALAR_STMTS (child)[0])) + && !oprnd_info->any_pattern) { slp_tree grandchild; @@ -1358,18 +1353,16 @@ vect_build_slp_tree_2 (vec_info *vinfo, /* ??? Rejecting patterns this way doesn't work. We'd have to do extra work to cancel the pattern so the uses see the scalar version. */ - && !is_pattern_stmt_p (stmt_info)) + && !is_pattern_stmt_p (stmt_info) + && !oprnd_info->any_pattern) { if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "Building vector operands from scalars\n"); this_tree_size++; - child = vect_create_new_slp_node (oprnd_info->def_stmts); - SLP_TREE_DEF_TYPE (child) = vect_external_def; - SLP_TREE_SCALAR_OPS (child) = oprnd_info->ops; + child = vect_create_new_slp_node (oprnd_info->ops); children.safe_push (child); oprnd_info->ops = vNULL; - oprnd_info->def_stmts = vNULL; continue; } @@ -1469,7 +1440,7 @@ vect_build_slp_tree_2 (vec_info *vinfo, /* ??? Rejecting patterns this way doesn't work. We'd have to do extra work to cancel the pattern so the uses see the scalar version. */ - && !is_pattern_stmt_p (SLP_TREE_SCALAR_STMTS (child)[0])) + && !oprnd_info->any_pattern) { unsigned int j; slp_tree grandchild; Index: gcc/testsuite/gcc.dg/torture/pr92222.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr92222.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr92222.c (working copy) @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-vectorize" } */ + +unsigned char *a; +int b; +void f(); +void c() +{ + char *d; + int e; + for (; b; b++) { + e = 7; + for (; e >= 0; e--) + *d++ = a[b] & 1 << e ? '1' : '0'; + } + f(); +}