From nobody Mon Nov 23 04:52:26 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=aurel32.net ARC-Seal: i=1; a=rsa-sha256; t=1791483456; cv=none; d=zohomail.com; s=zohoarc; b=n+M02RMkTMR9fCsBtxVd9dxGBvudNfW3N61uySHb4u/aANxIz/v5X9+ahArBivNWI4tZsa6ldemDkxWI8OZyWOBQmOY5we5O9M7MuKKGCGXE5aGPOOd8wow+T37HGsd2qEDEh0woMi0ppb6Bb4PYaS0cl8k/gVQOpset2gBqWDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791483456; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=P2tn9G9mcxCdnPLAdLLYfiQWg978ZbzD5xGrgOtHzvg=; b=As6yb9dAJfAFxt2XHj21eUjZyK7+WsqdQ6TVysTy5S3lh5mXNyCXYkR1jcqTyT2Ld3n5bCD/MZ/hCBYIkRbO2Y+46sF14zq8AquszllYjlZRsXtsIjnhsd1t9aOK3sMotVsO2mF7j550SF1A7TaDLy3a6GxV1Idsk2qhxLtEzt0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791483456103935.001420932628; Thu, 8 Oct 2026 11:17:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xEsfp-0007at-3I; Thu, 08 Oct 2026 14:16:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEsfl-0007Tq-Hc; Thu, 08 Oct 2026 14:16:53 -0400 Received: from hall.aurel32.net ([2001:bc8:30d7:100::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xEsfj-0001jW-KF; Thu, 08 Oct 2026 14:16:52 -0400 Received: from authenticated user by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xEsfh-0000000AwCW-1mNB; Thu, 08 Oct 2026 20:16:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:Cc:To:From:Content-Type:From:Reply-To:Subject:Content-ID: Content-Description:In-Reply-To:References:X-Debbugs-Cc; bh=P2tn9G9mcxCdnPLAdLLYfiQWg978ZbzD5xGrgOtHzvg=; b=WPXSIcyIPVWXTxDVlJ3AN6CFMD /aaKFWeEXu5z+6SJTb1KZyaD8Su8tUVzhRiuyhrTaQT46EVovAmJc9Flng3X2vXJergpMpM9a2OkC xN8eOlGkx3f6z5JDMbDVSydJ7qBIf1Dz7eapQ8MYXg+pAHUz7gVV/W89KC2HKb38w4l7x0IhGvRJS VvJcWwr72PvZAGj27q7ycWuDzjLPM7upRsJbpJT1/4GU+OJoDfKZ1c/s6R5HzQHRrOsv8i+hMjyl4 kqoqSdvz0PVWUsNeCH2uZ75uIatW7Jk+kYe0XHXaYjN/GstrNqKlLk0RNANVzkdRaswW7mh8LQSCf qs+r6kRg==; From: Aurelien Jarno To: Palmer Dabbelt , Alistair Francis , Daniel Henrique Barboza , Richard Henderson , qemu-riscv@nongnu.org (open list:RISC-V TCG target), qemu-devel@nongnu.org (open list:All patches CC here) Cc: Aurelien Jarno Subject: [PATCH] tcg/riscv64: Fix vector constant matching for logical ops Date: Thu, 8 Oct 2026 20:16:40 +0200 Message-ID: <20261008181647.3015949-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2001:bc8:30d7:100::1; envelope-from=aurelien@aurel32.net; helo=hall.aurel32.net X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @aurel32.net) X-ZM-MESSAGEID: 1791483460799158500 Content-Type: text/plain; charset="utf-8" For logical vector operations (in the case of the RISC-V backend that corresponds to and_vec, or_vec and xor_vec), VECE is unused. However, tcg_target_const_match() always treat it as an element size to extract the corresponding constant element from the whole constant. This causes the following aarch64 instruction bic v4.8h, #0xf0 to be translated into the following op: ... and_vec v128,e8,tmp5,tmp4,v128$0xff0fff0fff0fff0f ... which is then translated to the following RISC-V instruction: vand.vi v1,v1,15 Fix that by, when VECE is 0 aka MO_8, only extracting the element if the it can actually be represented as a duplicated constant. Fixes: 5a63f5998791 ("tcg/riscv: Add support for basic vector opcodes") Signed-off-by: Aurelien Jarno --- tcg/riscv64/tcg-target.c.inc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tcg/riscv64/tcg-target.c.inc b/tcg/riscv64/tcg-target.c.inc index 14a397117a..382c4b6a28 100644 --- a/tcg/riscv64/tcg-target.c.inc +++ b/tcg/riscv64/tcg-target.c.inc @@ -392,8 +392,15 @@ static bool tcg_target_const_match(int64_t val, int ct, return 1; } if (type >=3D TCG_TYPE_V64) { - /* Val is replicated by VECE; extract the highest element. */ - val >>=3D (-8 << vece) & 63; + /* + * For vector logical operations, VECE is unused and equals to 0, = so + * we need to check that the constant can properly be represented = after + * replication. + */ + if ((vece !=3D MO_8) || (val =3D=3D (uint8_t)val * 0x0101010101010= 101ull)) { + /* Val is replicated by VECE; extract the highest element. */ + val >>=3D (-8 << vece) & 63; + } } /* * Sign extended from 12 bits: [-0x800, 0x7ff]. --=20 2.53.0