Skip to content

Commit 2951c44

Browse files
committed
[RISCV] Add vector hasAndNot
1 parent 3f6dde9 commit 2951c44

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2051,14 +2051,22 @@ bool RISCVTargetLowering::isMaskAndCmp0FoldingBeneficial(
20512051
bool RISCVTargetLowering::hasAndNotCompare(SDValue Y) const {
20522052
EVT VT = Y.getValueType();
20532053

2054-
// FIXME: Support vectors once we have tests.
20552054
if (VT.isVector())
20562055
return false;
20572056

20582057
return (Subtarget.hasStdExtZbb() || Subtarget.hasStdExtZbkb()) &&
20592058
(!isa<ConstantSDNode>(Y) || cast<ConstantSDNode>(Y)->isOpaque());
20602059
}
20612060

2061+
bool RISCVTargetLowering::hasAndNot(SDValue Y) const {
2062+
EVT VT = Y.getValueType();
2063+
2064+
if (!VT.isVector())
2065+
return hasAndNotCompare(Y);
2066+
2067+
return Subtarget.hasStdExtZvkb();
2068+
}
2069+
20622070
bool RISCVTargetLowering::hasBitTest(SDValue X, SDValue Y) const {
20632071
// Zbs provides BEXT[_I], which can be used with SEQZ/SNEZ as a bit test.
20642072
if (Subtarget.hasStdExtZbs())

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ class RISCVTargetLowering : public TargetLowering {
535535
bool isCheapToSpeculateCtlz(Type *Ty) const override;
536536
bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override;
537537
bool hasAndNotCompare(SDValue Y) const override;
538+
bool hasAndNot(SDValue Y) const override;
538539
bool hasBitTest(SDValue X, SDValue Y) const override;
539540
bool shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
540541
SDValue X, ConstantSDNode *XC, ConstantSDNode *CC, SDValue Y,

llvm/test/CodeGen/RISCV/rvv/vandn-sdnode.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,9 +2580,9 @@ define <vscale x 1 x i8> @not_signbit_mask_nxv1i8(<vscale x 1 x i8> %a, <vscale
25802580
; CHECK-ZVKB-LABEL: not_signbit_mask_nxv1i8:
25812581
; CHECK-ZVKB: # %bb.0:
25822582
; CHECK-ZVKB-NEXT: vsetvli a0, zero, e8, mf8, ta, ma
2583-
; CHECK-ZVKB-NEXT: vmsgt.vi v0, v8, -1
2584-
; CHECK-ZVKB-NEXT: vmv.v.i v8, 0
2585-
; CHECK-ZVKB-NEXT: vmerge.vvm v8, v8, v9, v0
2583+
; CHECK-ZVKB-NEXT: vsra.vi v8, v8, 7
2584+
; CHECK-ZVKB-NEXT: vnot.v v8, v8
2585+
; CHECK-ZVKB-NEXT: vand.vv v8, v8, v9
25862586
; CHECK-ZVKB-NEXT: ret
25872587
%cond = icmp sgt <vscale x 1 x i8> %a, splat (i8 -1)
25882588
%r = select <vscale x 1 x i1> %cond, <vscale x 1 x i8> %b, <vscale x 1 x i8> zeroinitializer

0 commit comments

Comments
 (0)