From patchwork Thu Nov 10 21:35:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 18331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp387297wru; Thu, 10 Nov 2022 13:35:52 -0800 (PST) X-Google-Smtp-Source: AMsMyM76wInoKfzprLXQ9wXugQnVyHqM+NabFPLHRUPrVzXxrhvRdazND6xyLTYcqTpEwnqPAinr X-Received: by 2002:a05:6402:2903:b0:463:19ca:a573 with SMTP id ee3-20020a056402290300b0046319caa573mr3505765edb.31.1668116152081; Thu, 10 Nov 2022 13:35:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668116152; cv=none; d=google.com; s=arc-20160816; b=Kctw0XVbNKJHYGi7RT34M+xZpKjVs6fExJX06RN1OgtiRN3gfnNAe87eyGUq2+3wwI 1KoxsUeAw47KVgvjS/VKSGgcev51q1o8IVo3K0DQ/Iq9dBZe36uRWnux1MrwjAvU7DDr JUy4Ru/wvd2iZKkaM1soifSm0p7p/AIHz3ZA+wTZqb+kQX9Ze5TUh1Rx7H8Rxidhd20e zfQ7EIWetBLvk61K7+RxraDK6ZYxkeeFURSjjEovTc4ysL3nNrXgf7DqJYrxsO/2Vwqp U/1XuB4VjMwQKJmo0OHgMdseuAK3m/3J19ZlMK9grQEYXzc3mHehDfgPcPIddO8hGjDs CDnw== 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=bI7Tt+kQqmaWIzmVW3/XPwRrXmUgc5fCNRUuANTjyBs=; b=B62iDgQtoJKn/HurECiU493c2wBcTxK0ykSSvxlP8IXM92kMbD4NVkmc4EWvUFcJTO FTm2Z1jxj9IJ8oGOHDRipE5kKyP+w2X9RxGLVXSjx8VPbqDsIMt9/ume8jMXvgsvtlJ+ qs9eMAaIGo4nZr4Gfa1n8HkOAbmWKYfk+gmbiGXz5D4Vy//eiBNoIMsX2ClU3Ap3MuWg bNV+mAUdudNhqq6y5DMpaWtY7FdnqVLWdXNewQdrD3+od9GEZc7rTdvPQon32nZNJuTL AL0J1MnTtJYwOKEdr11C46nNAUA8yPApwE7ifShBIpaArniPs053Isi3CGh8x9PPlIu5 ekLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=FazyEQsJ; 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 g10-20020a056402090a00b00461b2c3c4acsi696885edz.515.2022.11.10.13.35.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 13:35:52 -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=FazyEQsJ; 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 684553846404 for ; Thu, 10 Nov 2022 21:35:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 990A13846469 for ; Thu, 10 Nov 2022 21:35:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 990A13846469 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-lj1-x229.google.com with SMTP id b9so2438285ljr.5 for ; Thu, 10 Nov 2022 13:35:05 -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=bI7Tt+kQqmaWIzmVW3/XPwRrXmUgc5fCNRUuANTjyBs=; b=FazyEQsJyCsziS+VKvTqpw/qRWSjRRX/OUKcvDvsfTXxrCwfhnNoKTCky/uz+oKLva CP/y3pVkHr/hU8BJv/fuFsMcWEqiS1V53SvgmCajkJG6FP0P9u5OMDOOtZSmdtcH8Gtr QOAtYNQCXwuD7PJ7GVNR26uL5tt87BKVNWxlDKCcShFf2W5YNtsbJwEXbwRfOw9uBzmH uuQq1i5zBtxFD8hXQq8kT0ktQN9E7gsUe+dz2ZD4jQeVWDpZhAINAIdEdDtrkjV1bA5t oohajzxgvdzIY7jMkGVfBK/zb7ir+KNhVz5nf1zgoc4tO/CGfFx/qoMws1yf3cXe5tik TmjQ== 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=bI7Tt+kQqmaWIzmVW3/XPwRrXmUgc5fCNRUuANTjyBs=; b=BwEpLXtVv6UyKWf8/v36YF0XnwBXkYpuW9YqwAvVYyJHwrICDBZ69yLoaKG4ZaW6nO cTlvn6eiPfk9L5CzmXYY6i4viyus5a5vpJEhn1mH6MzOBA0UthT31HpaECiIsH6xewYY NXxlaA4I3jzJw9DGggtU/t1gxx90MM5MxEVVCqiHfon08/7kvl2LPVf8/2wxSmP+Hxy7 0iuxPFAUlnayDZgWy+kAqM1xlHggDt753N138t4CLD+6q/yn4Yb5DZexVTGNC83Kg0lz B/W1S5t6gy5EdBiYMUmTZffvZX4+6QMq2xw0ezFuS0E7h6kgDOgT0hCGXAKSka01+Vir tU8w== X-Gm-Message-State: ACrzQf2XCjwva4PJcYFJUGZircdiru246bd7VvjyeKZNbnoGxS8IPv+i +E2PmH3XOqVzeDnYQSw75SrgTwgQc8+4RCsK X-Received: by 2002:a2e:94b:0:b0:26a:c77f:57f8 with SMTP id 72-20020a2e094b000000b0026ac77f57f8mr8680366ljj.465.1668116103790; Thu, 10 Nov 2022 13:35:03 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id p4-20020ac24ec4000000b0049adf925d00sm37664lfr.1.2022.11.10.13.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 13:35:03 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Christoph Muellner , Vineet Gupta , Jeff Law , Palmer Dabbelt , Philipp Tomsich Subject: [PATCH] RISC-V: Use binvi to cover more immediates than with xori alone Date: Thu, 10 Nov 2022 22:35:01 +0100 Message-Id: <20221110213501.3592470-1-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749146562244903092?= X-GMAIL-MSGID: =?utf-8?q?1749146562244903092?= Sequences of the form "a ^ C" with C being the positive half of a signed immediate's range with one extra bit set in addtion are mapped to xori and one binvi to avoid using a temporary (and a multi-insn sequence to load C into that temporary). gcc/ChangeLog: * config/riscv/bitmanip.md (*binvi_extrabit): New pattern. gcc/testsuite/ChangeLog: * gcc.target/riscv/zbs-binvi.c: New test. Signed-off-by: Philipp Tomsich --- - Depends on a predicate posted in "RISC-V: Optimize branches testing a bit-range or a shifted immediate". Depending on the order of applying these, I'll take care to pull that part out of the other patch if needed. gcc/config/riscv/bitmanip.md | 19 +++++++++++++++++++ gcc/testsuite/gcc.target/riscv/zbs-binvi.c | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-binvi.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index 436ff4ba958..7fa8461bb71 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -577,6 +577,25 @@ "binvi\t%0,%1,%S2" [(set_attr "type" "bitmanip")]) +; Catch those cases where we can use a binvi + xori or binvi + binvi +; instead of a lui + addi + xor sequence. +(define_insn_and_split "*binvi_extrabit" + [(set (match_operand:X 0 "register_operand" "=r") + (xor:X (match_operand:X 1 "register_operand" "r") + (match_operand:X 2 "uimm_extra_bit_operand" "i")))] + "TARGET_ZBS" + "#" + "&& reload_completed" + [(set (match_dup 0) (xor:X (match_dup 1) (match_dup 3))) + (set (match_dup 0) (xor:X (match_dup 0) (match_dup 4)))] +{ + unsigned HOST_WIDE_INT bits = UINTVAL (operands[2]); + unsigned HOST_WIDE_INT topbit = HOST_WIDE_INT_1U << floor_log2 (bits); + + operands[3] = GEN_INT (bits &~ topbit); + operands[4] = GEN_INT (topbit); +}) + (define_insn "*bext" [(set (match_operand:X 0 "register_operand" "=r") (zero_extract:X (match_operand:X 1 "register_operand" "r") diff --git a/gcc/testsuite/gcc.target/riscv/zbs-binvi.c b/gcc/testsuite/gcc.target/riscv/zbs-binvi.c new file mode 100644 index 00000000000..c2d6725b53b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-binvi.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +long long f3(long long a) +{ + return a ^ 0x1100; +} + +long long f4 (long long a) +{ + return a ^ 0x80000000000000ffull; +} + +long long f5 (long long a) +{ + return a ^ 0x8000001000000000ull; +} + +/* { dg-final { scan-assembler-times "binvi\t" 4 } } */ +/* { dg-final { scan-assembler-times "xori\t" 2 } } */ +