1; RUN: opt -S -structurizecfg %s | FileCheck %s 2 3; r321751 introduced a bug where control flow branching from if to exit was 4; not handled properly and instead ended up in an infinite loop. 5define void @bug36015(i32 %cmp0, i32 %count) { 6entry: 7 br label %loop.outer 8 9loop.outer: 10 %ctr.loop.outer = phi i32 [ 0, %entry ], [ %ctr.else, %else ] 11 call void @foo(i32 0) 12 br label %loop.inner 13 14loop.inner: 15 %ctr.loop.inner = phi i32 [ %ctr.loop.outer, %loop.outer ], [ %ctr.if, %if ] 16 call void @foo(i32 1) 17 %cond.inner = icmp eq i32 %cmp0, %ctr.loop.inner 18 br i1 %cond.inner, label %if, label %else 19 20; CHECK: if: 21; CHECK: %0 = xor i1 %cond.if, true 22; CHECK: br label %Flow 23if: 24 %ctr.if = add i32 %ctr.loop.inner, 1 25 call void @foo(i32 2) 26 %cond.if = icmp slt i32 %ctr.if, %count 27 br i1 %cond.if, label %loop.inner, label %exit 28 29; CHECK: Flow: 30; CHECK: %2 = phi i1 [ %0, %if ], [ true, %loop.inner ] 31; CHECK: %3 = phi i1 [ false, %if ], [ true, %loop.inner ] 32; CHECK: br i1 %2, label %Flow1, label %loop.inner 33 34; CHECK: Flow1: 35; CHECK: br i1 %3, label %else, label %Flow2 36 37; CHECK: else: 38; CHECK: br label %Flow2 39else: 40 %ctr.else = add i32 %ctr.loop.inner, 1 41 call void @foo(i32 3) 42 %cond.else = icmp slt i32 %ctr.else, %count 43 br i1 %cond.else, label %loop.outer, label %exit 44 45; CHECK: Flow2: 46; CHECK: %6 = phi i1 [ %4, %else ], [ true, %Flow1 ] 47; CHECK: br i1 %6, label %exit, label %loop.outer 48 49exit: 50 ret void 51} 52 53declare void @foo(i32) 54