1 ; RUN: opt -loop-reduce -S < %s | FileCheck %s 2 ; PR18000 3 4 target datalayout = "e-i64:64-f80:128-s:64-n8:16:32:64-S128" 5 target triple = "x86_64-unknown-linux-gnu" 6 7 @a = global i32 0, align 4 8 @b = common global i32 0, align 4 9 @e = common global i8 0, align 1 10 @d = common global i32 0, align 4 11 @c = common global i32 0, align 4 12 @.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1 13 14 ; Function Attrs: nounwind optsize uwtable 15 ; CHECK-LABEL: foo 16 define i32 @foo() { 17 entry: 18 %.pr = load i32* @b, align 4 19 %cmp10 = icmp slt i32 %.pr, 1 20 br i1 %cmp10, label %for.cond1.preheader.lr.ph, label %entry.for.end9_crit_edge 21 22 entry.for.end9_crit_edge: ; preds = %entry 23 %.pre = load i32* @c, align 4 24 br label %for.end9 25 26 for.cond1.preheader.lr.ph: ; preds = %entry 27 %0 = load i32* @a, align 4 28 %tobool = icmp eq i32 %0, 0 29 br i1 %tobool, label %for.cond1.preheader.for.cond1.preheader.split_crit_edge, label %return.loopexit.split 30 31 for.cond1.preheader.for.cond1.preheader.split_crit_edge: ; preds = %for.cond1.preheader.lr.ph, %for.inc8 32 %1 = phi i32 [ %inc, %for.inc8 ], [ %.pr, %for.cond1.preheader.lr.ph ] 33 br label %if.end 34 35 ; CHECK-LABEL: if.end 36 if.end: ; preds = %if.end, %for.cond1.preheader.for.cond1.preheader.split_crit_edge 37 38 ; CHECK: %lsr.iv = phi i32 [ %lsr.iv.next, %if.end ], [ 258, %for.cond1.preheader.for.cond1.preheader.split_crit_edge ] 39 %indvars.iv = phi i32 [ 1, %for.cond1.preheader.for.cond1.preheader.split_crit_edge ], [ %indvars.iv.next, %if.end ] 40 41 %2 = phi i8 [ 1, %for.cond1.preheader.for.cond1.preheader.split_crit_edge ], [ %dec, %if.end ] 42 %conv7 = mul i32 %indvars.iv, 258 43 %shl = and i32 %conv7, 510 44 store i32 %shl, i32* @c, align 4 45 46 ; CHECK: %lsr.iv.next = add i32 %lsr.iv, -258 47 %dec = add i8 %2, -1 48 49 %cmp2 = icmp sgt i8 %dec, -1 50 %indvars.iv.next = add i32 %indvars.iv, -1 51 br i1 %cmp2, label %if.end, label %for.inc8 52 53 for.inc8: ; preds = %if.end 54 store i32 0, i32* @d, align 4 55 %inc = add nsw i32 %1, 1 56 store i32 %inc, i32* @b, align 4 57 %cmp = icmp slt i32 %1, 0 58 br i1 %cmp, label %for.cond1.preheader.for.cond1.preheader.split_crit_edge, label %for.cond.for.end9_crit_edge 59 60 for.cond.for.end9_crit_edge: ; preds = %for.inc8 61 store i8 %dec, i8* @e, align 1 62 br label %for.end9 63 64 for.end9: ; preds = %entry.for.end9_crit_edge, %for.cond.for.end9_crit_edge 65 %3 = phi i32 [ %.pre, %entry.for.end9_crit_edge ], [ %shl, %for.cond.for.end9_crit_edge ] 66 %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @.str, i64 0, i64 0), i32 %3) #2 67 br label %return 68 69 return.loopexit.split: ; preds = %for.cond1.preheader.lr.ph 70 store i8 1, i8* @e, align 1 71 store i32 0, i32* @d, align 4 72 br label %return 73 74 return: ; preds = %return.loopexit.split, %for.end9 75 %retval.0 = phi i32 [ 0, %for.end9 ], [ 1, %return.loopexit.split ] 76 ret i32 %retval.0 77 } 78 79 ; Function Attrs: nounwind optsize 80 declare i32 @printf(i8* nocapture readonly, ...) 81 82