From patchwork Tue Nov 19 07:32:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1197210 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-513985-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="omJMMxvb"; 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 47HHcK39jnz9sSV for ; Tue, 19 Nov 2019 18:33:20 +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=HtHnfJ4RLtwwfVLbjazUHxwuzGC0yP3XI9BtzEedOglRXPoQAO1mr pG7ARV5ZRQ5xxGcYSxyoq94mY6iRtxqu8A/xAaVMiKRseikHaHsBzWk6Bm2tglxQ SRzGw+dnDTmK9CM/zQp/QUvCg8OST2QWQUf9a/KdbgKoLtmgpEDIYs= 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=68LsvadKIbeV0mwbXSiK0Nduq78=; b=omJMMxvbJT33j6gbXUCs di4Dg9widS5Z4ud61YeYsmGz5iXunFvdKodHPzOgVEU0DHBaH6EXr35cBbtJGSIZ QS+eUZeoxNITJSWYTUpgxYooVtPLwfhphe1rnL9JA3jGsnKtEnHeM87b4kXvT274 al/kKM7MEpfXmj2VgCvwUTg= Received: (qmail 116409 invoked by alias); 19 Nov 2019 07:33:12 -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 116399 invoked by uid 89); 19 Nov 2019 07:33:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-12.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.1 spammy=mirror, vec_stmt, gimple_convert 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; Tue, 19 Nov 2019 07:33:01 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 81789B229 for ; Tue, 19 Nov 2019 07:32:59 +0000 (UTC) Date: Tue, 19 Nov 2019 08:32:59 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR92554 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 The followng fixes yet another case where conversions confuse epilogue generation, this times for condition vectorization. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2019-11-19 Richard Biener PR tree-optimization/92554 * tree-vect-loop.c (vect_create_epilog_for_reduction): Look for the actual condition stmt and deal with sign-changes. * gcc.dg/vect/pr92554.c: New testcase. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 278406) +++ gcc/tree-vect-loop.c (working copy) @@ -4540,12 +4552,21 @@ vect_create_epilog_for_reduction (stmt_v zeroes. */ if (STMT_VINFO_REDUC_TYPE (reduc_info) == COND_REDUCTION) { - tree indx_before_incr, indx_after_incr; - poly_uint64 nunits_out = TYPE_VECTOR_SUBPARTS (vectype); - - gimple *vec_stmt = STMT_VINFO_VEC_STMT (stmt_info)->stmt; + stmt_vec_info cond_info = STMT_VINFO_REDUC_DEF (reduc_info); + cond_info = vect_stmt_to_vectorize (cond_info); + while (gimple_assign_rhs_code (cond_info->stmt) != COND_EXPR) + { + cond_info + = loop_vinfo->lookup_def (gimple_op (cond_info->stmt, + 1 + STMT_VINFO_REDUC_IDX + (cond_info))); + cond_info = vect_stmt_to_vectorize (cond_info); + } + gimple *vec_stmt = STMT_VINFO_VEC_STMT (cond_info)->stmt; gcc_assert (gimple_assign_rhs_code (vec_stmt) == VEC_COND_EXPR); + tree indx_before_incr, indx_after_incr; + poly_uint64 nunits_out = TYPE_VECTOR_SUBPARTS (vectype); int scalar_precision = GET_MODE_PRECISION (SCALAR_TYPE_MODE (TREE_TYPE (vectype))); tree cr_index_scalar_type = make_unsigned_type (scalar_precision); @@ -4599,9 +4620,9 @@ vect_create_epilog_for_reduction (stmt_v (CCOMPARE). The then and else values mirror the main VEC_COND_EXPR: the reduction phi corresponds to NEW_PHI_TREE and the new values correspond to INDEX_BEFORE_INCR. */ - gcc_assert (STMT_VINFO_REDUC_IDX (stmt_info) >= 1); + gcc_assert (STMT_VINFO_REDUC_IDX (cond_info) >= 1); tree index_cond_expr; - if (STMT_VINFO_REDUC_IDX (stmt_info) == 2) + if (STMT_VINFO_REDUC_IDX (cond_info) == 2) index_cond_expr = build3 (VEC_COND_EXPR, cr_index_vector_type, ccompare, indx_before_incr, new_phi_tree); else @@ -4797,10 +4818,11 @@ vect_create_epilog_for_reduction (stmt_v be zero. */ /* Vector of {0, 0, 0,...}. */ - tree zero_vec = make_ssa_name (vectype); - tree zero_vec_rhs = build_zero_cst (vectype); - gimple *zero_vec_stmt = gimple_build_assign (zero_vec, zero_vec_rhs); - gsi_insert_before (&exit_gsi, zero_vec_stmt, GSI_SAME_STMT); + tree zero_vec = build_zero_cst (vectype); + + gimple_seq stmts = NULL; + new_phi_result = gimple_convert (&stmts, vectype, new_phi_result); + gsi_insert_seq_before (&exit_gsi, stmts, GSI_SAME_STMT); /* Find maximum value from the vector of found indexes. */ tree max_index = make_ssa_name (index_scalar_type); @@ -4868,7 +4890,7 @@ vect_create_epilog_for_reduction (stmt_v /* Convert the reduced value back to the result type and set as the result. */ - gimple_seq stmts = NULL; + stmts = NULL; new_temp = gimple_build (&stmts, VIEW_CONVERT_EXPR, scalar_type, data_reduc); gsi_insert_seq_before (&exit_gsi, stmts, GSI_SAME_STMT); Index: gcc/testsuite/gcc.dg/vect/pr92554.c =================================================================== --- gcc/testsuite/gcc.dg/vect/pr92554.c (nonexistent) +++ gcc/testsuite/gcc.dg/vect/pr92554.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +short int w9; + +void __attribute__ ((simd)) +zc (int in) +{ + int va = 1; + + w9 *= va != 0 ? in < 0 : 0; +}