From patchwork Fri Jun 28 01:14:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1953658 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GENtphrv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W9HYj31ssz1yhT for ; Fri, 28 Jun 2024 11:15:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 998353882065 for ; Fri, 28 Jun 2024 01:15:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by sourceware.org (Postfix) with ESMTPS id 6BC923830B45 for ; Fri, 28 Jun 2024 01:14:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BC923830B45 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6BC923830B45 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719537302; cv=none; b=AwepmmxpRPeBYBDHPfvZ7WPqxEFSA13cOp4liPz0wnzakuLo9aytvW01WuI1R0XlUDzgbr+lXEhq3TApuxk7oGBUnafn7iCy9hpogEmY0GTjU18/PZFDZEI1iUtzkA9//kLr+/v3NxdEFtie9mOiRpe/3KNVBAqlHwU+eIVgbVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719537302; c=relaxed/simple; bh=ul8grS+myUAFaNegA8RGarH95AgexlLK6QaukAm3WOg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qT97ybZn2kBkderR5qS2XrOJQlOm4TOkulP7wycNk07KqWHa27YDsMIZi+m2BBY/3Z+N2AocLwJ0jRmIILSp0O/Fu0GZqRTG1YwF/9hQdNmSVkkM5jG9A60Y4uZDfjX9hdtKGySQiAvFPczf2q01RuTDb4c7Q46aK8aoxurC/3k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719537299; x=1751073299; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ul8grS+myUAFaNegA8RGarH95AgexlLK6QaukAm3WOg=; b=GENtphrvkspg/KfwBKHBm2lak7c/K/vqK/UMJnOEonFTwi2ONTgGAcQF ZsplggfnfFnDllVfw7QghJbeQy3xhfDqeJlw2jIENsmH4ncBXuwtdne87 s4OgXXCNK+lMXXbQAUedTOi8XK7pFi9jxZJpqAsl4t3mCpd0NWSPtYIQE gG5XlYMb2/tsraAeGVANn8Tk7mGXBiRtnMrH/XWMOGzl5T+Nulwhr0njo 9kxZl9tMV1pBWFmERXeVxELi5skfGFInTRxDPnImJ1qI+ktD7qQyRyKkV wz6zpl65rm4PMralT5gWefuKpGkYg89sqNVw0HZoZIhl3xORZxaYIsfPi g==; X-CSE-ConnectionGUID: iqOgU21ORyGJhMY8xZCseQ== X-CSE-MsgGUID: QQno4sUFSjeU9G6rNE0OMA== X-IronPort-AV: E=McAfee;i="6700,10204,11116"; a="28103461" X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="28103461" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2024 18:14:58 -0700 X-CSE-ConnectionGUID: sSmfDkAYRUidnTQrnSa0zw== X-CSE-MsgGUID: jKmpj0w/Su2ndJZfvPODbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,167,1716274800"; d="scan'208";a="44981345" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orviesa006.jf.intel.com with ESMTP; 27 Jun 2024 18:14:56 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id B3DED100566F; Fri, 28 Jun 2024 09:14:55 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] Fix native_encode_vector_part for itype when TYPE_PRECISION (itype) == BITS_PER_UNIT Date: Fri, 28 Jun 2024 09:14:55 +0800 Message-Id: <20240628011455.3980128-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP 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+incoming=patchwork.ozlabs.org@gcc.gnu.org for the testcase in the PR115406, here is part of the dump. char D.4882; vector(1) _1; vector(1) signed char _2; char _5; : _1 = { -1 }; When assign { -1 } to vector(1} {signed-boolean:8}, Since TYPE_PRECISION (itype) <= BITS_PER_UNIT, so it set each bit of dest with each vector elemnet. But i think the bit setting should only apply for TYPE_PRECISION (itype) < BITS_PER_UNIT. .i.e for vector(1). , it will be assigned as -1, instead of 1. Is there any specific reason vector(1) is handled differently from vector<1> ? Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: PR middle-end/115406 * fold-const.cc (native_encode_vector_part): Don't set each bit to the dest when TYPE_PRECISION (itype) == BITS_PER_UNIT. gcc/testsuite/ChangeLog: * gcc.target/i386/pr115406.c: New test. --- gcc/fold-const.cc | 2 +- gcc/testsuite/gcc.target/i386/pr115406.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr115406.c diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 710d697c021..0f045f851d1 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -8077,7 +8077,7 @@ native_encode_vector_part (const_tree expr, unsigned char *ptr, int len, { tree itype = TREE_TYPE (TREE_TYPE (expr)); if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (expr)) - && TYPE_PRECISION (itype) <= BITS_PER_UNIT) + && TYPE_PRECISION (itype) < BITS_PER_UNIT) { /* This is the only case in which elements can be smaller than a byte. Element 0 is always in the lsb of the containing byte. */ diff --git a/gcc/testsuite/gcc.target/i386/pr115406.c b/gcc/testsuite/gcc.target/i386/pr115406.c new file mode 100644 index 00000000000..623dff06fc3 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr115406.c @@ -0,0 +1,23 @@ +/* { dg-do run } */ +/* { dg-options "-O0 -mavx512f" } */ +/* { dg-require-effective-target avx512f } */ + +typedef __attribute__((__vector_size__ (1))) char V; + +char +foo (V v) +{ + return ((V) v == v)[0]; +} + +int +main () +{ + if (!__builtin_cpu_supports ("avx512f")) + return 0; + + char x = foo ((V) { }); + if (x != -1) + __builtin_abort (); + return 0; +}