1 2; RUN: opt -mtriple=thumbv8.1m.main -mve-tail-predication -tail-predication=enabled -mattr=+mve %s -S -o - | FileCheck %s 3 4; CHECK-LABEL: vec_mul_reduce_add 5 6; CHECK: vector.ph: 7; CHECK: %start = call i32 @llvm.start.loop.iterations.i32 8; CHECK: br label %vector.body 9 10; CHECK: vector.body: 11; CHECK: [[ELTS:%[^ ]+]] = phi i32 [ %N, %vector.ph ], [ [[SUB:%[^ ]+]], %vector.body ] 12; CHECK: [[VCTP:%[^ ]+]] = call <4 x i1> @llvm.arm.mve.vctp32(i32 [[ELTS]]) 13; CHECK: [[SUB]] = sub i32 [[ELTS]], 4 14; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]] 15; CHECK: call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* {{.*}}, i32 4, <4 x i1> [[VCTP]], 16 17; CHECK: middle.block: 18; CHECK: [[VPSEL:%[^ ]+]] = select <4 x i1> [[VCTP]], 19; CHECK: call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[VPSEL]]) 20 21define i32 @vec_mul_reduce_add(i32* noalias nocapture readonly %a, i32* noalias nocapture readonly %b, i32 %N) { 22entry: 23 %cmp8 = icmp eq i32 %N, 0 24 %0 = add i32 %N, 3 25 %1 = lshr i32 %0, 2 26 %2 = shl nuw i32 %1, 2 27 %3 = add i32 %2, -4 28 %4 = lshr i32 %3, 2 29 %5 = add nuw nsw i32 %4, 1 30 br i1 %cmp8, label %for.cond.cleanup, label %vector.ph 31 32vector.ph: ; preds = %entry 33 %trip.count.minus.1 = add i32 %N, -1 34 %broadcast.splatinsert11 = insertelement <4 x i32> undef, i32 %trip.count.minus.1, i32 0 35 %broadcast.splat12 = shufflevector <4 x i32> %broadcast.splatinsert11, <4 x i32> undef, <4 x i32> zeroinitializer 36 %start = call i32 @llvm.start.loop.iterations.i32(i32 %5) 37 br label %vector.body 38 39vector.body: ; preds = %vector.body, %vector.ph 40 %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ] 41 %lsr.iv2 = phi i32* [ %scevgep3, %vector.body ], [ %a, %vector.ph ] 42 %lsr.iv = phi i32* [ %scevgep, %vector.body ], [ %b, %vector.ph ] 43 %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %9, %vector.body ] 44 %6 = phi i32 [ %start, %vector.ph ], [ %10, %vector.body ] 45 %lsr.iv24 = bitcast i32* %lsr.iv2 to <4 x i32>* 46 %lsr.iv1 = bitcast i32* %lsr.iv to <4 x i32>* 47 %broadcast.splatinsert = insertelement <4 x i32> undef, i32 %index, i32 0 48 %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> undef, <4 x i32> zeroinitializer 49 %induction = add <4 x i32> %broadcast.splat, <i32 0, i32 1, i32 2, i32 3> 50 51 ; %7 = icmp ule <4 x i32> %induction, %broadcast.splat12 52 %7 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %index, i32 %N) 53 54 %wide.masked.load = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %lsr.iv24, i32 4, <4 x i1> %7, <4 x i32> undef) 55 %wide.masked.load13 = call <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>* %lsr.iv1, i32 4, <4 x i1> %7, <4 x i32> undef) 56 %8 = mul nsw <4 x i32> %wide.masked.load13, %wide.masked.load 57 %9 = add nsw <4 x i32> %8, %vec.phi 58 %index.next = add i32 %index, 4 59 %scevgep = getelementptr i32, i32* %lsr.iv, i32 4 60 %scevgep3 = getelementptr i32, i32* %lsr.iv2, i32 4 61 %10 = call i32 @llvm.loop.decrement.reg.i32.i32.i32(i32 %6, i32 1) 62 %11 = icmp ne i32 %10, 0 63 br i1 %11, label %vector.body, label %middle.block 64 65middle.block: ; preds = %vector.body 66 %12 = select <4 x i1> %7, <4 x i32> %9, <4 x i32> %vec.phi 67 %13 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %12) 68 br label %for.cond.cleanup 69 70for.cond.cleanup: ; preds = %middle.block, %entry 71 %res.0.lcssa = phi i32 [ 0, %entry ], [ %13, %middle.block ] 72 ret i32 %res.0.lcssa 73} 74 75declare <4 x i32> @llvm.masked.load.v4i32.p0v4i32(<4 x i32>*, i32 immarg, <4 x i1>, <4 x i32>) 76declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) 77declare i32 @llvm.start.loop.iterations.i32(i32) 78declare i32 @llvm.loop.decrement.reg.i32.i32.i32(i32, i32) 79declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32, i32) 80