From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 4FDE03858D28 for ; Thu, 10 Nov 2022 21:36:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FDE03858D28 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-x22f.google.com with SMTP id k19so2446292lji.2 for ; Thu, 10 Nov 2022 13:36:21 -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=wsCU+eymHeDV2I0z4xwEPXgzfP0P7x0SX9yTYkBGAz8=; b=nbiMDHp7twq7c1NepcZzbli1mmGg0Jxz2AbQQKm7Ika/3vXsKJsLB4dwhrHf4evSyI EyhHzsJguMxj1tAKLzn7fm1+JjW1R57SClX0pORmeMRcPPHGNa6LgTky6gy7G36LZqsm kkBft6F6CkDdZDrtvdD7TmujzB2AXsz5t7U9E70kZHVV9ilNq3KV6/0D8QXgZ5h8s6Rk YjMOMfesz0d9ifRk1xUr2AvkPplPPMX0FVJrhfFhEkKTIVfDeA1lFokXeBLUMRmPuIRY w4ByNPqVK/o63WJkVBsZJVlDtdRArd9aPUQhMao+aCJu+Tr+zB2s9PZd3jnZEa1cK4Nw crBQ== 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=wsCU+eymHeDV2I0z4xwEPXgzfP0P7x0SX9yTYkBGAz8=; b=S+gF4M0Uw2MZmUs4IeOhdRsPaRBkdZVE4DyNH/QXK37knyy8lYrlUEOWvi8vY2ObCi LxRx7UuTaMw792gkHwGnIr0Z0yrN1IplJJxxEgORnbovRhSGOVBdhNUOeZm3i2ZmTuvr /oIuIJ827CjtfHcFNbluXeMmtLvbJZ6iEAngqRgumqQTUETAlx55ilpQNsAGbRGRUiS3 dQcxRrUBrfCP+gLoejRdyQSxpxb2z4Ow7mDp6W9VulRMNwF4yimO6G4zsUuCYoMiS2uf 28yvGYv1B4G7fB8rX43jB1KgC591DzxzASDQA5O/ogZnHHtvca082q+HIQ4wLdjzqEL3 eDdA== X-Gm-Message-State: ACrzQf1wLoq6IMnUC/0okxfn2VVyKyDKzzzYkU/LvsY80RDV7ksRhiqu 5FecpNr1R/10msckxvoj826NE6nultruXBT8 X-Google-Smtp-Source: AMsMyM4ZBHzPvgOGtsNEXLs/eh8h3yiARhAqjoQmq95N3DlUISvujMnI58ux+hwYRHx9mkftpyfBWg== X-Received: by 2002:a2e:ab0c:0:b0:277:2b10:bf69 with SMTP id ce12-20020a2eab0c000000b002772b10bf69mr9994400ljb.392.1668116179531; Thu, 10 Nov 2022 13:36:19 -0800 (PST) Received: from ubuntu-focal.. ([2a01:4f9:3a:1e26::2]) by smtp.gmail.com with ESMTPSA id 19-20020a2eb953000000b002770f7d8dcasm84801ljs.134.2022.11.10.13.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 13:36:19 -0800 (PST) From: Philipp Tomsich To: gcc-patches@gcc.gnu.org Cc: Jeff Law , Palmer Dabbelt , Christoph Muellner , Kito Cheng , Vineet Gupta , Philipp Tomsich Subject: [PATCH] RISC-V: Optimize masking with two clear bits not a SMALL_OPERAND Date: Thu, 10 Nov 2022 22:36:17 +0100 Message-Id: <20221110213617.3592572-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=-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 List-Id: Add a split for cases where we can use two bclri (or one bclri and an andi) to clear two bits. gcc/ChangeLog: * config/riscv/bitmanip.md (*bclri_nottwobits): New pattern. (*bclridisi_nottwobits): New pattern, handling the sign-bit. * config/riscv/predicates.md (const_nottwobits_operand): New predicate. gcc/testsuite/ChangeLog: * gcc.target/riscv/zbs-bclri.c: New test. Signed-off-by: Philipp Tomsich --- gcc/config/riscv/bitmanip.md | 38 ++++++++++++++++++++++ gcc/config/riscv/predicates.md | 5 +++ gcc/testsuite/gcc.target/riscv/zbs-bclri.c | 12 +++++++ 3 files changed, 55 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-bclri.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index 7fa8461bb71..f1d8f24c2d3 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -560,6 +560,44 @@ "bclri\t%0,%1,%T2" [(set_attr "type" "bitmanip")]) +;; In case we have "val & ~IMM" where ~IMM has 2 bits set. +(define_insn_and_split "*bclri_nottwobits" + [(set (match_operand:X 0 "register_operand" "=r") + (and:X (match_operand:X 1 "register_operand" "r") + (match_operand:X 2 "const_nottwobits_operand" "i")))] + "TARGET_ZBS && !paradoxical_subreg_p (operands[1])" + "#" + "&& reload_completed" + [(set (match_dup 0) (and:X (match_dup 1) (match_dup 3))) + (set (match_dup 0) (and: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); +}) + +;; In case of a paradoxical subreg, the sign bit and the high bits are +;; not allowed to be changed +(define_insn_and_split "*bclridisi_nottwobits" + [(set (match_operand:DI 0 "register_operand" "=r") + (and:DI (match_operand:DI 1 "register_operand" "r") + (match_operand:DI 2 "const_nottwobits_operand" "i")))] + "TARGET_64BIT && TARGET_ZBS + && clz_hwi (~UINTVAL (operands[2])) > 33" + "#" + "&& reload_completed" + [(set (match_dup 0) (and:DI (match_dup 1) (match_dup 3))) + (set (match_dup 0) (and:DI (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 "*binv" [(set (match_operand:X 0 "register_operand" "=r") (xor:X (ashift:X (const_int 1) diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index 6de9b39e39b..b368c11c930 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -304,6 +304,11 @@ (match_test "ctz_hwi (INTVAL (op)) > 0") (match_test "SMALL_OPERAND (INTVAL (op) >> ctz_hwi (INTVAL (op)))"))) +;; A CONST_INT operand that has exactly two bits cleared. +(define_predicate "const_nottwobits_operand" + (and (match_code "const_int") + (match_test "popcount_hwi (~UINTVAL (op)) == 2"))) + ;; A CONST_INT operand that fits into the unsigned half of a ;; signed-immediate after the top bit has been cleared. (define_predicate "uimm_extra_bit_operand" diff --git a/gcc/testsuite/gcc.target/riscv/zbs-bclri.c b/gcc/testsuite/gcc.target/riscv/zbs-bclri.c new file mode 100644 index 00000000000..12e2063436c --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-bclri.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +/* bclri + bclri */ +long long f5 (long long a) +{ + return a & ~0x11000; +} + +/* { dg-final { scan-assembler-times "bclri\t" 2 } } */ + -- 2.34.1