1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -basic-aa -slp-vectorizer -dce -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | 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"
5target triple = "x86_64-apple-macosx10.8.0"
6
7; SLP vectorization example from http://cs.stanford.edu/people/eschkufz/research/asplos291-schkufza.pdf
8define void @SAXPY(i32* noalias nocapture %x, i32* noalias nocapture %y, i32 %a, i64 %i) {
9; CHECK-LABEL: @SAXPY(
10; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, i32* [[X:%.*]], i64 [[I:%.*]]
11; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[Y:%.*]], i64 [[I]]
12; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP1]] to <4 x i32>*
13; CHECK-NEXT:    [[TMP4:%.*]] = load <4 x i32>, <4 x i32>* [[TMP3]], align 4
14; CHECK-NEXT:    [[TMP5:%.*]] = insertelement <4 x i32> poison, i32 [[A:%.*]], i32 0
15; CHECK-NEXT:    [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[TMP5]], <4 x i32> poison, <4 x i32> zeroinitializer
16; CHECK-NEXT:    [[TMP6:%.*]] = mul nsw <4 x i32> [[TMP4]], [[SHUFFLE]]
17; CHECK-NEXT:    [[TMP7:%.*]] = bitcast i32* [[TMP2]] to <4 x i32>*
18; CHECK-NEXT:    [[TMP8:%.*]] = load <4 x i32>, <4 x i32>* [[TMP7]], align 4
19; CHECK-NEXT:    [[TMP9:%.*]] = add nsw <4 x i32> [[TMP6]], [[TMP8]]
20; CHECK-NEXT:    [[TMP10:%.*]] = bitcast i32* [[TMP1]] to <4 x i32>*
21; CHECK-NEXT:    store <4 x i32> [[TMP9]], <4 x i32>* [[TMP10]], align 4
22; CHECK-NEXT:    ret void
23;
24  %1 = getelementptr inbounds i32, i32* %x, i64 %i
25  %2 = load i32, i32* %1, align 4
26  %3 = mul nsw i32 %2, %a
27  %4 = getelementptr inbounds i32, i32* %y, i64 %i
28  %5 = load i32, i32* %4, align 4
29  %6 = add nsw i32 %3, %5
30  store i32 %6, i32* %1, align 4
31  %7 = add i64 %i, 1
32  %8 = getelementptr inbounds i32, i32* %x, i64 %7
33  %9 = load i32, i32* %8, align 4
34  %10 = mul nsw i32 %9, %a
35  %11 = getelementptr inbounds i32, i32* %y, i64 %7
36  %12 = load i32, i32* %11, align 4
37  %13 = add nsw i32 %10, %12
38  store i32 %13, i32* %8, align 4
39  %14 = add i64 %i, 2
40  %15 = getelementptr inbounds i32, i32* %x, i64 %14
41  %16 = load i32, i32* %15, align 4
42  %17 = mul nsw i32 %16, %a
43  %18 = getelementptr inbounds i32, i32* %y, i64 %14
44  %19 = load i32, i32* %18, align 4
45  %20 = add nsw i32 %17, %19
46  store i32 %20, i32* %15, align 4
47  %21 = add i64 %i, 3
48  %22 = getelementptr inbounds i32, i32* %x, i64 %21
49  %23 = load i32, i32* %22, align 4
50  %24 = mul nsw i32 %23, %a
51  %25 = getelementptr inbounds i32, i32* %y, i64 %21
52  %26 = load i32, i32* %25, align 4
53  %27 = add nsw i32 %24, %26
54  store i32 %27, i32* %22, align 4
55  ret void
56}
57
58; Make sure we don't crash on this one.
59define void @SAXPY_crash(i32* noalias nocapture %x, i32* noalias nocapture %y, i64 %i) {
60; CHECK-LABEL: @SAXPY_crash(
61; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[I:%.*]], 1
62; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32, i32* [[X:%.*]], i64 [[TMP1]]
63; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[Y:%.*]], i64 [[TMP1]]
64; CHECK-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <2 x i32>*
65; CHECK-NEXT:    [[TMP5:%.*]] = load <2 x i32>, <2 x i32>* [[TMP4]], align 4
66; CHECK-NEXT:    [[TMP6:%.*]] = add nsw <2 x i32> undef, [[TMP5]]
67; CHECK-NEXT:    [[TMP7:%.*]] = bitcast i32* [[TMP2]] to <2 x i32>*
68; CHECK-NEXT:    store <2 x i32> [[TMP6]], <2 x i32>* [[TMP7]], align 4
69; CHECK-NEXT:    ret void
70;
71  %1 = add i64 %i, 1
72  %2 = getelementptr inbounds i32, i32* %x, i64 %1
73  %3 = getelementptr inbounds i32, i32* %y, i64 %1
74  %4 = load i32, i32* %3, align 4
75  %5 = add nsw i32 undef, %4
76  store i32 %5, i32* %2, align 4
77  %6 = add i64 %i, 2
78  %7 = getelementptr inbounds i32, i32* %x, i64 %6
79  %8 = getelementptr inbounds i32, i32* %y, i64 %6
80  %9 = load i32, i32* %8, align 4
81  %10 = add nsw i32 undef, %9
82  store i32 %10, i32* %7, align 4
83  ret void
84}
85