[SLP] Treat SelectInsts as reduction values.
[oota-llvm.git] / test / Transforms / SLPVectorizer / AArch64 / horizontal.ll
1 ; RUN: opt -slp-vectorizer -slp-threshold=-6 -slp-vectorize-hor -S <  %s | FileCheck %s
2
3 ; FIXME: The threshold is changed to keep this test case a bit smaller.
4 ; The AArch64 cost model should not give such high costs to select statements.
5
6 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
7 target triple = "aarch64--linux"
8
9 ; CHECK-LABEL: test_select
10 ; CHECK: load <4 x i32>
11 ; CHECK: load <4 x i32>
12 ; CHECK: select <4 x i1>
13 define i32 @test_select(i32* noalias nocapture readonly %blk1, i32* noalias nocapture readonly %blk2, i32 %lx, i32 %h) {
14 entry:
15   %cmp.22 = icmp sgt i32 %h, 0
16   br i1 %cmp.22, label %for.body.lr.ph, label %for.end
17
18 for.body.lr.ph:                                   ; preds = %entry
19   %idx.ext = sext i32 %lx to i64
20   br label %for.body
21
22 for.body:                                         ; preds = %for.body, %for.body.lr.ph
23   %s.026 = phi i32 [ 0, %for.body.lr.ph ], [ %add27, %for.body ]
24   %j.025 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
25   %p2.024 = phi i32* [ %blk2, %for.body.lr.ph ], [ %add.ptr29, %for.body ]
26   %p1.023 = phi i32* [ %blk1, %for.body.lr.ph ], [ %add.ptr, %for.body ]
27   %0 = load i32, i32* %p1.023, align 4
28   %1 = load i32, i32* %p2.024, align 4
29   %sub = sub nsw i32 %0, %1
30   %cmp2 = icmp slt i32 %sub, 0
31   %sub3 = sub nsw i32 0, %sub
32   %sub3.sub = select i1 %cmp2, i32 %sub3, i32 %sub
33   %add = add nsw i32 %sub3.sub, %s.026
34   %arrayidx4 = getelementptr inbounds i32, i32* %p1.023, i64 1
35   %2 = load i32, i32* %arrayidx4, align 4
36   %arrayidx5 = getelementptr inbounds i32, i32* %p2.024, i64 1
37   %3 = load i32, i32* %arrayidx5, align 4
38   %sub6 = sub nsw i32 %2, %3
39   %cmp7 = icmp slt i32 %sub6, 0
40   %sub9 = sub nsw i32 0, %sub6
41   %v.1 = select i1 %cmp7, i32 %sub9, i32 %sub6
42   %add11 = add nsw i32 %add, %v.1
43   %arrayidx12 = getelementptr inbounds i32, i32* %p1.023, i64 2
44   %4 = load i32, i32* %arrayidx12, align 4
45   %arrayidx13 = getelementptr inbounds i32, i32* %p2.024, i64 2
46   %5 = load i32, i32* %arrayidx13, align 4
47   %sub14 = sub nsw i32 %4, %5
48   %cmp15 = icmp slt i32 %sub14, 0
49   %sub17 = sub nsw i32 0, %sub14
50   %sub17.sub14 = select i1 %cmp15, i32 %sub17, i32 %sub14
51   %add19 = add nsw i32 %add11, %sub17.sub14
52   %arrayidx20 = getelementptr inbounds i32, i32* %p1.023, i64 3
53   %6 = load i32, i32* %arrayidx20, align 4
54   %arrayidx21 = getelementptr inbounds i32, i32* %p2.024, i64 3
55   %7 = load i32, i32* %arrayidx21, align 4
56   %sub22 = sub nsw i32 %6, %7
57   %cmp23 = icmp slt i32 %sub22, 0
58   %sub25 = sub nsw i32 0, %sub22
59   %v.3 = select i1 %cmp23, i32 %sub25, i32 %sub22
60   %add27 = add nsw i32 %add19, %v.3
61   %add.ptr = getelementptr inbounds i32, i32* %p1.023, i64 %idx.ext
62   %add.ptr29 = getelementptr inbounds i32, i32* %p2.024, i64 %idx.ext
63   %inc = add nuw nsw i32 %j.025, 1
64   %exitcond = icmp eq i32 %inc, %h
65   br i1 %exitcond, label %for.end.loopexit, label %for.body
66
67 for.end.loopexit:                                 ; preds = %for.body
68   br label %for.end
69
70 for.end:                                          ; preds = %for.end.loopexit, %entry
71   %s.0.lcssa = phi i32 [ 0, %entry ], [ %add27, %for.end.loopexit ]
72   ret i32 %s.0.lcssa
73 }