From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 3C90B3865488 for ; Fri, 10 Feb 2023 22:41:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C90B3865488 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-ej1-x632.google.com with SMTP id m2so19453358ejb.8 for ; Fri, 10 Feb 2023 14:41:59 -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=Y8ydSbASF54ZRRFvsooOPXgYS7OUOK4hSdnNQUHBXH0=; b=A4pfTHD/Y+wEGdfW3Q4Aw9O7fQmh4Bycnsh4XmVqFi/ttVpg94g1vOlUUcp+BhuFp/ EzhIQ1KW8rAW+sgf5ImVVTMmayUZobxM5H9kVx64Dg2yxPF4W6TgG+g0tTdC8GYwAUC1 NqP1ooZcZuLDv4FzKbtuIqlg746s5Vq3wdh1yFQTfZmbYGz4ZbN9E29Z87tjiE/yK20I /KMjpEq3QLLtRUPzq+09X1w33ZyZatE+uAVEqJ/b27CnA8ZLiLVvEvbdI9V1rbLXFBTE YJmveeoB1K+jAIvNNC0y90sODPAumf8rovabMrTUI6OiY69RTwhxH/JCGWDe5PG6ClET 3s7A== 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=Y8ydSbASF54ZRRFvsooOPXgYS7OUOK4hSdnNQUHBXH0=; b=mUzTF9UkLeZuC0WLgrWiaAkR25gUwV1FvmwtlU+E8mhiwbYFYLrOOqsDYRqZj/xYH7 gvsfBDOaZZ8xMfFZCTXD8tnlZ0zPVHzwC2DzNPQgEUFZkgtQV+yazj/z8WMjar2nQ6KD 9rCt7DSnQiq24W2VJLchfEmTwJ8fie4RMtxwDraiQ7OD6Ouh1piAKZYkmgfZhxPOifUv ET45kX6EmDeoJOD/WheUSskoixxbM08slBPeZrgrNGCgM3DxmKjytlTeYrxSObuGvCps G+YVS+hHPDmYEY2hDnwGcB3E94IsJzYf5kZE1yCVTNmI7BCPLxC8tGG1uWHbrETZM6kg wqPA== X-Gm-Message-State: AO0yUKVo/FlLLavVxWAGaTMutvpTwnyUPp7eU9abd8gcUR945ui2tgsu B2TJE2kdWacgqq4rb3IcO03uo6AWEDzJJCkp69k= X-Google-Smtp-Source: AK7set+wMYhfQefVXlgK68ZhZ6QkoTQTOvj7xfKdnzJm4dVwS1gO9lZISWsxWobCSdeI0jYK978Elg== X-Received: by 2002:a17:906:eb14:b0:87b:d409:f087 with SMTP id mb20-20020a170906eb1400b0087bd409f087mr17654163ejb.21.1676068917779; Fri, 10 Feb 2023 14:41:57 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id c15-20020a17090603cf00b0088bd62b1cbbsm2976956eja.192.2023.02.10.14.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 14:41:57 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Kito Cheng , Christoph Muellner , Palmer Dabbelt , Andrew Waterman , Vineet Gupta , Philipp Tomsich Subject: [RFC PATCH v1 04/10] RISC-V: Support immediates in Zicond Date: Fri, 10 Feb 2023 23:41:44 +0100 Message-Id: <20230210224150.2801962-5-philipp.tomsich@vrull.eu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230210224150.2801962-1-philipp.tomsich@vrull.eu> References: <20230210224150.2801962-1-philipp.tomsich@vrull.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.0 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 if-conversion encounters sequences using immediates, the sequences can't trivially map back onto czero.eqz/czero.nezt (even if benefitial) due to czero.eqz/czero.nez not having immediate forms. This adds a splitter to rewrite opportunities for Zicond that operate on an immediate by first putting the immediate into a register to enable the non-immediate czero.eqz/czero.nez 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 czero.nez 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 the conditional-zero instruction (czero.eqz/nez) is emitted as part of the resulting branchless instruction sequence. gcc/ChangeLog: * config/riscv/zicond.md: Support immediates for czero.eqz/czero.nez through a splitter. gcc/testsuite/ChangeLog: * gcc.target/riscv/zicond-ifconv-imm.c: New test. Signed-off-by: Philipp Tomsich --- gcc/config/riscv/zicond.md | 20 +++++++++++++++++++ .../gcc.target/riscv/zicond-ifconv-imm.c | 19 ++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zicond-ifconv-imm.c diff --git a/gcc/config/riscv/zicond.md b/gcc/config/riscv/zicond.md index 278e3a67802..19d0b35585b 100644 --- a/gcc/config/riscv/zicond.md +++ b/gcc/config/riscv/zicond.md @@ -28,3 +28,23 @@ (define_insn "*czero." (match_operand:DI 2 "register_operand" "r")))] "TARGET_ZICOND" "czero.\t%0,%2,%1") + +;; Zicond 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 czero.eqz/nez. +(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_ZICOND" + [(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]; +}) diff --git a/gcc/testsuite/gcc.target/riscv/zicond-ifconv-imm.c b/gcc/testsuite/gcc.target/riscv/zicond-ifconv-imm.c new file mode 100644 index 00000000000..f410537a4f0 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zicond-ifconv-imm.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zicond -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */ + +/* Each function below should emit a czero.nez instruction */ + +long +foo0 (long a, long b, long c) +{ + if (c) + a = 0; + else + a = 5; + return a; +} + +/* { dg-final { scan-assembler-times "czero.nez\t" 1 } } */ +/* { dg-final { scan-assembler-not "beqz\t" } } */ +/* { dg-final { scan-assembler-not "bnez\t" } } */ -- 2.34.1