From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 1FEB9385772D for ; Tue, 13 Jun 2023 08:42:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FEB9385772D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4EB792250B for ; Tue, 13 Jun 2023 08:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1686645735; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=10wlgxTbw2u1+og8sxeEp1zr2HAfi4jxge06eJvxtlg=; b=EPNhhmCWc7E3hCTQoR7jWddxud9F9n546w8PibiKBEMzeFfcYdhq1vG+9zjDa1AkgEin6h pdHDbGCLBUGzT3pcYFJvmyD4suL0Y3kRLololWrp8JqjQJS8EqAdj8siYAN/1owxe02bqo FG4iohOoaZE2+ewcz2sx/Uhf1VLhK50= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1686645735; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=10wlgxTbw2u1+og8sxeEp1zr2HAfi4jxge06eJvxtlg=; b=M+q6+M/7gQEO8/y5oesgfy0B2AdduSTEXfyDK+ngAplZpMTHKtmJNuzf2pphmyfGmxAGOU xkbCbEpLtbkQ1FAA== 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 451D22C141 for ; Tue, 13 Jun 2023 08:42:15 +0000 (UTC) Date: Tue, 13 Jun 2023 08:42:15 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/110232 - fix native interpret of vector User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-10.5 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 List-Id: Message-ID: <20230613084215.YKT5bW1P3keMZC7sDSUcQdQfqQhGQFq4-RIKG1L5S30@z> The following fixes native interpretation of a buffer as boolean vector with bit-precision elements such as AVX512 vectors. The check whether the buffer covers the whole vector was broken for bit-precision elements and the following instead implements it based on the vector type size. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/110232 * fold-const.cc (native_interpret_vector): Use TYPE_SIZE_UNIT to check whether the buffer covers the whole vector. * gcc.target/i386/pr110232.c: New testcase. --- gcc/fold-const.cc | 11 ++++------- gcc/testsuite/gcc.target/i386/pr110232.c | 12 ++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr110232.c diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 84b0d06b819..9ea055d4523 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -8796,16 +8796,13 @@ native_interpret_vector_part (tree type, const unsigned char *bytes, static tree native_interpret_vector (tree type, const unsigned char *ptr, unsigned int len) { - tree etype; - unsigned int size; - unsigned HOST_WIDE_INT count; + unsigned HOST_WIDE_INT size; - etype = TREE_TYPE (type); - size = GET_MODE_SIZE (SCALAR_TYPE_MODE (etype)); - if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&count) - || size * count > len) + if (!tree_to_poly_uint64 (TYPE_SIZE_UNIT (type)).is_constant (&size) + || size > len) return NULL_TREE; + unsigned HOST_WIDE_INT count = TYPE_VECTOR_SUBPARTS (type).to_constant (); return native_interpret_vector_part (type, ptr, len, count, 1); } diff --git a/gcc/testsuite/gcc.target/i386/pr110232.c b/gcc/testsuite/gcc.target/i386/pr110232.c new file mode 100644 index 00000000000..43b74b15e00 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr110232.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=znver4 --param vect-partial-vector-usage=2 -fno-vect-cost-model -fdump-tree-vect" } */ + +int a[4096]; + +void foo () +{ + for (int i = 1; i < 4095; ++i) + a[i] = 42; +} + +/* { dg-final { scan-tree-dump-not "VIEW_CONVERT_EXPR" "vect" } } */ -- 2.35.3