From patchwork Sat Nov 12 21:29:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Tomsich X-Patchwork-Id: 19260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1434656wru; Sat, 12 Nov 2022 13:31:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5znu7YKJdgD5PsqFP5kcxnZhxhMRcXYMqDhiEhE8y2mHyarSUEmZ5pdf9Khm+qrc9rqaH6 X-Received: by 2002:a17:906:a443:b0:7ad:9760:539d with SMTP id cb3-20020a170906a44300b007ad9760539dmr5940036ejb.369.1668288704881; Sat, 12 Nov 2022 13:31:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668288704; cv=none; d=google.com; s=arc-20160816; b=AwJIpHiM4zpw4bJpGB24mbmxmnZxE+UbHJdnhWN9sTYnzxNAXLAnvcNXhLdsqMQBVd PVLbA4Gryi1EY3ieZY8fdI0uIzSVkavAVU/BATQe1hjQ3P+5FlsalpOprStVv6nBXwqs lgvOhahFJ0KmSw8gDdFaHLUvyRhiC2LEZt0rQV/4rnHKqUwpbjl/uBtvV63SOz8vYpdu 8ZZ7IMBblBIauhDKMG1JeTlOIxXmzWU9u5hi/HI0Tlnv4yw6uBJ3FYZeOFjXHp54ESw4 x2A3b5M7RJwPhA726FA8cCeyUyt73KIVtu/dI1IUaLCZwCwsjr1KittE4kVHfF7aMiK5 UbdA== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=p0HqPdbJ37QW4k98t0NP/xZq9bKhQMcaRRxhsftjbtI=; b=SXUyWmMpiS+qMWC8UrNxRtvIQyOALj9msLRxKFwY+FxpTeDdF5rZUnkVxncO5BPZxn IwLM3gMDbBTThK2lPRvbK1AfIf5Qmc5GTeReAiqnoiJXw7VQeBURnN4IQg2wlkeXI6Lz R7vSwsEtFvCeVSifKx0vd/oQgvVUt1uxA8LugSJvIUxoBuyQz0WMc/eRNSvGWjb2U/E7 COwvdlB2wByd1jFYwVZ4yOEDGvvtBKYUyGwEM5ltIQg2lsT7YUhW7NmvaoamvUn70ONT GSFx6D1vZDQHg+i84POeb2t/xKHAGaW4bWkT6naiF/FLuLuR1TFOmxXtJO2LTa6wcmJe 2EBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=H0VIs4bk; 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 i20-20020a50fc14000000b00461f7a83e58si5170673edr.46.2022.11.12.13.31.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 13:31:44 -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=H0VIs4bk; 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 0F592393BA63 for ; Sat, 12 Nov 2022 21:30:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 05243388553D for ; Sat, 12 Nov 2022 21:29:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 05243388553D 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-x132.google.com with SMTP id l12so13396663lfp.6 for ; Sat, 12 Nov 2022 13:29:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p0HqPdbJ37QW4k98t0NP/xZq9bKhQMcaRRxhsftjbtI=; b=H0VIs4bkFHBKR/Iv9XyXF2Z6+rQtmi+CQiUfy+PrrRWfaR+Lueti0IZMASzjZS5pu/ F/9Rf0VSESv3T87YDmh+KcHIpyn/DC3k3zjeZkt+QVZV09i64cMwK7t6bt5JTEpDsk4q 8qLHoHRzvK63OPfnnFbz93kaS8lgvmE45Wc6kUsb2Es6W8Dl3DwobVPDgw2v+ofZnVBT dbSSL7WN27zfF55oaAFyUuih5w60BTp+YBWiaEmfbxhK7Hi93nCnj4IhGDjgTkcpuZ2D K/O6/MysMQPvenmvcbY5Q3e3qYlKWEEXWQJVIn/vgBtvY/oSInQ2fVb+3fjmIRgJosO1 p80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p0HqPdbJ37QW4k98t0NP/xZq9bKhQMcaRRxhsftjbtI=; b=dqL2JF1WsQDmpkbObZgfshpglzngDiqkLUiq9WkjXBli1xH2OIyfAUm0YQ7O7IriTj HZyzX+OC1WXIpXig+3Xrl0hmr5cYpNdpGExNv1p9XmkX9HaVWqm7ntgP5DRKsiziiX5X Vzk5+tzV1pBt6nj4Ho56mGW3TpOr4yX3YvUQqoOnctz037AZVIYhtHA/zdsj998PIAxk Ur/oLplVrXBUhrPD3eeyxkWh9fJ7aiswcywGjjaRFqI8cZfqJSWOH+Ckjz/3WLDNY+B4 2lVAs6pOzOzkbIWnj5Y8FPyRR4bdGwYqvUulJHnmyoodSuw1jLRE0In5R9YQ5HlH4Qv0 BOsA== X-Gm-Message-State: ANoB5pndDvyDZxL1+okCiL50QVfqWCy+P3AV5xTKOWfceto3RKu/d7oY FZteazggwBV6Slwi84OcCZRwBLnAfwRJ7oIb X-Received: by 2002:ac2:430f:0:b0:494:6bb2:485f with SMTP id l15-20020ac2430f000000b004946bb2485fmr2703298lfh.451.1668288595297; Sat, 12 Nov 2022 13:29:55 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id b9-20020a0565120b8900b004a4251c7f75sm1042967lfv.202.2022.11.12.13.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 13:29:54 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Vineet Gupta , Palmer Dabbelt , Christoph Muellner , Kito Cheng , Jeff Law , Philipp Tomsich , Henry Brausen Subject: [PATCH 6/7] RISC-V: Support immediates in XVentanaCondOps Date: Sat, 12 Nov 2022 22:29:42 +0100 Message-Id: <20221112212943.3068249-7-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221112212943.3068249-1-philipp.tomsich@vrull.eu> References: <20221112212943.3068249-1-philipp.tomsich@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-11.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, 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?1749327496821982281?= X-GMAIL-MSGID: =?utf-8?q?1749327496821982281?= When if-conversion encounters sequences using immediates, the sequences can't trivially map back onto vt.maskc/vt.maskcn (even if benefitial) due to vt.maskc and vt.maskcn not having immediate forms. This adds a splitter to rewrite opportunities for XVentanaCondOps that operate on an immediate by first putting the immediate into a register to enable the non-immediate vt.maskc/vt.maskcn instructions to operate on the value. Consider code, such as long func2 (long a, long c) { if (c) a = 2; else a = 5; return a; } which will be converted to func2: seqz a0,a2 neg a0,a0 andi a0,a0,3 addi a0,a0,2 ret Following this change, we generate li a0,3 vt.maskcn a0,a0,a2 addi a0,a0,2 ret This commit also introduces a simple unit test for if-conversion with immediate (literal) values as the sources for simple sets in the THEN and ELSE blocks. The test checks that Ventana's conditional mask instruction (vt.maskc) is emitted as part of the resultant branchless instruction sequence. gcc/ChangeLog: * config/riscv/xventanacondops.md: Support immediates for vt.maskc/vt.maskcn through a splitter. gcc/testsuite/ChangeLog: * gcc.target/riscv/xventanacondops-ifconv-imm.c: New test. Signed-off-by: Philipp Tomsich Reviewed-by: Henry Brausen --- Ref #204 gcc/config/riscv/xventanacondops.md | 24 +++++++++++++++++-- .../riscv/xventanacondops-ifconv-imm.c | 19 +++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/xventanacondops-ifconv-imm.c diff --git a/gcc/config/riscv/xventanacondops.md b/gcc/config/riscv/xventanacondops.md index 22b4b7d103a..0e09ee91a69 100644 --- a/gcc/config/riscv/xventanacondops.md +++ b/gcc/config/riscv/xventanacondops.md @@ -29,6 +29,26 @@ "TARGET_XVENTANACONDOPS" "vt.maskc\t%0,%2,%1") +;; XVentanaCondOps does not have immediate forms, so we need to do extra +;; work to support these: if we encounter a vt.maskc/n with an immediate, +;; we split this into a load-immediate followed by a vt.maskc/n. +(define_split + [(set (match_operand:DI 0 "register_operand") + (and:DI (neg:DI (match_operator:DI 1 "equality_operator" + [(match_operand:DI 2 "register_operand") + (const_int 0)])) + (match_operand:DI 3 "immediate_operand"))) + (clobber (match_operand:DI 4 "register_operand"))] + "TARGET_XVENTANACONDOPS" + [(set (match_dup 4) (match_dup 3)) + (set (match_dup 0) (and:DI (neg:DI (match_dup 1)) + (match_dup 4)))] +{ + /* Eliminate the clobber/temporary, if it is not needed. */ + if (!rtx_equal_p (operands[0], operands[2])) + operands[4] = operands[0]; +}) + ;; Make order operators digestible to the vt.maskc logic by ;; wrapping their result in a comparison against (const_int 0). @@ -37,7 +57,7 @@ [(set (match_operand:X 0 "register_operand") (and:X (neg:X (match_operator:X 1 "anyge_operator" [(match_operand:X 2 "register_operand") - (match_operand:X 3 "register_operand")])) + (match_operand:X 3 "arith_operand")])) (match_operand:X 4 "register_operand"))) (clobber (match_operand:X 5 "register_operand"))] "TARGET_XVENTANACONDOPS" @@ -54,7 +74,7 @@ [(set (match_operand:X 0 "register_operand") (and:X (neg:X (match_operator:X 1 "anygt_operator" [(match_operand:X 2 "register_operand") - (match_operand:X 3 "register_operand")])) + (match_operand:X 3 "arith_operand")])) (match_operand:X 4 "register_operand"))) (clobber (match_operand:X 5 "register_operand"))] "TARGET_XVENTANACONDOPS" diff --git a/gcc/testsuite/gcc.target/riscv/xventanacondops-ifconv-imm.c b/gcc/testsuite/gcc.target/riscv/xventanacondops-ifconv-imm.c new file mode 100644 index 00000000000..0012e7b669c --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/xventanacondops-ifconv-imm.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */ + +/* Each function below should emit a vt.maskcn instruction */ + +long +foo0 (long a, long b, long c) +{ + if (c) + a = 0; + else + a = 5; + return a; +} + +/* { dg-final { scan-assembler-times "vt.maskcn\t" 1 } } */ +/* { dg-final { scan-assembler-not "beqz\t" } } */ +/* { dg-final { scan-assembler-not "bnez\t" } } */