Skip to content

Commit 13eecf7

Browse files
authored
[RISC] Use hasBEXTILike in useInversedSetcc and shouldFoldSelectWithSingleBitTest. (#158366)
Add hasVendorXTHeadCondMov to shouldFoldSelectWithSingleBitTest. The optimizations in these functions is equally applicable to these. I changed the RUN line for xtheadcondmove in condops.ll to use XTHeadBs to get coverage of the hasBEXTILike changes. I didn't think it was worth an additional RUN line and check prefix.
1 parent ba3bce0 commit 13eecf7

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18950,7 +18950,7 @@ static SDValue useInversedSetcc(SDNode *N, SelectionDAG &DAG,
1895018950

1895118951
// Replace (setcc eq (and x, C)) with (setcc ne (and x, C))) to generate
1895218952
// BEXTI, where C is power of 2.
18953-
if (Subtarget.hasStdExtZbs() && VT.isScalarInteger() &&
18953+
if (Subtarget.hasBEXTILike() && VT.isScalarInteger() &&
1895418954
(Subtarget.hasCZEROLike() || Subtarget.hasVendorXTHeadCondMov())) {
1895518955
SDValue LHS = Cond.getOperand(0);
1895618956
SDValue RHS = Cond.getOperand(1);
@@ -24939,8 +24939,8 @@ RISCVTargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
2493924939

2494024940
bool RISCVTargetLowering::shouldFoldSelectWithSingleBitTest(
2494124941
EVT VT, const APInt &AndMask) const {
24942-
if (Subtarget.hasCZEROLike())
24943-
return !Subtarget.hasStdExtZbs() && AndMask.ugt(1024);
24942+
if (Subtarget.hasCZEROLike() || Subtarget.hasVendorXTHeadCondMov())
24943+
return !Subtarget.hasBEXTILike() && AndMask.ugt(1024);
2494424944
return TargetLowering::shouldFoldSelectWithSingleBitTest(VT, AndMask);
2494524945
}
2494624946

llvm/test/CodeGen/RISCV/condops.ll

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; RUN: llc -mtriple=riscv64 -target-abi=lp64f -mattr=+f,+zbs < %s | FileCheck %s -check-prefix=RV64I
44
; RUN: llc -mtriple=riscv32 -target-abi=ilp32f -mattr=+f,+zbs,+xventanacondops < %s | FileCheck %s -check-prefix=RV32XVENTANACONDOPS
55
; RUN: llc -mtriple=riscv64 -target-abi=lp64f -mattr=+f,+zbs,+xventanacondops < %s | FileCheck %s -check-prefix=RV64XVENTANACONDOPS
6-
; RUN: llc -mtriple=riscv64 -target-abi=lp64f -mattr=+f,+zbs,+xtheadcondmov < %s | FileCheck %s -check-prefix=RV64XTHEADCONDMOV
6+
; RUN: llc -mtriple=riscv64 -target-abi=lp64f -mattr=+f,+xtheadbs,+xtheadcondmov < %s | FileCheck %s -check-prefix=RV64XTHEADCONDMOV
77
; RUN: llc -mtriple=riscv32 -target-abi=ilp32f -mattr=+f,+zbs,+zicond < %s | FileCheck %s -check-prefix=RV32ZICOND
88
; RUN: llc -mtriple=riscv64 -target-abi=lp64f -mattr=+f,+zbs,+zicond < %s | FileCheck %s -check-prefix=RV64ZICOND
99

@@ -126,7 +126,7 @@ define i64 @zero_singlebit1(i64 %rs1, i64 %rs2) {
126126
;
127127
; RV64XTHEADCONDMOV-LABEL: zero_singlebit1:
128128
; RV64XTHEADCONDMOV: # %bb.0:
129-
; RV64XTHEADCONDMOV-NEXT: bexti a1, a1, 12
129+
; RV64XTHEADCONDMOV-NEXT: th.tst a1, a1, 12
130130
; RV64XTHEADCONDMOV-NEXT: th.mvnez a0, zero, a1
131131
; RV64XTHEADCONDMOV-NEXT: ret
132132
;
@@ -179,9 +179,8 @@ define i64 @zero_singlebit2(i64 %rs1, i64 %rs2) {
179179
;
180180
; RV64XTHEADCONDMOV-LABEL: zero_singlebit2:
181181
; RV64XTHEADCONDMOV: # %bb.0:
182-
; RV64XTHEADCONDMOV-NEXT: slli a1, a1, 51
183-
; RV64XTHEADCONDMOV-NEXT: srai a1, a1, 63
184-
; RV64XTHEADCONDMOV-NEXT: and a0, a1, a0
182+
; RV64XTHEADCONDMOV-NEXT: th.tst a1, a1, 12
183+
; RV64XTHEADCONDMOV-NEXT: th.mveqz a0, zero, a1
185184
; RV64XTHEADCONDMOV-NEXT: ret
186185
;
187186
; RV32ZICOND-LABEL: zero_singlebit2:
@@ -4297,9 +4296,8 @@ define i64 @single_bit(i64 %x) {
42974296
;
42984297
; RV64XTHEADCONDMOV-LABEL: single_bit:
42994298
; RV64XTHEADCONDMOV: # %bb.0: # %entry
4300-
; RV64XTHEADCONDMOV-NEXT: slli a1, a0, 53
4301-
; RV64XTHEADCONDMOV-NEXT: srai a1, a1, 63
4302-
; RV64XTHEADCONDMOV-NEXT: and a0, a1, a0
4299+
; RV64XTHEADCONDMOV-NEXT: andi a1, a0, 1024
4300+
; RV64XTHEADCONDMOV-NEXT: th.mveqz a0, zero, a1
43034301
; RV64XTHEADCONDMOV-NEXT: ret
43044302
;
43054303
; RV32ZICOND-LABEL: single_bit:
@@ -4353,9 +4351,8 @@ define i64 @single_bit2(i64 %x) {
43534351
;
43544352
; RV64XTHEADCONDMOV-LABEL: single_bit2:
43554353
; RV64XTHEADCONDMOV: # %bb.0: # %entry
4356-
; RV64XTHEADCONDMOV-NEXT: slli a1, a0, 52
4357-
; RV64XTHEADCONDMOV-NEXT: srai a1, a1, 63
4358-
; RV64XTHEADCONDMOV-NEXT: and a0, a1, a0
4354+
; RV64XTHEADCONDMOV-NEXT: th.tst a1, a0, 11
4355+
; RV64XTHEADCONDMOV-NEXT: th.mveqz a0, zero, a1
43594356
; RV64XTHEADCONDMOV-NEXT: ret
43604357
;
43614358
; RV32ZICOND-LABEL: single_bit2:

0 commit comments

Comments
 (0)