1 ; RUN: opt -S < %s -instcombine -inline -jump-threading -loop-unroll -unroll-count=4 | FileCheck %s 2 ; 3 ; This is a test case that required a number of setup passes because 4 ; it depends on block order. 5 6 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" 7 target triple = "x86_64-apple-macosx10.6.8" 8 9 declare i1 @check() nounwind 10 declare i32 @getval() nounwind 11 12 ; Check that the loop exit merges values from all the iterations. This 13 ; could be a tad fragile, but it's a good test. 14 ; 15 ; CHECK-LABEL: @foo( 16 ; CHECK: return: 17 ; CHECK: %retval.0 = phi i32 [ %tmp7.i, %land.lhs.true ], [ 0, %do.cond ], [ %tmp7.i.1, %land.lhs.true.1 ], [ 0, %do.cond.1 ], [ %tmp7.i.2, %land.lhs.true.2 ], [ 0, %do.cond.2 ], [ %tmp7.i.3, %land.lhs.true.3 ], [ 0, %do.cond.3 ] 18 ; CHECK-NOT: @bar( 19 ; CHECK: bar.exit.3 20 define i32 @foo() uwtable ssp align 2 { 21 entry: 22 br i1 undef, label %return, label %if.end 23 24 if.end: ; preds = %entry 25 %call2 = call i32 @getval() 26 br label %do.body 27 28 do.body: ; preds = %do.cond, %if.end 29 %call6 = call i32 @bar() 30 %cmp = icmp ne i32 %call6, 0 31 br i1 %cmp, label %land.lhs.true, label %do.cond 32 33 land.lhs.true: ; preds = %do.body 34 %call10 = call i32 @getval() 35 %cmp11 = icmp eq i32 0, %call10 36 br i1 %cmp11, label %return, label %do.cond 37 38 do.cond: ; preds = %land.lhs.true, %do.body 39 %cmp18 = icmp sle i32 0, %call2 40 br i1 %cmp18, label %do.body, label %return 41 42 return: ; preds = %do.cond, %land.lhs.true, %entry 43 %retval.0 = phi i32 [ 0, %entry ], [ %call6, %land.lhs.true ], [ 0, %do.cond ] 44 ret i32 %retval.0 45 } 46 47 define linkonce_odr i32 @bar() nounwind uwtable ssp align 2 { 48 entry: 49 br i1 undef, label %land.lhs.true, label %cond.end 50 51 land.lhs.true: ; preds = %entry 52 %cmp4 = call zeroext i1 @check() 53 br i1 %cmp4, label %cond.true, label %cond.end 54 55 cond.true: ; preds = %land.lhs.true 56 %tmp7 = call i32 @getval() 57 br label %cond.end 58 59 cond.end: ; preds = %cond.true, %land.lhs.true, %entry 60 %cond = phi i32 [ %tmp7, %cond.true ], [ 0, %land.lhs.true ], [ 0, %entry ] 61 ret i32 %cond 62 } 63