1; Extract the 'if', 'then', and 'else' blocks into the same function. 2; RUN: echo 'foo if;then;else' > %t 3; Make sure we can still extract a single basic block 4; RUN: echo 'foo end' >> %t 5; RUN: echo 'bar bb14;bb20' >> %t 6; RUN: opt -S -extract-blocks -extract-blocks-file=%t %s | FileCheck %s 7 8; CHECK-LABEL: foo 9; 10; CHECK: if: 11; The diamond will produce an i32 value, make sure we account for that. 12; CHECK: [[RES_VAL_ADDR:%[^ ]*]] = alloca i32 13; CHECK-NEXT: br label %[[FOO_DIAMOND_LABEL:.*$]] 14; 15; The if-then-else blocks should be in just one function. 16; CHECK: [[FOO_DIAMOND_LABEL]]: 17; CHECK: call void [[FOO_DIAMOND:@[^(]*]](i32 %arg1, i32 %arg, i32* [[RES_VAL_ADDR]]) 18; CHECK-NEXT: [[RES_VAL:%[^ ]*]] = load i32, i32* [[RES_VAL_ADDR]] 19; Then it should directly jump to end. 20; CHECK: br label %[[FOO_END_LABEL:.*$]] 21; 22; End should have been extracted into its own function. 23; CHECK: [[FOO_END_LABEL]]: 24; CHECK: [[CMP:%[^ ]*]] = call i1 [[FOO_END:@[^(]*]](i32 [[RES_VAL]], i32 %arg) 25; CHECK-NEXT: br i1 [[CMP]], label %ret0, label %ret1 26define i32 @foo(i32 %arg, i32 %arg1) { 27if: 28 %tmp5 = icmp sgt i32 %arg, 0 29 %tmp8 = icmp sgt i32 %arg1, 0 30 %or.cond = and i1 %tmp5, %tmp8 31 br i1 %or.cond, label %then, label %else 32 33then: 34 %tmp12 = shl i32 %arg1, 2 35 %tmp13 = add nsw i32 %tmp12, %arg 36 br label %end 37 38else: 39 %tmp22 = mul nsw i32 %arg, 3 40 %tmp24 = sdiv i32 %arg1, 6 41 %tmp25 = add nsw i32 %tmp24, %tmp22 42 br label %end 43 44end: 45 %tmp.0 = phi i32 [ %tmp13, %then ], [ %tmp25, %else ] 46 %and0 = and i32 %tmp.0, %arg 47 %cmp1 = icmp slt i32 %and0, 0 48 br i1 %cmp1, label %ret0, label %ret1 49 50ret0: 51 ret i32 0 52 53ret1: 54 ret i32 1 55} 56 57; CHECK-LABEL: bar 58; 59; Check that we extracted bb14 and bb20 in their own (shared) function. 60; CHECK: bb 61; CHECK: br i1 %or.cond, label %bb9, label %[[BAR_DIAMOND_LABEL:.*$]] 62; 63; CHECK: [[BAR_DIAMOND_LABEL]]: 64; CHECK: [[CMP:%[^ ]*]] = call i1 [[BAR_DIAMOND:@[^(]*]](i32 %arg1, i32 %arg, i32* 65; CHECK: br i1 [[CMP]], label %bb26, label %bb30 66define i32 @bar(i32 %arg, i32 %arg1) { 67bb: 68 %tmp5 = icmp sgt i32 %arg, 0 69 %tmp8 = icmp sgt i32 %arg1, 0 70 %or.cond = and i1 %tmp5, %tmp8 71 br i1 %or.cond, label %bb9, label %bb14 72 73bb9: ; preds = %bb 74 %tmp12 = shl i32 %arg1, 2 75 %tmp13 = add nsw i32 %tmp12, %arg 76 br label %bb30 77 78bb14: ; preds = %bb 79 %0 = and i32 %arg1, %arg 80 %1 = icmp slt i32 %0, 0 81 br i1 %1, label %bb20, label %bb26 82 83bb20: ; preds = %bb14 84 %tmp22 = mul nsw i32 %arg, 3 85 %tmp24 = sdiv i32 %arg1, 6 86 %tmp25 = add nsw i32 %tmp24, %tmp22 87 br label %bb30 88 89bb26: ; preds = %bb14 90 %tmp29 = sub nsw i32 %arg, %arg1 91 br label %bb30 92 93bb30: ; preds = %bb26, %bb20, %bb9 94 %tmp.0 = phi i32 [ %tmp13, %bb9 ], [ %tmp25, %bb20 ], [ %tmp29, %bb26 ] 95 ret i32 %tmp.0 96} 97 98; Check that we extracted the three asked basic blocks. 99; CHECK: [[FOO_DIAMOND]] 100; CHECK: then: 101; Make sure the function doesn't end in the middle of the 102; list of the blocks we are checking. 103; CHECK-NOT: } 104; CHECK: else: 105; CHECK-NOT: } 106; The name of the if block is weird because it had to be split 107; since it was the name of the entry of the original function. 108; CHECK: if.split: 109; CHECK: } 110 111; CHECK: [[FOO_END]] 112; CHECK-NOT: } 113; CHECK: end: 114; CHECK: } 115 116; Check that we extracted the two asked basic blocks. 117; CHECK: [[BAR_DIAMOND]] 118; CHECK-NOT: } 119; CHECK: bb14: 120; CHECK-NOT: } 121; CHECK: bb20: 122; CHECK: } 123