From patchwork Tue Nov 8 19:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 17195 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2917999wru; Tue, 8 Nov 2022 11:57:26 -0800 (PST) X-Google-Smtp-Source: AMsMyM4FSWyfi93FuOJ1/27VuYppUqxddEzmlzay7t/vEKYV4Bq1hrFn1sIyAVCsh94k0o0OOINX X-Received: by 2002:aa7:c0cf:0:b0:463:8ba0:522f with SMTP id j15-20020aa7c0cf000000b004638ba0522fmr46199391edp.176.1667937446466; Tue, 08 Nov 2022 11:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667937446; cv=none; d=google.com; s=arc-20160816; b=rSW+p1Agr/91gq5B6pvLEvRaJIBBT4qXOsmtDmcj9A7hT6G/MlPkCvQNCTWgblBH15 5xvug6nXANK0r0L77M/8Ax41eLye0Dp0wvP2g5XCQg2YFSHbGc6vkmkJWb/muy80y1ct LABpGWZq2733vbVSKo3qCiK9Pb7qkVV9itpZFVmJFquiHMjOwTXyBusMqbmCjo+v5I05 D0Jicn0qsLJJEjKfy1Q/yBNlsiyUvK07PAfhXabwduwl4/5CZRNmACAu/1G9kIScilCp DG+9mD0wNwww9QNJfbqD3AROhZJwlMUv78pwVnzx3G4X/sFgm2TPhgpB//l8rFHywv/0 J8kw== 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=19OPoR+0P83uMgNTHeOH7z39xAeJ1vPYoGg7F65+BOA=; b=XSxw2qqI0wcRgM2ijkM46zmOtpLypx5NyXuZtULpDMDVZhD9PXFkGaWcnP3ah4GSyl O4ZubLpnHHJ/ZPKfFE0T4mlrjrB1FW/udL3kjsLO9IsIGNpXaLjo4Rr4GR28hl5Nvxyp i7jc3bxx8BH3uz9pQlQwY6X3AZ3QYnoWshkNcc/++uqojgdbURPw5fe8iXlDEOyRtUL4 yKApTo+irjSU4Uxpm4+nKeAbzFQZg/073jhrGR/o3wAcNgz9bEv3FpojA7re3eA17L+u PP1B7TTl6o3LsegUwqnccFJHEz/jgJmEgS4b1M6PIk8lZTP37z99zED/p+IMN0C7zT5U HC1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=c7CqRKD5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y25-20020a170906071900b0078dcd30bc94si10656128ejb.529.2022.11.08.11.57.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 11:57:26 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=c7CqRKD5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B5A2A3857022 for ; Tue, 8 Nov 2022 19:56:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 4D51D3857B82 for ; Tue, 8 Nov 2022 19:56:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D51D3857B82 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-x134.google.com with SMTP id a29so4142507lfj.9 for ; Tue, 08 Nov 2022 11:56:24 -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=19OPoR+0P83uMgNTHeOH7z39xAeJ1vPYoGg7F65+BOA=; b=c7CqRKD5T0Yw6xFUtrNjj+JoBxkt9cyr70MeLKBIhhQu127ALg4mLLZ9sj4sQVdFE1 Yuq7Z+J6FDk1Xvw8ZBF6+/ujTkHmh4QaKbnqEWInSR6brhF6Lel1zicJ3zMvj+mjEClW kai+h9f/+LprLspcanrp2DWnOb4vN4ROvs1kgzIfaDT0mwfFKIJJ72Vgm6ABFSX8LY0P u/vreP0H0O9sUd1y2AomMVL4OkmeoXctBzCBlPeMZK3NqUj5L+bNGg62+qu3OrfypUNU Mw25v9GFEqvshS+z0sLKkkYyengRj8BIEXswFCFl1dF3/PzA3hzjdV4k+ZzbuoufPGEg ZaqQ== 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=19OPoR+0P83uMgNTHeOH7z39xAeJ1vPYoGg7F65+BOA=; b=b3O0sel5sopqTEx78diRPmLC649nDvTQqrXAUFsV2Pyaci/xkxhNmshbxPwQD7/a6U E2Kwq/ljL1oQrMkFBMbQ8YcP6aPXjnO56f5DKPJBedTZwJHVIHrH0KN8lv7f6PzKrpEh RZa/qSPtY5OtY+YlII0E9rcQRvPiZtq5WHdX+hHJJ2IJAY92vOInUIials8QkhcYlbct wNao2CxfEIxrHStc6P72eqeZSv/OOUxQr0AuiiCznImbo+kclSktP1C+KRyAwnnV2FEy c6MJX4lLbtAEMBwBeb0UyTqgrRanBoRTngKe0r+OKWxdkqkYa+WDte4rsM5isRTTaYin M5hQ== X-Gm-Message-State: ACrzQf2AGPDpCbnQe6MV0XbWrmxtx/gm5UWwAYdG9LPcilvQJGbVZnoN yIiLRD7MNQmnXFCJYLyW8azKLSNTuFlo5CYw X-Received: by 2002:a05:6512:2209:b0:4a2:6b07:9a97 with SMTP id h9-20020a056512220900b004a26b079a97mr19314645lfu.509.1667937382541; Tue, 08 Nov 2022 11:56:22 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id u27-20020ac25bdb000000b004a9b9ccfbe6sm1908315lfn.51.2022.11.08.11.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 11:56:21 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Vineet Gupta , Palmer Dabbelt , Christoph Muellner , Jeff Law , Philipp Tomsich Subject: [PATCH] RISC-V: split to allow formation of sh[123]add before divw Date: Tue, 8 Nov 2022 20:56:17 +0100 Message-Id: <20221108195617.2701379-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, LIKELY_SPAM_BODY, 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?1748959175813993550?= X-GMAIL-MSGID: =?utf-8?q?1748959175813993550?= When using strength-reduction, we will reduce a multiplication to a sequence of shifts and adds. If this is performed with 32-bit types and followed by a division, the lack of w-form sh[123]add will make combination impossible and lead to a slli + addw being generated. Split the sequence with the knowledge that a w-form div will perform implicit sign-extensions. gcc/ChangeLog: * config/riscv/bitmanip.md: Add a define_split to optimize slliw + addiw + divw into sh[123]add + divw. gcc/testsuite/ChangeLog: * gcc.target/riscv/zba-shNadd-05.c: New test. Signed-off-by: Philipp Tomsich --- gcc/config/riscv/bitmanip.md | 17 +++++++++++++++++ gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index 30dabdf8ddc..726a07b0d90 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -39,6 +39,23 @@ [(set_attr "type" "bitmanip") (set_attr "mode" "")]) +; When using strength-reduction, we will reduce a multiplication to a +; sequence of shifts and adds. If this is performed with 32-bit types +; and followed by a division, the lack of w-form sh[123]add will make +; combination impossible and lead to a slli + addw being generated. +; Split the sequence with the knowledge that a w-form div will perform +; implicit sign-extensions. +(define_split + [(set (match_operand:DI 0 "register_operand") + (sign_extend:DI (div:SI (plus:SI (subreg:SI (ashift:DI (match_operand:DI 1 "register_operand") + (match_operand:QI 2 "imm123_operand")) 0) + (subreg:SI (match_operand:DI 3 "register_operand") 0)) + (subreg:SI (match_operand:DI 4 "register_operand") 0)))) + (clobber (match_operand:DI 5 "register_operand"))] + "TARGET_64BIT && TARGET_ZBA" + [(set (match_dup 5) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3))) + (set (match_dup 0) (sign_extend:DI (div:SI (subreg:SI (match_dup 5) 0) (subreg:SI (match_dup 4) 0))))]) + (define_insn "*shNadduw" [(set (match_operand:DI 0 "register_operand" "=r") (plus:DI diff --git a/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c new file mode 100644 index 00000000000..271c3a8c0ac --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zba -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-Oz" "-Og" } } */ + +long long f(int a, int b) +{ + return (a * 3) / b; +} + +/* { dg-final { scan-assembler-times "sh1add\t" 1 } } */ +/* { dg-final { scan-assembler-times "divw\t" 1 } } */