1; RUN: opt -S -loop-unroll -unroll-runtime < %s | FileCheck %s 2 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. 6 7; CHECK-LABEL: const_phi_val 8; CHECK: for.body.epil 9 10; Function Attrs: norecurse nounwind uwtable 11define void @const_phi_val(i32 %i0, i32* nocapture %a) { 12entry: 13 %cmp6 = icmp slt i32 %i0, 1000 14 br i1 %cmp6, label %for.body.preheader, label %for.end 15 16for.body.preheader: ; preds = %entry 17 %tmp = sext i32 %i0 to i64 18 br label %for.body 19 20for.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 29 30for.end.loopexit: ; preds = %for.body 31 br label %for.end 32 33for.end: ; preds = %for.end.loopexit, %entry 34 ret void 35} 36 37; When there is no phi with const coming from preheader, 38; there is no need to do epilogue unrolling. 39 40; CHECK-LABEL: var_phi_val 41; CHECK: for.body.prol 42 43; Function Attrs: norecurse nounwind uwtable 44define void @var_phi_val(i32 %i0, i32* nocapture %a) { 45entry: 46 %cmp6 = icmp slt i32 %i0, 1000 47 br i1 %cmp6, label %for.body.preheader, label %for.end 48 49for.body.preheader: ; preds = %entry 50 %tmp = sext i32 %i0 to i64 51 br label %for.body 52 53for.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 59 60for.end.loopexit: ; preds = %for.body 61 br label %for.end 62 63for.end: ; preds = %for.end.loopexit, %entry 64 ret void 65} 66