1; RUN: opt -simplifycfg -S < %s | FileCheck %s 2 3; It's not worthwhile to if-convert one of the phi nodes and leave 4; the other behind, because that still requires a branch. If 5; SimplifyCFG if-converts one of the phis, it should do both. 6 7; CHECK: %div.high.addr.0 = select i1 %cmp1, i32 %div, i32 %high.addr.0 8; CHECK-NEXT: %low.0.add2 = select i1 %cmp1, i32 %low.0, i32 %add2 9; CHECK-NEXT: br label %while.cond 10 11define i32 @upper_bound(i32* %r, i32 %high, i32 %k) nounwind { 12entry: 13 br label %while.cond 14 15while.cond: ; preds = %if.then, %if.else, %entry 16 %high.addr.0 = phi i32 [ %high, %entry ], [ %div, %if.then ], [ %high.addr.0, %if.else ] 17 %low.0 = phi i32 [ 0, %entry ], [ %low.0, %if.then ], [ %add2, %if.else ] 18 %cmp = icmp ult i32 %low.0, %high.addr.0 19 br i1 %cmp, label %while.body, label %while.end 20 21while.body: ; preds = %while.cond 22 %add = add i32 %low.0, %high.addr.0 23 %div = udiv i32 %add, 2 24 %idxprom = zext i32 %div to i64 25 %arrayidx = getelementptr inbounds i32, i32* %r, i64 %idxprom 26 %0 = load i32, i32* %arrayidx 27 %cmp1 = icmp ult i32 %k, %0 28 br i1 %cmp1, label %if.then, label %if.else 29 30if.then: ; preds = %while.body 31 br label %while.cond 32 33if.else: ; preds = %while.body 34 %add2 = add i32 %div, 1 35 br label %while.cond 36 37while.end: ; preds = %while.cond 38 ret i32 %low.0 39} 40