From patchwork Wed Dec 7 20:55:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Moreira Zinsly X-Patchwork-Id: 31049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp399537wrr; Wed, 7 Dec 2022 12:55:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf6gdLf+rHUe2Loh+XgCpAP6qTaEOFmAgAjF6tmz3cX7YmZohp6+7rC7tWbTq8AZw0ZgKP1y X-Received: by 2002:a17:906:78a:b0:7c0:d88b:4326 with SMTP id l10-20020a170906078a00b007c0d88b4326mr16325221ejc.108.1670446551931; Wed, 07 Dec 2022 12:55:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670446551; cv=none; d=google.com; s=arc-20160816; b=lnXf/A/Xek5bALXJb0PqZUIFAD5hiEVXeqqoNWsvSG36Rt8O6yoHdt5rl+HbW/2ioF U7W62hPZFgP6SvO2LEVHLD1gtjHv/HqZggXyOmKNpHktSjDNXtbm2JqlQ6EErXmaRWZL D1UCJH5ysPYYL4b6k8KqhJ4XfkH3+oXI+KftTeCHcGTBwucCCN1P8NxPgh3j43CXgY7V PkWZePsJnFeq6JseD7qCJlL01JZr5SCRz/BfSyJDZRH7u/cuf/IMO/G0X6S1ZFY/TP7x C9fEazOmcu0WEedBrlxXVrGbj57q9CWC4CMwa/Cd8jhncQlF8Zk/0WSkS+sff5HgAk3h JYaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=uMl263bZsUqkV49SbNCYGaFV2eB6lASfMSfyOtA9Ul0=; b=rbPm8liZFguw/iBL6pVrzqGmr6P2qiwZEPV1j2xDsbcvLiWdUHzmT1rnFlKEg+jyS/ 6tvWXQB0UBJlftUGznt3tBzwr7DKsjiFCKKc7WbuuqiZxZOncifrFc1ZSBwsh1xvLSs8 lH4Q6PsV7QgE8z8wwLf+PXArukS2qfEk6VPgbLg5w8SASfFJnXFRKSnIBkx9M4bTlZZ8 VwfO63CxbsCvlwdtvmcoPapjJ3pFZ4cnEjT+zJsuCoPDY1fqnBLqUGYGwpVblwmq5nO5 pIL4o2ewq/cGgL4/XUnNbAUMximZ8iIJVdFZ0CiLWjhDhLAW6896iCXMs07N+bq2FMs9 lSbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="kqr/kY1l"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id kz10-20020a17090777ca00b0073d81935416si10483822ejc.749.2022.12.07.12.55.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 12:55:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="kqr/kY1l"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A73B13893672 for ; Wed, 7 Dec 2022 20:55:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id C54E2383A0C5 for ; Wed, 7 Dec 2022 20:55:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C54E2383A0C5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com Received: by mail-oi1-x235.google.com with SMTP id m204so22113585oib.6 for ; Wed, 07 Dec 2022 12:55:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; 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=uMl263bZsUqkV49SbNCYGaFV2eB6lASfMSfyOtA9Ul0=; b=kqr/kY1l3GZaHcLAMZzoA1Y5TgYCrsQpXv1rI7FnsIF7NT7VUa1S2+in86Goh3yNvF JSEHbPn2cx3Wbgx7GPq9kANF83d8JIA4BsDMCNGb/MZiquY0TGUy/a3oLUw8hq7XhhZJ y9jQoGw1L3+i4b5yYBHO16ZXd8DHB/w3LQ2Il/jvjgZozoOg0vZjCaVaINwGm5ETlbg+ pmVV52shIXnS7iwulzkEbO7qzgwLyt6r8fhxvDk4TzyZEOzfC2NLGuZn2D7Lha7ft0NJ Vf5BlO4cHTRVbc7nNOVdRjRMQ5459yA+qOXFVamNxTyPpUtpmMTImXjHXdk/gmuUttXJ L1NA== 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=uMl263bZsUqkV49SbNCYGaFV2eB6lASfMSfyOtA9Ul0=; b=ZN/M3b+Cvk3ucj+Ygzd0dREkGgpS4nQwKGbwkK5QRwBotHXFrTvvgBo6phh9z58y6N 14+3swfunwhSzg616+WJwWmPOQFEjKvf4iaK9nlQpR6lbG60NbHccrcmfShQPnZU6gAj WRPHM4TLlqPPnEeDvBnUCGbyHBkYXUmaGQ0ybKwZPSdObiBMawm9TzML2f56xcdgrDzI 3xwjyOwZUm7F55GgfqSwghsY4pJ5oapC9Ob1ZXikdr12J4CettSMOyPT5nCmlbbU8fXP r7ZvG7Y0f8jz+F5D27+pRumsH6rVRs2mm8HPtcu4LMY9m/K9Z3Nwoj0o01HGXbMTQ5vE akFQ== X-Gm-Message-State: ANoB5pl6612AvMqF4/oT7hiSio6YBBm64kVVz1mTqVsFR51od0z1B4SM pSTpgriOaanIeiqmbkGxJiiUH8DgeFcSLSUC X-Received: by 2002:a05:6808:1381:b0:359:6b99:7c5e with SMTP id c1-20020a056808138100b003596b997c5emr35664160oiw.213.1670446523760; Wed, 07 Dec 2022 12:55:23 -0800 (PST) Received: from marvin.. ([2804:14d:baa4:50a9::1000]) by smtp.gmail.com with ESMTPSA id o77-20020a4a2c50000000b004a0a9fe51a4sm5689681ooo.42.2022.12.07.12.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 12:55:23 -0800 (PST) From: Raphael Moreira Zinsly To: gcc-patches@gcc.gnu.org Cc: jlaw@ventanamicro.com, Raphael Moreira Zinsly Subject: [PATCH] RISC-V: Produce better code with complex constants [PR95632] [PR106602] Date: Wed, 7 Dec 2022 17:55:17 -0300 Message-Id: <20221207205517.526182-1-rzinsly@ventanamicro.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751590163325155875?= X-GMAIL-MSGID: =?utf-8?q?1751590163325155875?= Due to RISC-V limitations on operations with big constants combine is failing to match such operations and is not being able to produce optimal code as it keeps splitting them. By pretending we can do those operations we can get more opportunities for simplification of surrounding instructions. 2022-12-06 Raphael Moreira Zinsly Jeff Law gcc/Changelog: PR target/95632 PR target/106602 * config/riscv/riscv.md: New pattern to simulate complex const_int loads. gcc/testsuite/ChangeLog: * gcc.target/riscv/pr95632.c: New test. * gcc.target/riscv/pr106602.c: Likewise. --- gcc/config/riscv/riscv.md | 16 ++++++++++++++++ gcc/testsuite/gcc.target/riscv/pr106602.c | 14 ++++++++++++++ gcc/testsuite/gcc.target/riscv/pr95632.c | 15 +++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/pr106602.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr95632.c diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index df57e2b0b4a..0a9b5ec22b0 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -1667,6 +1667,22 @@ MAX_MACHINE_MODE, &operands[3], TRUE); }) +;; Pretend to have the ability to load complex const_int in order to get +;; better code generation around them. +(define_insn_and_split "" + [(set (match_operand:GPR 0 "register_operand" "=r") + (match_operand:GPR 1 "splittable_const_int_operand" "i"))] + "cse_not_expected" + "#" + "&& 1" + [(const_int 0)] + +{ + riscv_move_integer (operands[0], operands[0], INTVAL (operands[1]), + mode, TRUE); + DONE; +}) + ;; 64-bit integer moves (define_expand "movdi" diff --git a/gcc/testsuite/gcc.target/riscv/pr106602.c b/gcc/testsuite/gcc.target/riscv/pr106602.c new file mode 100644 index 00000000000..83b70877012 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr106602.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64gc" } */ + +unsigned long +foo2 (unsigned long a) +{ + return (unsigned long)(unsigned int) a << 6; +} + +/* { dg-final { scan-assembler-times "slli\t" 1 } } */ +/* { dg-final { scan-assembler-times "srli\t" 1 } } */ +/* { dg-final { scan-assembler-not "\tli\t" } } */ +/* { dg-final { scan-assembler-not "addi\t" } } */ +/* { dg-final { scan-assembler-not "and\t" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/pr95632.c b/gcc/testsuite/gcc.target/riscv/pr95632.c new file mode 100644 index 00000000000..bd316ab1d7b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr95632.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32imafc -mabi=ilp32f" } */ + +unsigned short +foo (unsigned short crc) +{ + crc ^= 0x4002; + crc >>= 1; + crc |= 0x8000; + + return crc; +} + +/* { dg-final { scan-assembler-times "srli\t" 1 } } */ +/* { dg-final { scan-assembler-not "slli\t" } } */