From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: AMsMyM6S8/MOz1ZZFu/EbuiK29/NZTmhqjsOSvZ/J9JCrCinEh3+ziGhFEalmjPukqe1yolItzr5ug== 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 } } */ -- 2.34.1