From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9970 invoked by alias); 21 Jan 2019 14:47:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 9951 invoked by uid 89); 21 Jan 2019 14:47:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,KAM_NUMSUBJECT,SPF_PASS autolearn=ham version=3.3.2 spammy= 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; Mon, 21 Jan 2019 14:47:11 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 37B1BAF66 for ; Mon, 21 Jan 2019 14:47:09 +0000 (UTC) Date: Mon, 21 Jan 2019 14:47:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR88934 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2019-01/txt/msg01203.txt.bz2 This fixes PR88934 and makes vect_mask_constant_operand_p a little bit more sensible by consistently looking at the first comparison operand rather than a different one depending on whether this is a COND_EXPR vs. a tcc_comparison one. The first one happens to be non-constant if any is. We'll still fail miserably if one is invariant and the other is not. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2019-01-21 Richard Biener PR tree-optimization/88934 * tree-vect-slp.c (vect_mask_constant_operand_p): Always look at the possibly non-constant operand. (vect_get_constant_vectors): Adjust. * gfortran.dg/pr88934.f90: New testcase. Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c (revision 268110) +++ gcc/tree-vect-slp.c (working copy) @@ -3109,25 +3109,21 @@ vect_slp_bb (basic_block bb) } -/* Return 1 if vector type of boolean constant which is OPNUM - operand in statement STMT_VINFO is a boolean vector. */ +/* Return 1 if vector type STMT_VINFO is a boolean vector. */ static bool -vect_mask_constant_operand_p (stmt_vec_info stmt_vinfo, int opnum) +vect_mask_constant_operand_p (stmt_vec_info stmt_vinfo) { enum tree_code code = gimple_expr_code (stmt_vinfo->stmt); tree op, vectype; enum vect_def_type dt; /* For comparison and COND_EXPR type is chosen depending - on the other comparison operand. */ + on the non-constant other comparison operand. */ if (TREE_CODE_CLASS (code) == tcc_comparison) { gassign *stmt = as_a (stmt_vinfo->stmt); - if (opnum) - op = gimple_assign_rhs1 (stmt); - else - op = gimple_assign_rhs2 (stmt); + op = gimple_assign_rhs1 (stmt); if (!vect_is_simple_use (op, stmt_vinfo->vinfo, &dt, &vectype)) gcc_unreachable (); @@ -3142,8 +3138,6 @@ vect_mask_constant_operand_p (stmt_vec_i if (TREE_CODE (cond) == SSA_NAME) op = cond; - else if (opnum) - op = TREE_OPERAND (cond, 1); else op = TREE_OPERAND (cond, 0); @@ -3302,7 +3296,7 @@ vect_get_constant_vectors (tree op, slp_ /* Check if vector type is a boolean vector. */ if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op)) - && vect_mask_constant_operand_p (stmt_vinfo, op_num)) + && vect_mask_constant_operand_p (stmt_vinfo)) vector_type = build_same_sized_truth_vector_type (STMT_VINFO_VECTYPE (stmt_vinfo)); else Index: gcc/testsuite/gfortran.dg/pr88934.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr88934.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr88934.f90 (working copy) @@ -0,0 +1,23 @@ +! { dg-do compile } +! { dg-options "-O -ftree-vectorize" } +! { dg-additional-options "-mvsx" { target powerpc*-*-* } } +integer, parameter :: a=3 + integer , dimension(a,a) :: b + logical, dimension(a,a) :: c + do i=0,1 + b = ltoi(c) + do j=0,if + if (anymatmul(b) /= 0) then + end if + end do + end do +contains + elemental function ltoi(d) + logical, intent(in) :: d + if (d) then + ltoi = 1 + else + ltoi = 0 + end if + end +end