xref: /llvm-project/llvm/test/Transforms/LoopVectorize/scalable-reduction-inloop.ll (revision 56c091ea7106507b36015297ee9005c9d5fab0bf)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -passes=loop-vectorize -force-target-supports-scalable-vectors=true -scalable-vectorization=on -S | FileCheck %s
3
4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5
6define i8 @reduction_add_trunc(ptr noalias nocapture %A) {
7; CHECK-LABEL: @reduction_add_trunc(
8; CHECK:         call i32 @llvm.vscale.i32()
9; CHECK:         call i32 @llvm.vscale.i32()
10; CHECK:         [[TMP30:%.*]] = call i32 @llvm.vscale.i32()
11; CHECK-NEXT:    [[TMP31:%.*]] = mul i32 [[TMP30]], 16
12; CHECK:       vector.body:
13; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
14; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <vscale x 8 x i32> [ insertelement (<vscale x 8 x i32> zeroinitializer, i32 255, i32 0), %vector.ph ], [ [[TMP34:%.*]], %vector.body ]
15; CHECK-NEXT:    [[VEC_PHI1:%.*]] = phi <vscale x 8 x i32> [ zeroinitializer, %vector.ph ], [ [[TMP36:%.*]], %vector.body ]
16; CHECK:         [[TMP14:%.*]] = and <vscale x 8 x i32> [[VEC_PHI]], splat (i32 255)
17; CHECK-NEXT:    [[TMP15:%.*]] = and <vscale x 8 x i32> [[VEC_PHI1]], splat (i32 255)
18; CHECK:         [[WIDE_LOAD:%.*]] = load <vscale x 8 x i8>, ptr
19; CHECK:         [[WIDE_LOAD2:%.*]] = load <vscale x 8 x i8>, ptr
20; CHECK-NEXT:    [[TMP26:%.*]] = zext <vscale x 8 x i8> [[WIDE_LOAD]] to <vscale x 8 x i32>
21; CHECK-NEXT:    [[TMP27:%.*]] = zext <vscale x 8 x i8> [[WIDE_LOAD2]] to <vscale x 8 x i32>
22; CHECK-NEXT:    [[TMP28:%.*]] = add <vscale x 8 x i32> [[TMP14]], [[TMP26]]
23; CHECK-NEXT:    [[TMP29:%.*]] = add <vscale x 8 x i32> [[TMP15]], [[TMP27]]
24; CHECK-NEXT:    [[TMP33:%.*]] = trunc <vscale x 8 x i32> [[TMP28]] to <vscale x 8 x i8>
25; CHECK-NEXT:    [[TMP35:%.*]] = trunc <vscale x 8 x i32> [[TMP29]] to <vscale x 8 x i8>
26; CHECK-NEXT:    [[TMP34]] = zext <vscale x 8 x i8> [[TMP33]] to <vscale x 8 x i32>
27; CHECK-NEXT:    [[TMP36]] = zext <vscale x 8 x i8> [[TMP35]] to <vscale x 8 x i32>
28; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], [[TMP31]]
29; CHECK-NEXT:    [[TMP32:%.*]] = icmp eq i32 [[INDEX_NEXT]], {{%.*}}
30; CHECK:       middle.block:
31; CHECK-NEXT:    [[TMP37:%.*]] = trunc <vscale x 8 x i32> [[TMP34]] to <vscale x 8 x i8>
32; CHECK-NEXT:    [[TMP38:%.*]] = trunc <vscale x 8 x i32> [[TMP36]] to <vscale x 8 x i8>
33; CHECK-NEXT:    [[BIN_RDX:%.*]] = add <vscale x 8 x i8> [[TMP38]], [[TMP37]]
34; CHECK-NEXT:    [[TMP39:%.*]] = call i8 @llvm.vector.reduce.add.nxv8i8(<vscale x 8 x i8> [[BIN_RDX]])
35; CHECK-NEXT:    [[TMP40:%.*]] = zext i8 [[TMP39]] to i32
36; CHECK-NEXT:    %cmp.n = icmp eq i32 256, %n.vec
37;
38entry:
39  br label %loop
40
41loop:                                           ; preds = %entry, %loop
42  %indvars.iv = phi i32 [ %indvars.iv.next, %loop ], [ 0, %entry ]
43  %sum.02p = phi i32 [ %l9, %loop ], [ 255, %entry ]
44  %sum.02 = and i32 %sum.02p, 255
45  %l2 = getelementptr inbounds i8, ptr %A, i32 %indvars.iv
46  %l3 = load i8, ptr %l2, align 4
47  %l3e = zext i8 %l3 to i32
48  %l9 = add i32 %sum.02, %l3e
49  %indvars.iv.next = add i32 %indvars.iv, 1
50  %exitcond = icmp eq i32 %indvars.iv.next, 256
51  br i1 %exitcond, label %exit, label %loop, !llvm.loop !0
52
53exit:                                      ; preds = %loop
54  %sum.0.lcssa = phi i32 [ %l9, %loop ]
55  %ret = trunc i32 %sum.0.lcssa to i8
56  ret i8 %ret
57}
58
59!0 = distinct !{!0, !1, !2, !3, !4}
60!1 = !{!"llvm.loop.vectorize.width", i32 8}
61!2 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
62!3 = !{!"llvm.loop.interleave.count", i32 2}
63!4 = !{!"llvm.loop.vectorize.enable", i1 true}
64