From patchwork Mon Nov 21 11:57:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 60922 Return-Path: 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 9B3A4384F6FF for ; Mon, 21 Nov 2022 11:57:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 1164B38518B5 for ; Mon, 21 Nov 2022 11:57:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1164B38518B5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-lf1-x135.google.com with SMTP id j4so18530619lfk.0 for ; Mon, 21 Nov 2022 03:57:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WoCRp+jXhmsuBFl7OH+f6qo8NgUBnTWYnLO9pvby9Jc=; b=qOnFa72FKOOD31ri811CBxT91becFFB1ISDVYWcEqRHzz8oZqPMuPlFvPP28SbjkyH oj5BGJ67MvQyboz3EFfNGHb5njjMIY7T/sOSfMhqZUmEC1bpypk7/42eAbTOCyjs4PYe fp5d7ifYvJy9MbaMYCETDVjjki7oTJ+1HuPQJO/kkI6ZRsHvPS0S1AxzX/ebjOud/HrY jK8jeLOJ6/AoSyq8ejB1Eemst0yU5H7DQ7ln3KQGcBOlAmbG1NrR2QNjGYfVNB0uOwvE rYiFyRqXcb7Ih4nhf/2X6Vbw55pp+jrg9mIRPHLddPw33tVQ0pSZ2cg05uETjAsVCcrf IwTw== 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=WoCRp+jXhmsuBFl7OH+f6qo8NgUBnTWYnLO9pvby9Jc=; b=emEWXyl/6RTTp6hgqUgKGaDPmqgs9HgcZJFxT755pFuBSYliwwPAEyoSgrE9yms8xl b9z6OkPaZXNB9NvjDNWTYDbzPNDLbhQcL6Uy/bKkBoNgn7hC3OsFZ0MyjbJPsc4Ndg2X BhcHqtAYurKkaDi6TGoyJn6/OWAw3DcfCezUT9TgEyWKIiqsJOy0JXSTXeVEQCpdp2VY PblWmCAiIdYyTOKCNXL00WL4tQxBH5ZI7j4tkV0Nf2VumlDoX75V7qlPPuS60JNDTT5O SBAgBKeTR4c/JIp5z5uecFzaMPBZaZjKx1NkhUlO9ITdEBw+Lpi5IMWoASUs2nX05LmC zHgw== X-Gm-Message-State: ANoB5pllkKycpDZFl+qjWtsTHXCxH2W2VDPjV4W9z+TX1iQhEa0PLsyQ E/IqzMicMozsoc6oXQ57QzBdmDMVMwbVb8UT X-Google-Smtp-Source: AA0mqf5UIxqy+Hx2VOhxX0bL1+COAHIWjSNaXrGYaUgpEnc0WH6R2OPNCpcVOAF1QIqNUs56ycbYYw== X-Received: by 2002:a19:3845:0:b0:4a2:b387:8b19 with SMTP id d5-20020a193845000000b004a2b3878b19mr17981lfj.284.1669031844000; Mon, 21 Nov 2022 03:57:24 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id o15-20020ac24c4f000000b004a44ffb1050sm2000080lfk.171.2022.11.21.03.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 03:57:23 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Philipp Tomsich Subject: [PR107786 PATCH COMMITTED] RISC-V: Fix ICE in branch_shiftedarith_equals_zero Date: Mon, 21 Nov 2022 12:57:20 +0100 Message-Id: <20221121115720.2510778-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" With the recent improvements to the splitting of special cases of branch patterns on RISC-V, a dependency on an unmerged/in-discussion change for branch-equals-zero slipped in: this allowed a non-X mode to be presented to branch-equals-zero (where only X mode is permissible). This addresses the issue by wrapping the ANYI operand in a paradoxical SUBREG:X (the high bits can be safely ignored, as we we perform an and-immediate before the branch in the pattern). Tested against the GCC testsuite and committed as obvious. gcc/ChangeLog: PR target/107786 * config/riscv/riscv.md (*branch_shiftedarith_equals_zero): Wrap ANYI in a subreg, as our branch instructions only supports X. gcc/testsuite/ChangeLog: * gcc.target/riscv/pr107786-2.c: New test. * gcc.target/riscv/pr107786.c: New test. Signed-off-by: Philipp Tomsich --- gcc/config/riscv/riscv.md | 8 ++++---- gcc/testsuite/gcc.target/riscv/pr107786-2.c | 17 +++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr107786.c | 17 +++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/pr107786-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr107786.c diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index b7bb338ac04..df57e2b0b4a 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2224,12 +2224,12 @@ (define_insn_and_split "*branch_shiftedarith_equals_zero" (const_int 0)]) (label_ref (match_operand 0 "" "")) (pc))) - (clobber (match_scratch:ANYI 4 "=&r"))] - "INTVAL (operands[3]) >= 0 || !partial_subreg_p (operands[2])" + (clobber (match_scratch:X 4 "=&r"))] + "!SMALL_OPERAND (INTVAL (operands[3]))" "#" "&& reload_completed" - [(set (match_dup 4) (lshiftrt:ANYI (match_dup 2) (match_dup 6))) - (set (match_dup 4) (and:ANYI (match_dup 4) (match_dup 7))) + [(set (match_dup 4) (lshiftrt:X (subreg:X (match_dup 2) 0) (match_dup 6))) + (set (match_dup 4) (and:X (match_dup 4) (match_dup 7))) (set (pc) (if_then_else (match_op_dup 1 [(match_dup 4) (const_int 0)]) (label_ref (match_dup 0)) (pc)))] { diff --git a/gcc/testsuite/gcc.target/riscv/pr107786-2.c b/gcc/testsuite/gcc.target/riscv/pr107786-2.c new file mode 100644 index 00000000000..ee316a67f87 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr107786-2.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" } } */ + +int c; + +int main() { + for (;;) { + short h = c * 100; + if (h & 0x7ff0) + break; + } +} + +/* { dg-final { scan-assembler-times "andi\t" 1 } } */ +/* { dg-final { scan-assembler-times "srli\t" 1 } } */ + diff --git a/gcc/testsuite/gcc.target/riscv/pr107786.c b/gcc/testsuite/gcc.target/riscv/pr107786.c new file mode 100644 index 00000000000..5246ec7d338 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr107786.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" } } */ + +int c; + +int main() { + for (;;) { + char h = c * 100; + if (h) + break; + } +} + +/* { dg-final { scan-assembler-times "andi\t" 1 } } */ +/* { dg-final { scan-assembler-not "srli\t" } } */ +