From patchwork Tue Nov 21 14:35:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 167795 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp665172vqb; Tue, 21 Nov 2023 06:35:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEe/s5q1pLu9EqDSy1r7DWs+XxBFuwBwMnhT/9MiJ0ecN6i3UTlQPMvwwcjNICEhDq0PKj3 X-Received: by 2002:ad4:5d64:0:b0:66d:6919:7bf7 with SMTP id fn4-20020ad45d64000000b0066d69197bf7mr12721993qvb.27.1700577329624; Tue, 21 Nov 2023 06:35:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700577329; cv=pass; d=google.com; s=arc-20160816; b=x2IvyZjgAn/6hnppbUPpLE1pnSBkITnjrVuNRZ67z80VGa1ecm9QPA2lSzPdY71mFU NQsiwVxsQCIgzusfNhMxPar+1XDhVrzbqbWluYLXk0DLEWt511Ly6lts0KJnViiSMQvj QKy33o8fUx57zui1FJNfoXfIR60n3keBYo1uOcaceBEPd1ApKuRtQ9crNFHaxq60PupM khJijy3L7qP6CxVluZs7toe5MNR9O57f1mAaCQF6AK8HBaPfgCLRRKDfrjS9dqqKmw6c G4RTcBm19HvsT+Oeb+IRZvPxDlFkmPndsVvRVJIimY+NqXs9wxFgo5YZdMbDfBDEoj4d x2pw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:subject:cc:to:from:date:dkim-signature:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=BrEQr5DZMRircRcR4AsGjkE7J1DW2z6J/fSFVMqY+uA=; fh=Hz/QWAL2vMAbrm3W16QrnQrLktFWGNewssxaKtdN1w4=; b=mkW25RtfLTwa6hWnaOGx7WG8Fk3nhOLLpiwupK9l0KQHBmQ7pWkbP0gbwJSEciCz9c IHM/45QlKzt3tAfDY5zraGb9PTpsw1kr8ZqGosTX5CXZFCL8Od4ZwiJOmyoA80C0KR4M Fku8lcPRwIurimI3Jgp4KeuxxQ27oK7Yax7n8et/Fk/rwBKPrPrUeAfqkfOvOuMQ3ead sn1X7Ct3P09gaCU+C4jW5n0nN3/KpPBOGCqTIEEhC6Cn7bEv1MQh49O4gYiU7wN55IjA s1A6Ys4FUXc0GmW6bJHVsyC8O+ZRQG9ooq0j5iJ3FIOGf6cA/BD0pt8ItAHYIDbaQcU1 ElSA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=v27TVa5O; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=zbm+wUiV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bl18-20020a05620a1a9200b00773e066060csi9685265qkb.296.2023.11.21.06.35.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 06:35:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=v27TVa5O; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=zbm+wUiV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B1003858C30 for ; Tue, 21 Nov 2023 14:35:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id A49593858415 for ; Tue, 21 Nov 2023 14:35:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A49593858415 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A49593858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700577305; cv=none; b=Hx0DF3iy+h8jA0SipAmn4vsalkSP0vTGemis8v854sqOqKlFgmdCtvaqyifobeeVlzRBcZJjLeNis8eQB43K1LNpLOtFzI2qmwPWAjmpELAqlnfT3tFEeh1B/n955/d9l8MXOhagoyQIf7wNdxj0m/yh2ttneYi1gYp0I0PN73I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700577305; c=relaxed/simple; bh=oUnE2bqi51AlWIQ+zz++a/KMRGUd1eWqWIyLQupKZ6s=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=ev9RK2GXJGgXwxfus+z3fqHFoBiwyHvILmVv3WYwNy6bE+xZW/aLmMKbuoMg1L+bsPYJRIusnze5id4nKgzyBl5zCNrMQtueNn3p34Ig1qVC54CrrfrJjLsSULbnVgFmd4djalmcPk9F4pjdj30H/qcMKsAk3nUrgT9YesbZ1X4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6EA571F8B8; Tue, 21 Nov 2023 14:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700577302; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=BrEQr5DZMRircRcR4AsGjkE7J1DW2z6J/fSFVMqY+uA=; b=v27TVa5OfDenVfBxtkArLrirEpDrVZhGdBKmlvxFN3QbKpb7/xx0rT9W57mS/KDSaNVmaK /yhi3zKNsUtCQQSFplxq/vIsb+HuYXh3GdICROnLPyyzL/plRJkChfD/i5enK64GN6/FeT 7z3m9EZGR9aLM9AwgLduI4MrMT5iiKU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700577302; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=BrEQr5DZMRircRcR4AsGjkE7J1DW2z6J/fSFVMqY+uA=; b=zbm+wUiVtDO9Wv/TmYfdgciVpu11Z1SWUt/dBY9TB8VE9XXeFTRwHa2dy29icrKYoBsGpv qKGkOnQ14IPq3bAA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 730C72C16D; Tue, 21 Nov 2023 14:35:02 +0000 (UTC) Date: Tue, 21 Nov 2023 14:35:02 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] tree-optimization/112623 - forwprop VEC_PACK_TRUNC generation User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spamd-Bar: ++++++++++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=none; spf=softfail (smtp-out2.suse.de: 149.44.160.134 is neither permitted nor denied by domain of rguenther@suse.de) smtp.mailfrom=rguenther@suse.de X-Rspamd-Server: rspamd1 X-Spamd-Result: default: False [16.49 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(1.20)[suse.de]; R_SPF_SOFTFAIL(4.60)[~all:c]; R_RATELIMIT(0.00)[rip(RLa6h5sh378tcam5q78u)]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWO(0.00)[2]; VIOLATED_DIRECT_SPF(3.50)[]; RWL_MAILSPIKE_GOOD(-1.00)[149.44.160.134:from]; NEURAL_SPAM_LONG(3.50)[1.000]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 16.49 X-Rspamd-Queue-Id: 6EA571F8B8 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20231121143529.5B1003858C30@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783184573514805515 X-GMAIL-MSGID: 1783184573514805515 For vec_pack_trunc patterns there can be an ambiguity for the source mode for BFmode vs HFmode. The vectorizer checks the insns operand mode for this, the following makes forwprop do the same. That of course doesn't help if the target supports both conversions. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? Thanks, Richard. PR tree-optimization/112623 * tree-ssa-forwprop.cc (simplify_vector_constructor): Check the source mode of the insn for vector pack/unpacks. * gcc.target/i386/pr112623.c: New testcase. --- gcc/testsuite/gcc.target/i386/pr112623.c | 11 +++++++++++ gcc/tree-ssa-forwprop.cc | 13 +++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr112623.c diff --git a/gcc/testsuite/gcc.target/i386/pr112623.c b/gcc/testsuite/gcc.target/i386/pr112623.c new file mode 100644 index 00000000000..c4ebacec85c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr112623.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O -mavx512vl -mavx512fp16" } */ + +typedef __bf16 __attribute__((__vector_size__ (16))) BF; +typedef float __attribute__((__vector_size__ (32))) F; + +BF +foo (F f) +{ + return __builtin_convertvector (f, BF); +} diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index d39dfc1065f..0fb21e58138 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -47,6 +47,8 @@ along with GCC; see the file COPYING3. If not see #include "tree-cfgcleanup.h" #include "cfganal.h" #include "optabs-tree.h" +#include "insn-config.h" +#include "recog.h" #include "tree-vector-builder.h" #include "vec-perm-indices.h" #include "internal-fn.h" @@ -2978,6 +2980,7 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) /* Only few targets implement direct conversion patterns so try some simple special cases via VEC_[UN]PACK[_FLOAT]_LO_EXPR. */ optab optab; + insn_code icode; tree halfvectype, dblvectype; enum tree_code unpack_op; @@ -3015,8 +3018,9 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) && (optab = optab_for_tree_code (unpack_op, dblvectype, optab_default)) - && (optab_handler (optab, TYPE_MODE (dblvectype)) - != CODE_FOR_nothing)) + && ((icode = optab_handler (optab, TYPE_MODE (dblvectype))) + != CODE_FOR_nothing) + && (insn_data[icode].operand[0].mode == TYPE_MODE (type))) { gimple_seq stmts = NULL; tree dbl; @@ -3054,8 +3058,9 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) && (optab = optab_for_tree_code (VEC_PACK_TRUNC_EXPR, halfvectype, optab_default)) - && (optab_handler (optab, TYPE_MODE (halfvectype)) - != CODE_FOR_nothing)) + && ((icode = optab_handler (optab, TYPE_MODE (halfvectype))) + != CODE_FOR_nothing) + && (insn_data[icode].operand[0].mode == TYPE_MODE (type))) { gimple_seq stmts = NULL; tree low = gimple_build (&stmts, BIT_FIELD_REF, halfvectype,