1; RUN: opt -O2 -S %s | FileCheck %s
2; RUN: opt -passes='default<O2>' -S %s | FileCheck %s
3
4target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-apple-macosx"
6
7; The loop below needs to be peeled first to eliminate the constant PHI %first
8; before loop vectorization.
9;
10; Test case from PR47671.
11
12define i32 @test(i32* readonly %p, i32* readnone %q) {
13; CHECK-LABEL: define i32 @test(
14; CHECK-NOT: vector.body
15;
16entry:
17  %cmp.not7 = icmp eq i32* %p, %q
18  br i1 %cmp.not7, label %exit, label %loop.ph
19
20loop.ph:
21  br label %loop
22
23loop:
24  %sum = phi i32 [ %sum.next, %loop ], [ 0, %loop.ph ]
25  %first = phi i1 [ false, %loop ], [ true, %loop.ph ]
26  %iv = phi i32* [ %iv.next, %loop ], [ %p, %loop.ph ]
27  %add = add nsw i32 %sum, 2
28  %spec.select = select i1 %first, i32 %sum, i32 %add
29  %lv = load i32, i32* %iv, align 4
30  %sum.next = add nsw i32 %lv, %spec.select
31  %iv.next = getelementptr inbounds i32, i32* %iv, i64 1
32  %cmp.not = icmp eq i32* %iv.next, %q
33  br i1 %cmp.not, label %loopexit, label %loop
34
35loopexit:
36  %sum.next.lcssa = phi i32 [ %sum.next, %loop ]
37  br label %exit
38
39exit:
40  %sum.0.lcssa = phi i32 [ 0, %entry ], [ %sum.next.lcssa, %loopexit ]
41  ret i32 %sum.0.lcssa
42}
43