1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -mtriple=x86_64-pc-linux-gnu -mcpu=generic -slp-vectorizer -pass-remarks-output=%t < %s | FileCheck %s
3 ; RUN: FileCheck --input-file=%t --check-prefix=YAML %s
5 define i32 @foo(i32* %diff) #0 {
8 ; CHECK-NEXT: [[M2:%.*]] = alloca [8 x [8 x i32]], align 16
9 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast [8 x [8 x i32]]* [[M2]] to i8*
10 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
12 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
13 ; CHECK-NEXT: [[A_088:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[OP_EXTRA:%.*]], [[FOR_BODY]] ]
14 ; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[INDVARS_IV]], 3
15 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[DIFF:%.*]], i64 [[TMP1]]
16 ; CHECK-NEXT: [[TMP2:%.*]] = or i64 [[TMP1]], 4
17 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, i32* [[DIFF]], i64 [[TMP2]]
18 ; CHECK-NEXT: [[ARRAYIDX6:%.*]] = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* [[M2]], i64 0, i64 [[INDVARS_IV]], i64 0
19 ; CHECK-NEXT: [[TMP3:%.*]] = or i64 [[TMP1]], 1
20 ; CHECK-NEXT: [[ARRAYIDX13:%.*]] = getelementptr inbounds i32, i32* [[DIFF]], i64 [[TMP3]]
21 ; CHECK-NEXT: [[TMP4:%.*]] = or i64 [[TMP1]], 5
22 ; CHECK-NEXT: [[ARRAYIDX16:%.*]] = getelementptr inbounds i32, i32* [[DIFF]], i64 [[TMP4]]
23 ; CHECK-NEXT: [[TMP5:%.*]] = or i64 [[TMP1]], 2
24 ; CHECK-NEXT: [[ARRAYIDX27:%.*]] = getelementptr inbounds i32, i32* [[DIFF]], i64 [[TMP5]]
25 ; CHECK-NEXT: [[TMP6:%.*]] = or i64 [[TMP1]], 6
26 ; CHECK-NEXT: [[ARRAYIDX30:%.*]] = getelementptr inbounds i32, i32* [[DIFF]], i64 [[TMP6]]
27 ; CHECK-NEXT: [[TMP7:%.*]] = or i64 [[TMP1]], 3
28 ; CHECK-NEXT: [[ARRAYIDX41:%.*]] = getelementptr inbounds i32, i32* [[DIFF]], i64 [[TMP7]]
29 ; CHECK-NEXT: [[TMP8:%.*]] = bitcast i32* [[ARRAYIDX]] to <4 x i32>*
30 ; CHECK-NEXT: [[TMP9:%.*]] = load <4 x i32>, <4 x i32>* [[TMP8]], align 4
31 ; CHECK-NEXT: [[TMP10:%.*]] = or i64 [[TMP1]], 7
32 ; CHECK-NEXT: [[ARRAYIDX44:%.*]] = getelementptr inbounds i32, i32* [[DIFF]], i64 [[TMP10]]
33 ; CHECK-NEXT: [[TMP11:%.*]] = bitcast i32* [[ARRAYIDX2]] to <4 x i32>*
34 ; CHECK-NEXT: [[TMP12:%.*]] = load <4 x i32>, <4 x i32>* [[TMP11]], align 4
35 ; CHECK-NEXT: [[TMP13:%.*]] = add nsw <4 x i32> [[TMP12]], [[TMP9]]
36 ; CHECK-NEXT: [[ARRAYIDX20:%.*]] = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* [[M2]], i64 0, i64 [[INDVARS_IV]], i64 1
37 ; CHECK-NEXT: [[ARRAYIDX34:%.*]] = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* [[M2]], i64 0, i64 [[INDVARS_IV]], i64 2
38 ; CHECK-NEXT: [[ARRAYIDX48:%.*]] = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* [[M2]], i64 0, i64 [[INDVARS_IV]], i64 3
39 ; CHECK-NEXT: [[TMP14:%.*]] = bitcast i32* [[ARRAYIDX6]] to <4 x i32>*
40 ; CHECK-NEXT: store <4 x i32> [[TMP13]], <4 x i32>* [[TMP14]], align 16
41 ; CHECK-NEXT: [[TMP15:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP13]])
42 ; CHECK-NEXT: [[OP_EXTRA]] = add nsw i32 [[TMP15]], [[A_088]]
43 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
44 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 8
45 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
47 ; CHECK-NEXT: ret i32 [[OP_EXTRA]]
50 %m2 = alloca [8 x [8 x i32]], align 16
51 %0 = bitcast [8 x [8 x i32]]* %m2 to i8*
54 for.body: ; preds = %for.body, %entry
55 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
56 %a.088 = phi i32 [ 0, %entry ], [ %add52, %for.body ]
57 %1 = shl i64 %indvars.iv, 3
58 %arrayidx = getelementptr inbounds i32, i32* %diff, i64 %1
59 %2 = load i32, i32* %arrayidx, align 4
61 %arrayidx2 = getelementptr inbounds i32, i32* %diff, i64 %3
62 %4 = load i32, i32* %arrayidx2, align 4
63 %add3 = add nsw i32 %4, %2
64 %arrayidx6 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 0
65 store i32 %add3, i32* %arrayidx6, align 16
67 %add10 = add nsw i32 %add3, %a.088
69 %arrayidx13 = getelementptr inbounds i32, i32* %diff, i64 %5
70 %6 = load i32, i32* %arrayidx13, align 4
72 %arrayidx16 = getelementptr inbounds i32, i32* %diff, i64 %7
73 %8 = load i32, i32* %arrayidx16, align 4
74 %add17 = add nsw i32 %8, %6
75 %arrayidx20 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 1
76 store i32 %add17, i32* %arrayidx20, align 4
78 %add24 = add nsw i32 %add10, %add17
80 %arrayidx27 = getelementptr inbounds i32, i32* %diff, i64 %9
81 %10 = load i32, i32* %arrayidx27, align 4
83 %arrayidx30 = getelementptr inbounds i32, i32* %diff, i64 %11
84 %12 = load i32, i32* %arrayidx30, align 4
85 %add31 = add nsw i32 %12, %10
86 %arrayidx34 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 2
87 store i32 %add31, i32* %arrayidx34, align 8
89 %add38 = add nsw i32 %add24, %add31
91 %arrayidx41 = getelementptr inbounds i32, i32* %diff, i64 %13
92 %14 = load i32, i32* %arrayidx41, align 4
94 %arrayidx44 = getelementptr inbounds i32, i32* %diff, i64 %15
95 %16 = load i32, i32* %arrayidx44, align 4
97 %add45 = add nsw i32 %16, %14
98 %arrayidx48 = getelementptr inbounds [8 x [8 x i32]], [8 x [8 x i32]]* %m2, i64 0, i64 %indvars.iv, i64 3
99 store i32 %add45, i32* %arrayidx48, align 4
101 %add52 = add nsw i32 %add38, %add45
104 ; YAML-NEXT: Pass: slp-vectorizer
105 ; YAML-NEXT: Name: StoresVectorized
106 ; YAML-NEXT: Function: foo
108 ; YAML-NEXT: - String: 'Stores SLP vectorized with cost '
109 ; YAML-NEXT: - Cost: '-5'
110 ; YAML-NEXT: - String: ' and with tree size '
111 ; YAML-NEXT: - TreeSize: '4'
114 ; YAML-NEXT: Pass: slp-vectorizer
115 ; YAML-NEXT: Name: VectorizedHorizontalReduction
116 ; YAML-NEXT: Function: foo
118 ; YAML-NEXT: - String: 'Vectorized horizontal reduction with cost '
119 ; YAML-NEXT: - Cost: '-7'
120 ; YAML-NEXT: - String: ' and with tree size '
121 ; YAML-NEXT: - TreeSize: '1'
123 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
124 %exitcond = icmp eq i64 %indvars.iv.next, 8
125 br i1 %exitcond, label %for.end, label %for.body
127 for.end: ; preds = %for.body