Skip to content

Commit f4a1948

Browse files
[RISCV][VLOPT] Add vsadd and vsaddu to isSupportedInstr
1 parent a61eeaa commit f4a1948

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,15 @@ static bool isSupportedInstr(const MachineInstr &MI) {
801801
case RISCV::VMSOF_M:
802802
case RISCV::VIOTA_M:
803803
case RISCV::VID_V:
804+
805+
// Vector Single-Width Saturating Add and Subtract
806+
case RISCV::VSADDU_VI:
807+
case RISCV::VSADDU_VV:
808+
case RISCV::VSADDU_VX:
809+
case RISCV::VSADD_VI:
810+
case RISCV::VSADD_VV:
811+
case RISCV::VSADD_VX:
812+
804813
return true;
805814
}
806815

@@ -872,7 +881,7 @@ bool RISCVVLOptimizer::isCandidate(const MachineInstr &MI) const {
872881
const MCInstrDesc &Desc = MI.getDesc();
873882
if (!RISCVII::hasVLOp(Desc.TSFlags) || !RISCVII::hasSEWOp(Desc.TSFlags))
874883
return false;
875-
if (MI.getNumDefs() != 1)
884+
if (MI.getNumExplicitDefs() != 1)
876885
return false;
877886

878887
// If we're not using VLMAX, then we need to be careful whether we are using

llvm/test/CodeGen/RISCV/rvv/vl-opt-instrs.ll

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,3 +2925,123 @@ define <vscale x 4 x i32> @vid.v(<vscale x 4 x i32> %c, iXLen %vl) {
29252925
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %c, iXLen %vl)
29262926
ret <vscale x 4 x i32> %2
29272927
}
2928+
2929+
define <vscale x 4 x i32> @vsaddu_vi(<vscale x 4 x i32> %a, iXLen %vl) {
2930+
; NOVLOPT-LABEL: vsaddu_vi:
2931+
; NOVLOPT: # %bb.0:
2932+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
2933+
; NOVLOPT-NEXT: vsaddu.vi v10, v8, 5
2934+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
2935+
; NOVLOPT-NEXT: vadd.vv v8, v10, v8
2936+
; NOVLOPT-NEXT: ret
2937+
;
2938+
; VLOPT-LABEL: vsaddu_vi:
2939+
; VLOPT: # %bb.0:
2940+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
2941+
; VLOPT-NEXT: vsaddu.vi v10, v8, 5
2942+
; VLOPT-NEXT: vadd.vv v8, v10, v8
2943+
; VLOPT-NEXT: ret
2944+
%1 = call <vscale x 4 x i32> @llvm.riscv.vsaddu.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, i32 5, iXLen -1)
2945+
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %a, iXLen %vl)
2946+
ret <vscale x 4 x i32> %2
2947+
}
2948+
2949+
define <vscale x 4 x i32> @vsaddu_vv(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl) {
2950+
; NOVLOPT-LABEL: vsaddu_vv:
2951+
; NOVLOPT: # %bb.0:
2952+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
2953+
; NOVLOPT-NEXT: vsaddu.vv v8, v8, v10
2954+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
2955+
; NOVLOPT-NEXT: vadd.vv v8, v8, v10
2956+
; NOVLOPT-NEXT: ret
2957+
;
2958+
; VLOPT-LABEL: vsaddu_vv:
2959+
; VLOPT: # %bb.0:
2960+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
2961+
; VLOPT-NEXT: vsaddu.vv v8, v8, v10
2962+
; VLOPT-NEXT: vadd.vv v8, v8, v10
2963+
; VLOPT-NEXT: ret
2964+
%1 = call <vscale x 4 x i32> @llvm.riscv.vsaddu.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen -1)
2965+
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %b, iXLen %vl)
2966+
ret <vscale x 4 x i32> %2
2967+
}
2968+
2969+
define <vscale x 4 x i32> @vsaddu_vx(<vscale x 4 x i32> %a, i32 %b, iXLen %vl) {
2970+
; NOVLOPT-LABEL: vsaddu_vx:
2971+
; NOVLOPT: # %bb.0:
2972+
; NOVLOPT-NEXT: vsetvli a2, zero, e32, m2, ta, ma
2973+
; NOVLOPT-NEXT: vsaddu.vx v10, v8, a0
2974+
; NOVLOPT-NEXT: vsetvli zero, a1, e32, m2, ta, ma
2975+
; NOVLOPT-NEXT: vadd.vv v8, v10, v8
2976+
; NOVLOPT-NEXT: ret
2977+
;
2978+
; VLOPT-LABEL: vsaddu_vx:
2979+
; VLOPT: # %bb.0:
2980+
; VLOPT-NEXT: vsetvli zero, a1, e32, m2, ta, ma
2981+
; VLOPT-NEXT: vsaddu.vx v10, v8, a0
2982+
; VLOPT-NEXT: vadd.vv v8, v10, v8
2983+
; VLOPT-NEXT: ret
2984+
%1 = call <vscale x 4 x i32> @llvm.riscv.vsaddu.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, i32 %b, iXLen -1)
2985+
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %a, iXLen %vl)
2986+
ret <vscale x 4 x i32> %2
2987+
}
2988+
2989+
define <vscale x 4 x i32> @vsadd_vi(<vscale x 4 x i32> %a, iXLen %vl) {
2990+
; NOVLOPT-LABEL: vsadd_vi:
2991+
; NOVLOPT: # %bb.0:
2992+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
2993+
; NOVLOPT-NEXT: vsadd.vi v10, v8, 5
2994+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
2995+
; NOVLOPT-NEXT: vadd.vv v8, v10, v8
2996+
; NOVLOPT-NEXT: ret
2997+
;
2998+
; VLOPT-LABEL: vsadd_vi:
2999+
; VLOPT: # %bb.0:
3000+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3001+
; VLOPT-NEXT: vsadd.vi v10, v8, 5
3002+
; VLOPT-NEXT: vadd.vv v8, v10, v8
3003+
; VLOPT-NEXT: ret
3004+
%1 = call <vscale x 4 x i32> @llvm.riscv.vsadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, i32 5, iXLen -1)
3005+
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %a, iXLen %vl)
3006+
ret <vscale x 4 x i32> %2
3007+
}
3008+
3009+
define <vscale x 4 x i32> @vsadd_vv(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl) {
3010+
; NOVLOPT-LABEL: vsadd_vv:
3011+
; NOVLOPT: # %bb.0:
3012+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3013+
; NOVLOPT-NEXT: vsadd.vv v8, v8, v10
3014+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3015+
; NOVLOPT-NEXT: vadd.vv v8, v8, v10
3016+
; NOVLOPT-NEXT: ret
3017+
;
3018+
; VLOPT-LABEL: vsadd_vv:
3019+
; VLOPT: # %bb.0:
3020+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3021+
; VLOPT-NEXT: vsadd.vv v8, v8, v10
3022+
; VLOPT-NEXT: vadd.vv v8, v8, v10
3023+
; VLOPT-NEXT: ret
3024+
%1 = call <vscale x 4 x i32> @llvm.riscv.vsadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen -1)
3025+
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %b, iXLen %vl)
3026+
ret <vscale x 4 x i32> %2
3027+
}
3028+
3029+
define <vscale x 4 x i32> @vsadd_vx(<vscale x 4 x i32> %a, i32 %b, iXLen %vl) {
3030+
; NOVLOPT-LABEL: vsadd_vx:
3031+
; NOVLOPT: # %bb.0:
3032+
; NOVLOPT-NEXT: vsetvli a2, zero, e32, m2, ta, ma
3033+
; NOVLOPT-NEXT: vsadd.vx v10, v8, a0
3034+
; NOVLOPT-NEXT: vsetvli zero, a1, e32, m2, ta, ma
3035+
; NOVLOPT-NEXT: vadd.vv v8, v10, v8
3036+
; NOVLOPT-NEXT: ret
3037+
;
3038+
; VLOPT-LABEL: vsadd_vx:
3039+
; VLOPT: # %bb.0:
3040+
; VLOPT-NEXT: vsetvli zero, a1, e32, m2, ta, ma
3041+
; VLOPT-NEXT: vsadd.vx v10, v8, a0
3042+
; VLOPT-NEXT: vadd.vv v8, v10, v8
3043+
; VLOPT-NEXT: ret
3044+
%1 = call <vscale x 4 x i32> @llvm.riscv.vsadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, i32 %b, iXLen -1)
3045+
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %a, iXLen %vl)
3046+
ret <vscale x 4 x i32> %2
3047+
}

0 commit comments

Comments
 (0)