xref: /llvm-project/llvm/test/Transforms/PhaseOrdering/X86/peel-before-lv-to-enable-vectorization.ll (revision 1c55cc600e99a963233d6f467373c8f16a1b8826)
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(ptr readonly %p, ptr readnone %q) {
13; CHECK-LABEL: define i32 @test(
14; CHECK: vector.body:
15; CHECK:   %index.next = add nuw i64 %index, 8
16; CHECK: middle.block:
17;
18entry:
19  %cmp.not7 = icmp eq ptr %p, %q
20  br i1 %cmp.not7, label %exit, label %loop.ph
21
22loop.ph:
23  br label %loop
24
25loop:
26  %sum = phi i32 [ %sum.next, %loop ], [ 0, %loop.ph ]
27  %first = phi i1 [ false, %loop ], [ true, %loop.ph ]
28  %iv = phi ptr [ %iv.next, %loop ], [ %p, %loop.ph ]
29  %add = add nsw i32 %sum, 2
30  %spec.select = select i1 %first, i32 %sum, i32 %add
31  %lv = load i32, ptr %iv, align 4
32  %sum.next = add nsw i32 %lv, %spec.select
33  %iv.next = getelementptr inbounds i32, ptr %iv, i64 1
34  %cmp.not = icmp eq ptr %iv.next, %q
35  br i1 %cmp.not, label %loopexit, label %loop
36
37loopexit:
38  %sum.next.lcssa = phi i32 [ %sum.next, %loop ]
39  br label %exit
40
41exit:
42  %sum.0.lcssa = phi i32 [ 0, %entry ], [ %sum.next.lcssa, %loopexit ]
43  ret i32 %sum.0.lcssa
44}
45