Skip to content

Commit d3396a5

Browse files
committed
[RISCV] Use shiftop<rotl> in one of the BCLR patterns.
This allows us to remove AND from the shift amount when DAG combine has replaced (not (shl 1, X)) with (rotl -2, X). SimplifyDemandedBits will often simplify the rotl case on its own, but not if the masked shift amount has multiple users. This will need to be rebase if llvm#164050 goes in first.
1 parent 140b571 commit d3396a5

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def : Pat<(riscv_rolw GPR:$rs1, uimm5:$rs2),
527527
let Predicates = [HasStdExtZbs] in {
528528
def : Pat<(XLenVT (and (not (shiftop<shl> 1, (XLenVT GPR:$rs2))), GPR:$rs1)),
529529
(BCLR GPR:$rs1, GPR:$rs2)>;
530-
def : Pat<(XLenVT (and (rotl -2, (XLenVT GPR:$rs2)), GPR:$rs1)),
530+
def : Pat<(XLenVT (and (shiftop<rotl> -2, (XLenVT GPR:$rs2)), GPR:$rs1)),
531531
(BCLR GPR:$rs1, GPR:$rs2)>;
532532
def : Pat<(XLenVT (or (shiftop<shl> 1, (XLenVT GPR:$rs2)), GPR:$rs1)),
533533
(BSET GPR:$rs1, GPR:$rs2)>;

llvm/test/CodeGen/RISCV/rv32zbs.ll

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,12 @@ define i32 @bclr_i32_mask_multiple(i32 %a, i32 %b, i32 %shamt) nounwind {
5656
; RV32I-NEXT: add a0, a0, a1
5757
; RV32I-NEXT: ret
5858
;
59-
; RV32ZBSNOZBB-LABEL: bclr_i32_mask_multiple:
60-
; RV32ZBSNOZBB: # %bb.0:
61-
; RV32ZBSNOZBB-NEXT: bclr a0, a0, a2
62-
; RV32ZBSNOZBB-NEXT: bset a1, a1, a2
63-
; RV32ZBSNOZBB-NEXT: add a0, a0, a1
64-
; RV32ZBSNOZBB-NEXT: ret
65-
;
66-
; RV32ZBSZBB-LABEL: bclr_i32_mask_multiple:
67-
; RV32ZBSZBB: # %bb.0:
68-
; RV32ZBSZBB-NEXT: andi a3, a2, 63
69-
; RV32ZBSZBB-NEXT: bclr a0, a0, a3
70-
; RV32ZBSZBB-NEXT: bset a1, a1, a2
71-
; RV32ZBSZBB-NEXT: add a0, a0, a1
72-
; RV32ZBSZBB-NEXT: ret
59+
; RV32ZBS-LABEL: bclr_i32_mask_multiple:
60+
; RV32ZBS: # %bb.0:
61+
; RV32ZBS-NEXT: bclr a0, a0, a2
62+
; RV32ZBS-NEXT: bset a1, a1, a2
63+
; RV32ZBS-NEXT: add a0, a0, a1
64+
; RV32ZBS-NEXT: ret
7365
%shamt_masked = and i32 %shamt, 63
7466
%shl = shl nuw i32 1, %shamt_masked
7567
%neg = xor i32 %shl, -1

llvm/test/CodeGen/RISCV/rv64zbs.ll

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
33
; RUN: | FileCheck %s -check-prefixes=CHECK,RV64I
44
; RUN: llc -mtriple=riscv64 -mattr=+zbs -verify-machineinstrs < %s \
5-
; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBS,RV64ZBSNOZBB
5+
; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBS
66
; RUN: llc -mtriple=riscv64 -mattr=+zbs,+zbb -verify-machineinstrs < %s \
7-
; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBS,RV64ZBSZBB
7+
; RUN: | FileCheck %s -check-prefixes=CHECK,RV64ZBS
88

99
define signext i32 @bclr_i32(i32 signext %a, i32 signext %b) nounwind {
1010
; RV64I-LABEL: bclr_i32:
@@ -121,20 +121,12 @@ define i64 @bclr_i64_mask_multiple(i64 %a, i64 %b, i64 %shamt) nounwind {
121121
; RV64I-NEXT: add a0, a0, a1
122122
; RV64I-NEXT: ret
123123
;
124-
; RV64ZBSNOZBB-LABEL: bclr_i64_mask_multiple:
125-
; RV64ZBSNOZBB: # %bb.0:
126-
; RV64ZBSNOZBB-NEXT: bclr a0, a0, a2
127-
; RV64ZBSNOZBB-NEXT: bset a1, a1, a2
128-
; RV64ZBSNOZBB-NEXT: add a0, a0, a1
129-
; RV64ZBSNOZBB-NEXT: ret
130-
;
131-
; RV64ZBSZBB-LABEL: bclr_i64_mask_multiple:
132-
; RV64ZBSZBB: # %bb.0:
133-
; RV64ZBSZBB-NEXT: andi a3, a2, 63
134-
; RV64ZBSZBB-NEXT: bclr a0, a0, a3
135-
; RV64ZBSZBB-NEXT: bset a1, a1, a2
136-
; RV64ZBSZBB-NEXT: add a0, a0, a1
137-
; RV64ZBSZBB-NEXT: ret
124+
; RV64ZBS-LABEL: bclr_i64_mask_multiple:
125+
; RV64ZBS: # %bb.0:
126+
; RV64ZBS-NEXT: bclr a0, a0, a2
127+
; RV64ZBS-NEXT: bset a1, a1, a2
128+
; RV64ZBS-NEXT: add a0, a0, a1
129+
; RV64ZBS-NEXT: ret
138130
%shamt_masked = and i64 %shamt, 63
139131
%shl = shl nuw i64 1, %shamt_masked
140132
%neg = xor i64 %shl, -1

0 commit comments

Comments
 (0)