From patchwork Thu Dec 5 09:42:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1204546 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-515201-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="WCq5yeyo"; 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 47T9kR3DbSz9sR8 for ; Thu, 5 Dec 2019 20:42:53 +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=rF4GVS/zqicVL7r4vK8KJU0In7dUzwG4RmrekkqbN1/IXHmrjOaBy mCpFOu5mFmJG8xe51+ru5ouPa0y2Y9jlN96QmlPQu3j5ffDFKOaNxnEiYj/3dN80 fe5kr3glEHnGW4v53GtXGw/gk3zkXMJbqGs5WgdMJnucPXfkbhH6FQ= 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=V+gmDuxwopsatHkuXSq74NYPW0M=; b=WCq5yeyoFu5u0P75deQu SadhE5WoTFlWgIf3CaZCne2dCehFIoNkoSvQitrtGppSE1gEHm4BJVK7OTlVSofu LpHuFMDKr9ekpoPpjY1+6Dn0BSRJRwBMQdbIpb8cEaJQxWN7reVEkaY/n+TTLvw4 aQPD+sdgQE9q6DeeSgY6BYg= Received: (qmail 30569 invoked by alias); 5 Dec 2019 09:42:46 -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 30561 invoked by uid 89); 5 Dec 2019 09:42:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.3 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=forwprop1 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; Thu, 05 Dec 2019 09:42:44 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0BC8CB417 for ; Thu, 5 Dec 2019 09:42:42 +0000 (UTC) Date: Thu, 5 Dec 2019 10:42:41 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR92803 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 The following patch fixes invariant vector construction in vector CTOR optimization. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2019-12-05 Richard Biener PR tree-optimization/92803 * tree-ssa-forwprop.c (simplify_vector_constructor): Fix invariant vector construction. * gcc.target/i386/pr92803.c: New testcase. Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c (revision 278985) +++ gcc/tree-ssa-forwprop.c (working copy) @@ -2286,24 +2286,28 @@ simplify_vector_constructor (gimple_stmt else if (orig[1] == error_mark_node && one_nonconstant) { - orig[1] = gimple_build_vector_from_val (&stmts, UNKNOWN_LOCATION, - type, one_nonconstant); /* ??? We can see if we can safely convert to the original element type. */ converted_orig1 = conv_code != ERROR_MARK; + orig[1] = gimple_build_vector_from_val (&stmts, UNKNOWN_LOCATION, + converted_orig1 + ? type : perm_type, + one_nonconstant); } else if (orig[1] == error_mark_node) { - tree_vector_builder vec (type, nelts, 1); - for (unsigned i = 0; i < nelts; ++i) - if (constants[i]) + /* ??? See if we can convert the vector to the original type. */ + converted_orig1 = conv_code != ERROR_MARK; + unsigned n = converted_orig1 ? nelts : refnelts; + tree_vector_builder vec (converted_orig1 + ? type : perm_type, n, 1); + for (unsigned i = 0; i < n; ++i) + if (i < nelts && constants[i]) vec.quick_push (constants[i]); else /* ??? Push a don't-care value. */ vec.quick_push (one_constant); orig[1] = vec.build (); - /* ??? See if we can convert the vector to the original type. */ - converted_orig1 = conv_code != ERROR_MARK; } tree blend_op2 = NULL_TREE; if (converted_orig1) Index: gcc/testsuite/gcc.target/i386/pr92803.c =================================================================== --- gcc/testsuite/gcc.target/i386/pr92803.c (revision 0) +++ gcc/testsuite/gcc.target/i386/pr92803.c (working copy) @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wno-psabi -mavx2 -fdump-tree-forwprop1" } */ + +typedef double v4df __attribute__((vector_size (32))); +typedef float v8sf __attribute__((vector_size (32))); +typedef float v4sf __attribute__((vector_size (16))); +typedef int v4si __attribute__((vector_size (16))); +typedef double v2df __attribute__((vector_size (16))); + +v2df +foo (v4df x, double *p, v2df y) +{ + return (v2df) { x[3], *p }; +} + +v4sf +bar (v4si x, float *p) +{ + return (v4sf) { x[0], x[1], x[2], *p }; +} + +v4sf +baz (v4si x) +{ + return (v4sf) { x[0], x[1], 3.0f, 1.0f }; +} + +v4sf +barf (v8sf x) +{ + return (v4sf) { x[4], x[5], 1.0f, 2.0f }; +} + +/* We expect all CTORs to turn into permutes, the FP converting ones + to two each with the one with constants possibly elided in the future + by converting 3.0f and 1.0f "back" to integers. */ +/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 6 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 5 "forwprop1" { xfail *-*-* } } } */