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: [[TMP0:%.*]] = load <4 x i32>, ptr [[A:%.*]], align 4
20 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x i32> poison, i32 [[MUL238]], i32 0
21 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> poison, <4 x i32> zeroinitializer
22 ; CHECK-NEXT: [[TMP3:%.*]] = mul <4 x i32> [[TMP0]], [[TMP2]]
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: [[TMP0:%.*]] = load <4 x i32>, ptr [[A:%.*]], align 4
63 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 4
64 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> poison, i32 [[MUL238]], i32 0
65 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> poison, <4 x i32> zeroinitializer
66 ; CHECK-NEXT: [[TMP4:%.*]] = mul <4 x i32> [[TMP0]], [[TMP3]]
67 ; CHECK-NEXT: store <4 x i32> [[TMP4]], ptr [[B:%.*]], align 4
68 ; CHECK-NEXT: ret i32 [[TMP1]]
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: [[ARRAYIDX4:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 1
99 ; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i32>, ptr [[A]], align 4
100 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX4]], align 4
101 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x i32> poison, i32 [[MUL238]], i32 0
102 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> poison, <4 x i32> zeroinitializer
103 ; CHECK-NEXT: [[TMP4:%.*]] = mul <4 x i32> [[TMP0]], [[TMP3]]
104 ; CHECK-NEXT: store <4 x i32> [[TMP4]], ptr [[B:%.*]], align 4
105 ; CHECK-NEXT: ret i32 [[TMP1]]
108 %0 = load i32, ptr %A, align 4
109 %mul238 = add i32 %m, %n
110 %add = mul i32 %0, %mul238
111 store i32 %add, ptr %B, align 4
112 %arrayidx4 = getelementptr inbounds i32, ptr %A, i64 1
113 %1 = load i32, ptr %arrayidx4, align 4
114 %add8 = mul i32 %1, %mul238
115 %arrayidx9 = getelementptr inbounds i32, ptr %B, i64 1
116 store i32 %add8, ptr %arrayidx9, align 4
117 %arrayidx10 = getelementptr inbounds i32, ptr %A, i64 2
118 %2 = load i32, ptr %arrayidx10, align 4
119 %add14 = mul i32 %2, %mul238
120 %arrayidx15 = getelementptr inbounds i32, ptr %B, i64 2
121 store i32 %add14, ptr %arrayidx15, align 4
122 %arrayidx16 = getelementptr inbounds i32, ptr %A, i64 3
123 %3 = load i32, ptr %arrayidx16, align 4
124 %add20 = mul i32 %3, %mul238
125 %arrayidx21 = getelementptr inbounds i32, ptr %B, i64 3
126 store i32 %add20, ptr %arrayidx21, align 4
127 ret i32 %1 ;<--------- This value has multiple users