1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=slp-vectorizer -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
4 target 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 target triple = "x86_64-apple-macosx10.8.0"
7 ; int foo(int * restrict B, int * restrict A, int n, int m) {
8 ; B[0] = n * A[0] + m * A[0];
9 ; B[1] = n * A[1] + m * A[1];
10 ; B[2] = n * A[2] + m * A[2];
11 ; B[3] = n * A[3] + m * A[3];
15 define i32 @foo(ptr noalias nocapture %B, ptr noalias nocapture %A, i32 %n, i32 %m) #0 {
18 ; CHECK-NEXT: [[MUL238:%.*]] = add i32 [[M:%.*]], [[N:%.*]]
19 ; CHECK-NEXT: [[TMP1:%.*]] = load <4 x i32>, ptr [[A:%.*]], align 4
20 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> poison, i32 [[MUL238]], i32 0
21 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> poison, <4 x i32> zeroinitializer
22 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i32> [[TMP1]], [[SHUFFLE]]
23 ; CHECK-NEXT: store <4 x i32> [[TMP3]], ptr [[B:%.*]], align 4
24 ; CHECK-NEXT: ret i32 0
27 %0 = load i32, ptr %A, align 4
28 %mul238 = add i32 %m, %n
29 %add = mul i32 %0, %mul238
30 store i32 %add, ptr %B, align 4
31 %arrayidx4 = getelementptr inbounds i32, ptr %A, i64 1
32 %1 = load i32, ptr %arrayidx4, align 4
33 %add8 = mul i32 %1, %mul238
34 %arrayidx9 = getelementptr inbounds i32, ptr %B, i64 1
35 store i32 %add8, ptr %arrayidx9, align 4
36 %arrayidx10 = getelementptr inbounds i32, ptr %A, i64 2
37 %2 = load i32, ptr %arrayidx10, align 4
38 %add14 = mul i32 %2, %mul238
39 %arrayidx15 = getelementptr inbounds i32, ptr %B, i64 2
40 store i32 %add14, ptr %arrayidx15, align 4
41 %arrayidx16 = getelementptr inbounds i32, ptr %A, i64 3
42 %3 = load i32, ptr %arrayidx16, align 4
43 %add20 = mul i32 %3, %mul238
44 %arrayidx21 = getelementptr inbounds i32, ptr %B, i64 3
45 store i32 %add20, ptr %arrayidx21, align 4
50 ; int extr_user(int * restrict B, int * restrict A, int n, int m) {
51 ; B[0] = n * A[0] + m * A[0];
52 ; B[1] = n * A[1] + m * A[1];
53 ; B[2] = n * A[2] + m * A[2];
54 ; B[3] = n * A[3] + m * A[3];
58 define i32 @extr_user(ptr noalias nocapture %B, ptr noalias nocapture %A, i32 %n, i32 %m) {
59 ; CHECK-LABEL: @extr_user(
61 ; CHECK-NEXT: [[MUL238:%.*]] = add i32 [[M:%.*]], [[N:%.*]]
62 ; CHECK-NEXT: [[TMP1:%.*]] = load <4 x i32>, ptr [[A:%.*]], align 4
63 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> poison, i32 [[MUL238]], i32 0
64 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> poison, <4 x i32> zeroinitializer
65 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i32> [[TMP1]], [[SHUFFLE]]
66 ; CHECK-NEXT: store <4 x i32> [[TMP3]], ptr [[B:%.*]], align 4
67 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x i32> [[TMP1]], i32 0
68 ; CHECK-NEXT: ret i32 [[TMP5]]
71 %0 = load i32, ptr %A, align 4
72 %mul238 = add i32 %m, %n
73 %add = mul i32 %0, %mul238
74 store i32 %add, ptr %B, align 4
75 %arrayidx4 = getelementptr inbounds i32, ptr %A, i64 1
76 %1 = load i32, ptr %arrayidx4, align 4
77 %add8 = mul i32 %1, %mul238
78 %arrayidx9 = getelementptr inbounds i32, ptr %B, i64 1
79 store i32 %add8, ptr %arrayidx9, align 4
80 %arrayidx10 = getelementptr inbounds i32, ptr %A, i64 2
81 %2 = load i32, ptr %arrayidx10, align 4
82 %add14 = mul i32 %2, %mul238
83 %arrayidx15 = getelementptr inbounds i32, ptr %B, i64 2
84 store i32 %add14, ptr %arrayidx15, align 4
85 %arrayidx16 = getelementptr inbounds i32, ptr %A, i64 3
86 %3 = load i32, ptr %arrayidx16, align 4
87 %add20 = mul i32 %3, %mul238
88 %arrayidx21 = getelementptr inbounds i32, ptr %B, i64 3
89 store i32 %add20, ptr %arrayidx21, align 4
90 ret i32 %0 ;<--------- This value has multiple users
93 ; In this example we have an external user that is not the first element in the vector.
94 define i32 @extr_user1(ptr noalias nocapture %B, ptr noalias nocapture %A, i32 %n, i32 %m) {
95 ; CHECK-LABEL: @extr_user1(
97 ; CHECK-NEXT: [[MUL238:%.*]] = add i32 [[M:%.*]], [[N:%.*]]
98 ; CHECK-NEXT: [[TMP1:%.*]] = load <4 x i32>, ptr [[A:%.*]], align 4
99 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> poison, i32 [[MUL238]], i32 0
100 ; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> poison, <4 x i32> zeroinitializer
101 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i32> [[TMP1]], [[SHUFFLE]]
102 ; CHECK-NEXT: store <4 x i32> [[TMP3]], ptr [[B:%.*]], align 4
103 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x i32> [[TMP1]], i32 1
104 ; CHECK-NEXT: ret i32 [[TMP5]]
107 %0 = load i32, ptr %A, align 4
108 %mul238 = add i32 %m, %n
109 %add = mul i32 %0, %mul238
110 store i32 %add, ptr %B, align 4
111 %arrayidx4 = getelementptr inbounds i32, ptr %A, i64 1
112 %1 = load i32, ptr %arrayidx4, align 4
113 %add8 = mul i32 %1, %mul238
114 %arrayidx9 = getelementptr inbounds i32, ptr %B, i64 1
115 store i32 %add8, ptr %arrayidx9, align 4
116 %arrayidx10 = getelementptr inbounds i32, ptr %A, i64 2
117 %2 = load i32, ptr %arrayidx10, align 4
118 %add14 = mul i32 %2, %mul238
119 %arrayidx15 = getelementptr inbounds i32, ptr %B, i64 2
120 store i32 %add14, ptr %arrayidx15, align 4
121 %arrayidx16 = getelementptr inbounds i32, ptr %A, i64 3
122 %3 = load i32, ptr %arrayidx16, align 4
123 %add20 = mul i32 %3, %mul238
124 %arrayidx21 = getelementptr inbounds i32, ptr %B, i64 3
125 store i32 %add20, ptr %arrayidx21, align 4
126 ret i32 %1 ;<--------- This value has multiple users