Skip to content

Commit 7a0b85b

Browse files
committed
[RISCV] DAG combine special for AND/OR immediately
Combine: RISCVISD::VMAND_VL x, 0/1, y -> 0/x RISCVISD::VMXOR_VL x, 0/1, y -> x/1 td: riscv_vmor_vl + riscv_vmand_vl + riscv_vmnot_vl, better to select vmorn.mm v0, v8, v0 instead of vmand.mm v8, v8, v0 vmorn.mm v0, v8, v0
1 parent 86f0547 commit 7a0b85b

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15621,6 +15621,32 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1562115621
}
1562215622
break;
1562315623
}
15624+
case RISCVISD::VMAND_VL: {
15625+
SDValue N0 = N->getOperand(0);
15626+
SDValue N1 = N->getOperand(1);
15627+
if (isNullOrNullSplat(N0))
15628+
return N0;
15629+
else if (isNullOrNullSplat(N1))
15630+
return N1;
15631+
else if (isOneOrOneSplat(N0))
15632+
return N1;
15633+
else if (isOneOrOneSplat(N1))
15634+
return N0;
15635+
break;
15636+
}
15637+
case RISCVISD::VMOR_VL: {
15638+
SDValue N0 = N->getOperand(0);
15639+
SDValue N1 = N->getOperand(1);
15640+
if (isNullOrNullSplat(N1))
15641+
return N0;
15642+
else if (isNullOrNullSplat(N0))
15643+
return N1;
15644+
else if (isOneOrOneSplat(N0))
15645+
return N0;
15646+
else if (isOneOrOneSplat(N1))
15647+
return N1;
15648+
break;
15649+
}
1562415650
case ISD::SRA:
1562515651
if (SDValue V = performSRACombine(N, DAG, Subtarget))
1562615652
return V;

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,11 @@ foreach mti = AllMasks in {
27362736
VLOpFrag)),
27372737
(!cast<Instruction>("PseudoVMANDN_MM_" # mti.LMul.MX)
27382738
VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
2739+
def : Pat<(mti.Mask (riscv_vmor_vl (riscv_vmand_vl VR:$rs1, VR:$rs2, VLOpFrag),
2740+
(riscv_vmnot_vl VR:$rs2, VLOpFrag),
2741+
VLOpFrag)),
2742+
(!cast<Instruction>("PseudoVMORN_MM_" # mti.LMul.MX)
2743+
VR:$rs1, VR:$rs2, GPR:$vl, mti.Log2SEW)>;
27392744
def : Pat<(mti.Mask (riscv_vmor_vl VR:$rs1,
27402745
(riscv_vmnot_vl VR:$rs2, VLOpFrag),
27412746
VLOpFrag)),

llvm/test/CodeGen/RISCV/rvv/vselect-vp.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,23 @@ define <vscale x 16 x double> @select_nxv16f64(<vscale x 16 x i1> %a, <vscale x
745745
%v = call <vscale x 16 x double> @llvm.vp.select.nxv16f64(<vscale x 16 x i1> %a, <vscale x 16 x double> %b, <vscale x 16 x double> %c, i32 %evl)
746746
ret <vscale x 16 x double> %v
747747
}
748+
749+
define <vscale x 2 x i1> @select_zero(<vscale x 2 x i1> %x, <vscale x 2 x i1> %y, <vscale x 2 x i1> %m, i32 zeroext %evl) {
750+
; CHECK-LABEL: select_zero:
751+
; CHECK: # %bb.0:
752+
; CHECK-NEXT: vsetvli zero, a0, e8, mf4, ta, ma
753+
; CHECK-NEXT: vmand.mm v0, v8, v0
754+
; CHECK-NEXT: ret
755+
%a = call <vscale x 2 x i1> @llvm.vp.select.nxv2i1(<vscale x 2 x i1> %x, <vscale x 2 x i1> %y, <vscale x 2 x i1> zeroinitializer, i32 %evl)
756+
ret <vscale x 2 x i1> %a
757+
}
758+
759+
define <vscale x 2 x i1> @select_one(<vscale x 2 x i1> %x, <vscale x 2 x i1> %y, <vscale x 2 x i1> %m, i32 zeroext %evl) {
760+
; CHECK-LABEL: select_one:
761+
; CHECK: # %bb.0:
762+
; CHECK-NEXT: vsetvli zero, a0, e8, mf4, ta, ma
763+
; CHECK-NEXT: vmorn.mm v0, v8, v0
764+
; CHECK-NEXT: ret
765+
%a = call <vscale x 2 x i1> @llvm.vp.select.nxv2i1(<vscale x 2 x i1> %x, <vscale x 2 x i1> %y, <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> undef, i1 true, i32 0), <vscale x 2 x i1> undef, <vscale x 2 x i32> zeroinitializer), i32 %evl)
766+
ret <vscale x 2 x i1> %a
767+
}

0 commit comments

Comments
 (0)