12f077eceSMichael Maitland; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 2169c32ebSMichael Maitland; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v -verify-machineinstrs \ 3169c32ebSMichael Maitland; RUN: -riscv-enable-vl-optimizer=false | FileCheck %s -check-prefixes=CHECK,NOVLOPT 4169c32ebSMichael Maitland; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs \ 5169c32ebSMichael Maitland; RUN: -riscv-enable-vl-optimizer=false | FileCheck %s -check-prefixes=CHECK,NOVLOPT 62f077eceSMichael Maitland; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v -riscv-enable-vl-optimizer \ 72f077eceSMichael Maitland; RUN: -verify-machineinstrs | FileCheck %s -check-prefixes=CHECK,VLOPT 82f077eceSMichael Maitland; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v -riscv-enable-vl-optimizer \ 92f077eceSMichael Maitland; RUN: -verify-machineinstrs | FileCheck %s -check-prefixes=CHECK,VLOPT 101ebe16bfSMichael Maitland 111ebe16bfSMichael Maitlanddeclare <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32>, <vscale x 4 x i32>, <vscale x 4 x i32>, iXLen) 121ebe16bfSMichael Maitland 131ebe16bfSMichael Maitlanddefine <vscale x 4 x i32> @different_imm_vl_with_ta(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 14ae68d532SMichael Maitland; NOVLOPT-LABEL: different_imm_vl_with_ta: 15ae68d532SMichael Maitland; NOVLOPT: # %bb.0: 16ae68d532SMichael Maitland; NOVLOPT-NEXT: vsetivli zero, 5, e32, m2, ta, ma 17ae68d532SMichael Maitland; NOVLOPT-NEXT: vadd.vv v8, v10, v12 18ae68d532SMichael Maitland; NOVLOPT-NEXT: vsetivli zero, 4, e32, m2, ta, ma 19ae68d532SMichael Maitland; NOVLOPT-NEXT: vadd.vv v8, v8, v10 20ae68d532SMichael Maitland; NOVLOPT-NEXT: ret 21ae68d532SMichael Maitland; 22ae68d532SMichael Maitland; VLOPT-LABEL: different_imm_vl_with_ta: 23ae68d532SMichael Maitland; VLOPT: # %bb.0: 24ae68d532SMichael Maitland; VLOPT-NEXT: vsetivli zero, 4, e32, m2, ta, ma 25ae68d532SMichael Maitland; VLOPT-NEXT: vadd.vv v8, v10, v12 26ae68d532SMichael Maitland; VLOPT-NEXT: vadd.vv v8, v8, v10 27ae68d532SMichael Maitland; VLOPT-NEXT: ret 281ebe16bfSMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen 5) 291ebe16bfSMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, iXLen 4) 301ebe16bfSMichael Maitland ret <vscale x 4 x i32> %w 311ebe16bfSMichael Maitland} 321ebe16bfSMichael Maitland 33ae68d532SMichael Maitlanddefine <vscale x 4 x i32> @vlmax_and_imm_vl_with_ta(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 34ae68d532SMichael Maitland; NOVLOPT-LABEL: vlmax_and_imm_vl_with_ta: 35ae68d532SMichael Maitland; NOVLOPT: # %bb.0: 36ae68d532SMichael Maitland; NOVLOPT-NEXT: vsetvli a0, zero, e32, m2, ta, ma 37ae68d532SMichael Maitland; NOVLOPT-NEXT: vadd.vv v8, v10, v12 38ae68d532SMichael Maitland; NOVLOPT-NEXT: vsetivli zero, 4, e32, m2, ta, ma 39ae68d532SMichael Maitland; NOVLOPT-NEXT: vadd.vv v8, v8, v10 40ae68d532SMichael Maitland; NOVLOPT-NEXT: ret 41ae68d532SMichael Maitland; 42ae68d532SMichael Maitland; VLOPT-LABEL: vlmax_and_imm_vl_with_ta: 43ae68d532SMichael Maitland; VLOPT: # %bb.0: 44ae68d532SMichael Maitland; VLOPT-NEXT: vsetivli zero, 4, e32, m2, ta, ma 45ae68d532SMichael Maitland; VLOPT-NEXT: vadd.vv v8, v10, v12 46ae68d532SMichael Maitland; VLOPT-NEXT: vadd.vv v8, v8, v10 47ae68d532SMichael Maitland; VLOPT-NEXT: ret 48ae68d532SMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen -1) 49ae68d532SMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, iXLen 4) 50ae68d532SMichael Maitland ret <vscale x 4 x i32> %w 51ae68d532SMichael Maitland} 52ae68d532SMichael Maitland 53ae68d532SMichael Maitland; Not beneficial to propagate VL since VL is larger in the use side. 541ebe16bfSMichael Maitlanddefine <vscale x 4 x i32> @different_imm_vl_with_ta_larger_vl(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 551ebe16bfSMichael Maitland; CHECK-LABEL: different_imm_vl_with_ta_larger_vl: 561ebe16bfSMichael Maitland; CHECK: # %bb.0: 571ebe16bfSMichael Maitland; CHECK-NEXT: vsetivli zero, 4, e32, m2, ta, ma 581ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v10, v12 591ebe16bfSMichael Maitland; CHECK-NEXT: vsetivli zero, 5, e32, m2, ta, ma 601ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v8, v10 611ebe16bfSMichael Maitland; CHECK-NEXT: ret 621ebe16bfSMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen 4) 631ebe16bfSMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, iXLen 5) 641ebe16bfSMichael Maitland ret <vscale x 4 x i32> %w 651ebe16bfSMichael Maitland} 661ebe16bfSMichael Maitland 671ebe16bfSMichael Maitlanddefine <vscale x 4 x i32> @different_imm_reg_vl_with_ta(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 681ebe16bfSMichael Maitland; CHECK-LABEL: different_imm_reg_vl_with_ta: 691ebe16bfSMichael Maitland; CHECK: # %bb.0: 701ebe16bfSMichael Maitland; CHECK-NEXT: vsetivli zero, 4, e32, m2, ta, ma 711ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v10, v12 721ebe16bfSMichael Maitland; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, ma 731ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v8, v10 741ebe16bfSMichael Maitland; CHECK-NEXT: ret 751ebe16bfSMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen 4) 761ebe16bfSMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, iXLen %vl1) 771ebe16bfSMichael Maitland ret <vscale x 4 x i32> %w 781ebe16bfSMichael Maitland} 791ebe16bfSMichael Maitland 80ae68d532SMichael Maitland; Not beneficial to propagate VL since VL is already one. 811ebe16bfSMichael Maitlanddefine <vscale x 4 x i32> @different_imm_vl_with_ta_1(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 821ebe16bfSMichael Maitland; CHECK-LABEL: different_imm_vl_with_ta_1: 831ebe16bfSMichael Maitland; CHECK: # %bb.0: 841ebe16bfSMichael Maitland; CHECK-NEXT: vsetivli zero, 1, e32, m2, ta, ma 851ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v10, v12 861ebe16bfSMichael Maitland; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, ma 871ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v8, v10 881ebe16bfSMichael Maitland; CHECK-NEXT: ret 891ebe16bfSMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen 1) 901ebe16bfSMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, iXLen %vl1) 911ebe16bfSMichael Maitland ret <vscale x 4 x i32> %w 921ebe16bfSMichael Maitland} 931ebe16bfSMichael Maitland 941ebe16bfSMichael Maitland; Propgate %vl2 to last instruction since it is may smaller than %vl1, 951ebe16bfSMichael Maitland; it's still safe even %vl2 is larger than %vl1, becuase rest of the vector are 961ebe16bfSMichael Maitland; undefined value. 971ebe16bfSMichael Maitlanddefine <vscale x 4 x i32> @different_vl_with_ta(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 981ebe16bfSMichael Maitland; CHECK-LABEL: different_vl_with_ta: 991ebe16bfSMichael Maitland; CHECK: # %bb.0: 1001ebe16bfSMichael Maitland; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, ma 1011ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v10, v8, v10 1021ebe16bfSMichael Maitland; CHECK-NEXT: vsetvli zero, a1, e32, m2, ta, ma 1031ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v10, v8 1041ebe16bfSMichael Maitland; CHECK-NEXT: ret 1051ebe16bfSMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1) 1061ebe16bfSMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a,iXLen %vl2) 1071ebe16bfSMichael Maitland ret <vscale x 4 x i32> %w 1081ebe16bfSMichael Maitland} 1091ebe16bfSMichael Maitland 110*cb6f021aSLuke Lau; We can propagate VL to a tail-undisturbed policy, provided none of its users 111*cb6f021aSLuke Lau; are passthrus (i.e. read past VL). 1121ebe16bfSMichael Maitlanddefine <vscale x 4 x i32> @different_vl_with_tu(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 1131ebe16bfSMichael Maitland; CHECK-LABEL: different_vl_with_tu: 1141ebe16bfSMichael Maitland; CHECK: # %bb.0: 1151ebe16bfSMichael Maitland; CHECK-NEXT: vsetvli zero, a0, e32, m2, tu, ma 116b6c0f1bfSLuke Lau; CHECK-NEXT: vmv2r.v v14, v10 1171ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v14, v10, v12 1181ebe16bfSMichael Maitland; CHECK-NEXT: vsetvli zero, a1, e32, m2, tu, ma 1191ebe16bfSMichael Maitland; CHECK-NEXT: vadd.vv v8, v14, v10 1201ebe16bfSMichael Maitland; CHECK-NEXT: ret 1211ebe16bfSMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1) 1221ebe16bfSMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, iXLen %vl2) 1231ebe16bfSMichael Maitland ret <vscale x 4 x i32> %w 1241ebe16bfSMichael Maitland} 1251ebe16bfSMichael Maitland 126*cb6f021aSLuke Lau; We can propagate VL to a tail-undisturbed policy, provided none of its users 127*cb6f021aSLuke Lau; are passthrus (i.e. read past VL). 1281ebe16bfSMichael Maitlanddefine <vscale x 4 x i32> @different_imm_vl_with_tu(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 129*cb6f021aSLuke Lau; NOVLOPT-LABEL: different_imm_vl_with_tu: 130*cb6f021aSLuke Lau; NOVLOPT: # %bb.0: 131*cb6f021aSLuke Lau; NOVLOPT-NEXT: vsetivli zero, 5, e32, m2, tu, ma 132*cb6f021aSLuke Lau; NOVLOPT-NEXT: vmv2r.v v14, v10 133*cb6f021aSLuke Lau; NOVLOPT-NEXT: vadd.vv v14, v10, v12 134*cb6f021aSLuke Lau; NOVLOPT-NEXT: vsetivli zero, 4, e32, m2, tu, ma 135*cb6f021aSLuke Lau; NOVLOPT-NEXT: vadd.vv v8, v14, v10 136*cb6f021aSLuke Lau; NOVLOPT-NEXT: ret 137*cb6f021aSLuke Lau; 138*cb6f021aSLuke Lau; VLOPT-LABEL: different_imm_vl_with_tu: 139*cb6f021aSLuke Lau; VLOPT: # %bb.0: 140*cb6f021aSLuke Lau; VLOPT-NEXT: vsetivli zero, 4, e32, m2, tu, ma 141*cb6f021aSLuke Lau; VLOPT-NEXT: vmv2r.v v14, v10 142*cb6f021aSLuke Lau; VLOPT-NEXT: vadd.vv v14, v10, v12 143*cb6f021aSLuke Lau; VLOPT-NEXT: vadd.vv v8, v14, v10 144*cb6f021aSLuke Lau; VLOPT-NEXT: ret 1451ebe16bfSMichael Maitland %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen 5) 1461ebe16bfSMichael Maitland %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %passthru, <vscale x 4 x i32> %v, <vscale x 4 x i32> %a, iXLen 4) 1471ebe16bfSMichael Maitland ret <vscale x 4 x i32> %w 1481ebe16bfSMichael Maitland} 149131b7fe2SMichael Maitland 150*cb6f021aSLuke Lau; We can't reduce the VL as %v is used as a passthru, i.e. the elements past VL 151*cb6f021aSLuke Lau; are demanded. 152*cb6f021aSLuke Laudefine <vscale x 4 x i32> @different_vl_as_passthru(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 153*cb6f021aSLuke Lau; CHECK-LABEL: different_vl_as_passthru: 154*cb6f021aSLuke Lau; CHECK: # %bb.0: 155*cb6f021aSLuke Lau; CHECK-NEXT: vsetvli zero, a0, e32, m2, tu, ma 156*cb6f021aSLuke Lau; CHECK-NEXT: vmv2r.v v12, v8 157*cb6f021aSLuke Lau; CHECK-NEXT: vadd.vv v12, v8, v10 158*cb6f021aSLuke Lau; CHECK-NEXT: vsetvli zero, a1, e32, m2, tu, ma 159*cb6f021aSLuke Lau; CHECK-NEXT: vadd.vv v12, v8, v10 160*cb6f021aSLuke Lau; CHECK-NEXT: vmv2r.v v8, v12 161*cb6f021aSLuke Lau; CHECK-NEXT: ret 162*cb6f021aSLuke Lau %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1) 163*cb6f021aSLuke Lau %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %v, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl2) 164*cb6f021aSLuke Lau ret <vscale x 4 x i32> %w 165*cb6f021aSLuke Lau} 166*cb6f021aSLuke Lau 167*cb6f021aSLuke Lau; We can't reduce the VL as %v is used as a passthru, i.e. the elements past VL 168*cb6f021aSLuke Lau; are demanded. 169*cb6f021aSLuke Laudefine <vscale x 4 x i32> @different_imm_vl_as_passthru(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen %vl1, iXLen %vl2) { 170*cb6f021aSLuke Lau; CHECK-LABEL: different_imm_vl_as_passthru: 171*cb6f021aSLuke Lau; CHECK: # %bb.0: 172*cb6f021aSLuke Lau; CHECK-NEXT: vsetivli zero, 5, e32, m2, tu, ma 173*cb6f021aSLuke Lau; CHECK-NEXT: vmv2r.v v12, v8 174*cb6f021aSLuke Lau; CHECK-NEXT: vadd.vv v12, v8, v10 175*cb6f021aSLuke Lau; CHECK-NEXT: vsetivli zero, 4, e32, m2, tu, ma 176*cb6f021aSLuke Lau; CHECK-NEXT: vadd.vv v12, v8, v10 177*cb6f021aSLuke Lau; CHECK-NEXT: vmv2r.v v8, v12 178*cb6f021aSLuke Lau; CHECK-NEXT: ret 179*cb6f021aSLuke Lau %v = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen 5) 180*cb6f021aSLuke Lau %w = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> %v, <vscale x 4 x i32> %a, <vscale x 4 x i32> %b, iXLen 4) 181*cb6f021aSLuke Lau ret <vscale x 4 x i32> %w 182*cb6f021aSLuke Lau} 183*cb6f021aSLuke Lau 184131b7fe2SMichael Maitlanddefine <vscale x 4 x i32> @dont_optimize_tied_def(<vscale x 4 x i32> %a, <vscale x 4 x i16> %b, <vscale x 4 x i16> %c, iXLen %vl) { 185131b7fe2SMichael Maitland; CHECK-LABEL: dont_optimize_tied_def: 186131b7fe2SMichael Maitland; CHECK: # %bb.0: 187131b7fe2SMichael Maitland; CHECK-NEXT: vsetvli a1, zero, e16, m1, tu, ma 188131b7fe2SMichael Maitland; CHECK-NEXT: vwmacc.vv v8, v10, v11 189131b7fe2SMichael Maitland; CHECK-NEXT: vsetvli zero, a0, e16, m1, tu, ma 190131b7fe2SMichael Maitland; CHECK-NEXT: vwmacc.vv v8, v10, v11 191131b7fe2SMichael Maitland; CHECK-NEXT: ret 192131b7fe2SMichael Maitland %1 = call <vscale x 4 x i32> @llvm.riscv.vwmacc.nxv4i32.nxv4i16(<vscale x 4 x i32> %a, <vscale x 4 x i16> %b, <vscale x 4 x i16> %c, iXLen -1, iXLen 0) 193131b7fe2SMichael Maitland %2 = call <vscale x 4 x i32> @llvm.riscv.vwmacc.nxv4i32.nxv4i16(<vscale x 4 x i32> %1, <vscale x 4 x i16> %b, <vscale x 4 x i16> %c, iXLen %vl, iXLen 0) 194131b7fe2SMichael Maitland ret <vscale x 4 x i32> %2 195131b7fe2SMichael Maitland} 196131b7fe2SMichael Maitland 197