1 ; RUN: opt -S -loop-unroll -unroll-runtime < %s | FileCheck %s
3 ; Epilog unroll allows to keep PHI constant value.
4 ; For the test this means that after unroll XOR could be deleted.
5 ; Check that we do epilogue reminder here.
7 ; CHECK-LABEL: const_phi_val
10 ; Function Attrs: norecurse nounwind uwtable
11 define void @const_phi_val(i32 %i0, i32* nocapture %a) {
13 %cmp6 = icmp slt i32 %i0, 1000
14 br i1 %cmp6, label %for.body.preheader, label %for.end
16 for.body.preheader: ; preds = %entry
17 %tmp = sext i32 %i0 to i64
20 for.body: ; preds = %for.body, %for.body.preheader
21 %indvars.iv = phi i64 [ %tmp, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
22 %s.08 = phi i32 [ 0, %for.body.preheader ], [ %xor, %for.body ]
23 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
24 store i32 %s.08, i32* %arrayidx, align 4
25 %xor = xor i32 %s.08, 1
26 %indvars.iv.next = add nsw i64 %indvars.iv, 1
27 %exitcond = icmp eq i64 %indvars.iv.next, 1000
28 br i1 %exitcond, label %for.end.loopexit, label %for.body
30 for.end.loopexit: ; preds = %for.body
33 for.end: ; preds = %for.end.loopexit, %entry
37 ; When there is no phi with const coming from preheader,
38 ; there is no need to do epilogue unrolling.
40 ; CHECK-LABEL: var_phi_val
41 ; CHECK: for.body.prol
43 ; Function Attrs: norecurse nounwind uwtable
44 define void @var_phi_val(i32 %i0, i32* nocapture %a) {
46 %cmp6 = icmp slt i32 %i0, 1000
47 br i1 %cmp6, label %for.body.preheader, label %for.end
49 for.body.preheader: ; preds = %entry
50 %tmp = sext i32 %i0 to i64
53 for.body: ; preds = %for.body, %for.body.preheader
54 %indvars.iv = phi i64 [ %tmp, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
55 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
56 %indvars.iv.next = add nsw i64 %indvars.iv, 1
57 %exitcond = icmp eq i64 %indvars.iv.next, 1000
58 br i1 %exitcond, label %for.end.loopexit, label %for.body
60 for.end.loopexit: ; preds = %for.body
63 for.end: ; preds = %for.end.loopexit, %entry