1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -simplifycfg -keep-loops=false -S < %s | FileCheck %s 3 4; It's not worthwhile to if-convert one of the phi nodes and leave 5; the other behind, because that still requires a branch. If 6; SimplifyCFG if-converts one of the phis, it should do both. 7 8define i32 @upper_bound(i32* %r, i32 %high, i32 %k) nounwind { 9; CHECK-LABEL: @upper_bound( 10; CHECK-NEXT: entry: 11; CHECK-NEXT: br label [[WHILE_COND:%.*]] 12; CHECK: while.cond: 13; CHECK-NEXT: [[HIGH_ADDR_0:%.*]] = phi i32 [ [[HIGH:%.*]], [[ENTRY:%.*]] ], [ [[DIV_HIGH_ADDR_0:%.*]], [[WHILE_BODY:%.*]] ] 14; CHECK-NEXT: [[LOW_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[LOW_0_ADD2:%.*]], [[WHILE_BODY]] ] 15; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[LOW_0]], [[HIGH_ADDR_0]] 16; CHECK-NEXT: br i1 [[CMP]], label [[WHILE_BODY]], label [[WHILE_END:%.*]] 17; CHECK: while.body: 18; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LOW_0]], [[HIGH_ADDR_0]] 19; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[ADD]], 2 20; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[DIV]] to i64 21; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[R:%.*]], i64 [[IDXPROM]] 22; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]] 23; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i32 [[K:%.*]], [[TMP0]] 24; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[DIV]], 1 25; CHECK-NEXT: [[DIV_HIGH_ADDR_0]] = select i1 [[CMP1]], i32 [[DIV]], i32 [[HIGH_ADDR_0]] 26; CHECK-NEXT: [[LOW_0_ADD2]] = select i1 [[CMP1]], i32 [[LOW_0]], i32 [[ADD2]] 27; CHECK-NEXT: br label [[WHILE_COND]] 28; CHECK: while.end: 29; CHECK-NEXT: ret i32 [[LOW_0]] 30; 31entry: 32 br label %while.cond 33 34while.cond: ; preds = %if.then, %if.else, %entry 35 %high.addr.0 = phi i32 [ %high, %entry ], [ %div, %if.then ], [ %high.addr.0, %if.else ] 36 %low.0 = phi i32 [ 0, %entry ], [ %low.0, %if.then ], [ %add2, %if.else ] 37 %cmp = icmp ult i32 %low.0, %high.addr.0 38 br i1 %cmp, label %while.body, label %while.end 39 40while.body: ; preds = %while.cond 41 %add = add i32 %low.0, %high.addr.0 42 %div = udiv i32 %add, 2 43 %idxprom = zext i32 %div to i64 44 %arrayidx = getelementptr inbounds i32, i32* %r, i64 %idxprom 45 %0 = load i32, i32* %arrayidx 46 %cmp1 = icmp ult i32 %k, %0 47 br i1 %cmp1, label %if.then, label %if.else 48 49if.then: ; preds = %while.body 50 br label %while.cond 51 52if.else: ; preds = %while.body 53 %add2 = add i32 %div, 1 54 br label %while.cond 55 56while.end: ; preds = %while.cond 57 ret i32 %low.0 58} 59