Message ID | 20230228050036.30601-1-mynameisxiaou@gmail.com |
---|---|
State | Committed |
Commit | 9debb240a4b1a711c0648fd9e4385dbde5ad45fd |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 954453858434 for <patchwork@sourceware.org>; Tue, 28 Feb 2023 05:01:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 954453858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677560474; bh=I8ZyVVtmi76lWT32gi8HpQy5eG1Jerem/qm7cQucuvo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dQQPsuA3BpSrQEPYDzqGFLx7xsg5gN7oHayJD8IMg4rtPqQPz+8hbnXsbFUHvnU5G TQa+oG3SoL6sObbsDTyc8bhyESC3E0kebjx3zMpBS6LFWsYW0RTzwiFvinWwXYW6t/ /Jr+Lr8Sxb+g08OGPbs2VQ45/fhGdTiQtMiOAMVU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id 8D58C3858D39 for <gcc-patches@gcc.gnu.org>; Tue, 28 Feb 2023 05:00:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D58C3858D39 Received: by mail-pj1-x1029.google.com with SMTP id u3-20020a17090a450300b00239db6d7d47so1315694pjg.4 for <gcc-patches@gcc.gnu.org>; Mon, 27 Feb 2023 21:00:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=I8ZyVVtmi76lWT32gi8HpQy5eG1Jerem/qm7cQucuvo=; b=AeRTJ85txGS1zkojSGjuXWnYE/u+aH3twD1a3QYzWMNns/HlrTlQqLRqyR9jIKSV+1 ToHVepW/d8Mz8mKsj+eEiaGpxWzy9xi7k663vwd8jFdB+KbOmLoIOKKlJSAMaWiQ6mZb 840U2VZgLyM4PDewiK+MSGaIf86S8euoZJ7drZWnQLo8FQrb5FsdYt2MSjNdle4gfy6a wBrLNw/dk2NKBHjuu3D7BnW9SRKLsyMoTFU5Hb4B/I0jZpVQlJClfngzUNPCJJEjwpdA nIma+xQq08llTYcECGY9RjzidQq7u7/TksLTb2OlYaCFLjUrt93WkSxHCbZ8hqe4g5R3 vzEw== X-Gm-Message-State: AO0yUKVdjxtm1vy1I7jJOMSQ68qJVJz4k36TzKj2N/opebXt7onWwY6Z vxBy8HXkLcUEOE+ZxYM4PGe6GXUh0T5ueJOjyhj5mA== X-Google-Smtp-Source: AK7set/0D6WxBI0HbVACE6JPvRmiZ7nzZnvv26dDOn6OmIqvm82BLlL4Fc64bYJiK76zVTUWiPR26g== X-Received: by 2002:a17:90a:7b8b:b0:234:289d:5e69 with SMTP id z11-20020a17090a7b8b00b00234289d5e69mr1352817pjc.2.1677560444263; Mon, 27 Feb 2023 21:00:44 -0800 (PST) Received: from localhost.localdomain ([47.246.101.59]) by smtp.gmail.com with ESMTPSA id g2-20020a170902868200b0019a5aa7eab0sm5418821plo.54.2023.02.27.21.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 21:00:43 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: philipp.tomsich@vrull.eu, kito.cheng@gmail.com, palmer@dabbelt.com, andrew@sifive.com, Lin Sinan <sinan.lin@linux.alibaba.com> Subject: [PATCH] RISC-V: Fix wrong partial subreg check for bsetidisi Date: Tue, 28 Feb 2023 13:00:36 +0800 Message-Id: <20230228050036.30601-1-mynameisxiaou@gmail.com> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Lin Sinan via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Lin Sinan <mynameisxiaou@gmail.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
RISC-V: Fix wrong partial subreg check for bsetidisi
|
|
Commit Message
Lin Sinan
Feb. 28, 2023, 5 a.m. UTC
From: Lin Sinan <sinan.lin@linux.alibaba.com>
The partial subreg check should be for subreg operand(operand 1) instead of
the immediate operand(operand 2). This change also fix pr68648.c in zbs.
gcc/ChangeLog:
* config/riscv/bitmanip.md: Fix wrong index in the check.
---
gcc/config/riscv/bitmanip.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
I encountered a miscompilation case with zbs, where bseti without sign extension emitted from bsetidisi pattern leads to wrong output. Take pr68648.c as an example, -march=rv64gc_zba_zbb_zbs -O3 did not generate sext.w in int bar (void) and led to a wrong value in a0. It seems that the partial subreg check is wrongly set to the immediate operand. int foo (void): li a0,123 ret int bar (void): addi sp,sp,-16 sd ra,8(sp) call foo # a0 123 li a5,248639488 # a0 123, a5 0xed1f000 addi a5,a5,11 # a0 123, a5 0xed1f00b slli a5,a5,14 # a0 123, a5 0x3b47c02c000 addi a5,a5,-8 # a0 123, a5 0x3b47c02bff8 ld ra,8(sp) or a0,a0,a5 # a0 0x3b47c02bffb, a5 0x3b47c02bff8 bseti a5,zero,32 # a0 0x3b47c02bffb, a5 0x100000000 addi a5,a5,-1 # a0 0x3b47c02bffb, a5 0x0ffffffff xor a0,a0,a5 # a0 0x3b483fd4004, a5 0x0ffffffff bseti a0,a0,0 # a0 0x3b483fd4005, a5 0x0ffffffff addi sp,sp,16 # sext.w a0,a0 is missing jr ra main: addi sp,sp,-16 sd ra,8(sp) call bar li a5,-2080555008 addi a5,a5,5 bne a0,a5,.L8 # a0 0x3b483fd4005, a5 0x83fd4005 ld ra,8(sp) li a0,0 addi sp,sp,16 jr ra .L8: call abort Lin Sinan <mynameisxiaou@gmail.com> 于2023年2月28日周二 13:00写道: > From: Lin Sinan <sinan.lin@linux.alibaba.com> > > The partial subreg check should be for subreg operand(operand 1) instead of > the immediate operand(operand 2). This change also fix pr68648.c in zbs. > > gcc/ChangeLog: > > * config/riscv/bitmanip.md: Fix wrong index in the check. > > --- > gcc/config/riscv/bitmanip.md | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md > index 14d18edbe62..58a86bd929f 100644 > --- a/gcc/config/riscv/bitmanip.md > +++ b/gcc/config/riscv/bitmanip.md > @@ -442,7 +442,7 @@ > (ior:DI (sign_extend:DI (match_operand:SI 1 "register_operand" > "r")) > (match_operand 2 "single_bit_mask_operand" "i")))] > "TARGET_ZBS && TARGET_64BIT > - && !partial_subreg_p (operands[2])" > + && !partial_subreg_p (operands[1])" > "bseti\t%0,%1,%S2" > [(set_attr "type" "bitmanip")]) > > -- > 2.34.1 > >
On Tue, 28 Feb 2023 at 06:00, Lin Sinan <mynameisxiaou@gmail.com> wrote: > > From: Lin Sinan <sinan.lin@linux.alibaba.com> > > The partial subreg check should be for subreg operand(operand 1) instead of > the immediate operand(operand 2). This change also fix pr68648.c in zbs. Good catch. Reviewed-by: <philipp.tomsich@vrull.eu>
Committed, thanks! On Tue, Feb 28, 2023 at 5:32 PM Philipp Tomsich <philipp.tomsich@vrull.eu> wrote: > > On Tue, 28 Feb 2023 at 06:00, Lin Sinan <mynameisxiaou@gmail.com> wrote: > > > > From: Lin Sinan <sinan.lin@linux.alibaba.com> > > > > The partial subreg check should be for subreg operand(operand 1) instead of > > the immediate operand(operand 2). This change also fix pr68648.c in zbs. > > Good catch. > Reviewed-by: <philipp.tomsich@vrull.eu>
diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index 14d18edbe62..58a86bd929f 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -442,7 +442,7 @@ (ior:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "r")) (match_operand 2 "single_bit_mask_operand" "i")))] "TARGET_ZBS && TARGET_64BIT - && !partial_subreg_p (operands[2])" + && !partial_subreg_p (operands[1])" "bseti\t%0,%1,%S2" [(set_attr "type" "bitmanip")])