brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · ecf726c Raw
123 lines · plain
1; Extract the 'if', 'then', and 'else' blocks into the same function.2; RUN: echo 'foo if;then;else' > %t3; Make sure we can still extract a single basic block4; RUN: echo 'foo end' >> %t5; RUN: echo 'bar bb14;bb20' >> %t6; RUN: opt -S -passes=extract-blocks -extract-blocks-file=%t %s | FileCheck %s7 8; CHECK-LABEL: foo9;10; CHECK: if:11; The diamond will produce an i32 value, make sure we account for that.12; CHECK: [[RES_VAL_ADDR:%[^ ]*]] = alloca i3213; 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, ptr [[RES_VAL_ADDR]])18; CHECK-NEXT: [[RES_VAL:%[^ ]*]] = load i32, ptr [[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 %ret126define i32 @foo(i32 %arg, i32 %arg1) {27if:28  %tmp5 = icmp sgt i32 %arg, 029  %tmp8 = icmp sgt i32 %arg1, 030  %or.cond = and i1 %tmp5, %tmp831  br i1 %or.cond, label %then, label %else32 33then:34  %tmp12 = shl i32 %arg1, 235  %tmp13 = add nsw i32 %tmp12, %arg36  br label %end37 38else:39  %tmp22 = mul nsw i32 %arg, 340  %tmp24 = sdiv i32 %arg1, 641  %tmp25 = add nsw i32 %tmp24, %tmp2242  br label %end43 44end:45  %tmp.0 = phi i32 [ %tmp13, %then ], [ %tmp25, %else ]46  %and0 = and i32 %tmp.0, %arg47  %cmp1 = icmp slt i32 %and0, 048  br i1 %cmp1, label %ret0, label %ret149 50ret0:51  ret i32 052 53ret1:54  ret i32 155}56 57; CHECK-LABEL: bar58;59; Check that we extracted bb14 and bb20 in their own (shared) function.60; CHECK: bb61; 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, ptr65; CHECK: br i1 [[CMP]], label %bb26, label %bb3066define i32 @bar(i32 %arg, i32 %arg1) {67bb:68  %tmp5 = icmp sgt i32 %arg, 069  %tmp8 = icmp sgt i32 %arg1, 070  %or.cond = and i1 %tmp5, %tmp871  br i1 %or.cond, label %bb9, label %bb1472 73bb9:                                              ; preds = %bb74  %tmp12 = shl i32 %arg1, 275  %tmp13 = add nsw i32 %tmp12, %arg76  br label %bb3077 78bb14:                                             ; preds = %bb79  %0 = and i32 %arg1, %arg80  %1 = icmp slt i32 %0, 081  br i1 %1, label %bb20, label %bb2682 83bb20:                                             ; preds = %bb1484  %tmp22 = mul nsw i32 %arg, 385  %tmp24 = sdiv i32 %arg1, 686  %tmp25 = add nsw i32 %tmp24, %tmp2287  br label %bb3088 89bb26:                                             ; preds = %bb1490  %tmp29 = sub nsw i32 %arg, %arg191  br label %bb3092 93bb30:                                             ; preds = %bb26, %bb20, %bb994  %tmp.0 = phi i32 [ %tmp13, %bb9 ], [ %tmp25, %bb20 ], [ %tmp29, %bb26 ]95  ret i32 %tmp.096}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 the102; 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 split107; 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