From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 38610 invoked by alias); 4 Sep 2017 14:09:12 -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 38346 invoked by uid 89); 4 Sep 2017 14:09:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,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, 04 Sep 2017 14:09:06 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AC076ABB4 for ; Mon, 4 Sep 2017 14:09:04 +0000 (UTC) Date: Mon, 04 Sep 2017 14:09:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR82084 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: 2017-09/txt/msg00183.txt.bz2 The following fixes vectorization of stores from wide-char STRING_CSTs which native_encode_string doesn't handle (will post a preliminary patch for that and trunk later). Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk sofar. Richard. 2017-09-04 Richard Biener PR tree-optimization/82084 * fold-const.h (can_native_encode_string_p): Declare. * fold-const.c (can_native_encode_string_p): Factor out from ... (native_encode_string): ... here. * tree-vect-stmts.c (vectorizable_store): Call it to avoid vectorizing stores from constants we later cannot handle. * g++.dg/torture/pr82084.C: New testcase. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 251649) +++ gcc/fold-const.c (working copy) @@ -7184,16 +7184,10 @@ native_encode_vector (const_tree expr, u static int native_encode_string (const_tree expr, unsigned char *ptr, int len, int off) { - tree type = TREE_TYPE (expr); - HOST_WIDE_INT total_bytes; - - if (TREE_CODE (type) != ARRAY_TYPE - || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE - || (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (type))) - != BITS_PER_UNIT) - || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type))) + if (! can_native_encode_string_p (expr)) return 0; - total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (type)); + + HOST_WIDE_INT total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (expr))); if ((off == -1 && total_bytes > len) || off >= total_bytes) return 0; @@ -7487,6 +7481,23 @@ can_native_encode_type_p (tree type) } } +/* Return true iff a STRING_CST S is accepted by + native_encode_expr. */ + +bool +can_native_encode_string_p (const_tree expr) +{ + tree type = TREE_TYPE (expr); + + if (TREE_CODE (type) != ARRAY_TYPE + || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE + || (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (type))) + != BITS_PER_UNIT) + || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type))) + return false; + return true; +} + /* Fold a VIEW_CONVERT_EXPR of a constant expression EXPR to type TYPE at compile-time. If we're unable to perform the conversion return NULL_TREE. */ Index: gcc/fold-const.h =================================================================== --- gcc/fold-const.h (revision 251649) +++ gcc/fold-const.h (working copy) @@ -28,6 +28,7 @@ extern int folding_initializer; extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1); extern tree native_interpret_expr (tree, const unsigned char *, int); extern bool can_native_encode_type_p (tree); +extern bool can_native_encode_string_p (const_tree); /* Fold constants as much as possible in an expression. Returns the simplified expression. Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c (revision 251649) +++ gcc/tree-vect-stmts.c (working copy) @@ -5733,6 +5733,12 @@ vectorizable_store (gimple *stmt, gimple op = gimple_assign_rhs1 (stmt); + /* In the case this is a store from a STRING_CST make sure + native_encode_expr can handle it. */ + if (TREE_CODE (op) == STRING_CST + && ! can_native_encode_string_p (op)) + return false; + if (!vect_is_simple_use (op, vinfo, &def_stmt, &dt, &rhs_vectype)) { if (dump_enabled_p ()) Index: gcc/testsuite/g++.dg/torture/pr82084.C =================================================================== --- gcc/testsuite/g++.dg/torture/pr82084.C (revision 0) +++ gcc/testsuite/g++.dg/torture/pr82084.C (working copy) @@ -0,0 +1,9 @@ +// { dg-do compile } + +#include +int main() +{ + wchar_t strs[4][2]= { L"A", L"B", L"C" , L"D"}; + std::wstring ss(strs[0]); + return 0; +}