brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.5 KiB · 562dded Raw
201 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1"5target triple = "wasm32-unknown-unknown"6 7%struct.quux = type { i32 }8%struct.blam = type <{ i32, %struct.quux }>9 10declare void @foo()11declare void @bar(ptr)12declare i32 @baz()13declare i32 @__gxx_wasm_personality_v0(...)14; Function Attrs: noreturn15declare void @llvm.wasm.rethrow() #016 17; Test that a PHI in catchswitch BB are excluded from combining into a non-PHI18; instruction.19define void @test0(i1 %c1) personality ptr @__gxx_wasm_personality_v0 {20; CHECK-LABEL: @test0(21; CHECK-NEXT:  bb:22; CHECK-NEXT:    [[TMP0:%.*]] = alloca [[STRUCT_BLAM:%.*]], align 423; CHECK-NEXT:    br i1 [[C1:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]24; CHECK:       bb1:25; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds nuw i8, ptr [[TMP0]], i32 426; CHECK-NEXT:    invoke void @foo()27; CHECK-NEXT:            to label [[BB3:%.*]] unwind label [[BB4:%.*]]28; CHECK:       bb2:29; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds nuw i8, ptr [[TMP0]], i32 430; CHECK-NEXT:    invoke void @foo()31; CHECK-NEXT:            to label [[BB3]] unwind label [[BB4]]32; CHECK:       bb3:33; CHECK-NEXT:    unreachable34; CHECK:       bb4:35; CHECK-NEXT:    [[TMP3:%.*]] = phi ptr [ [[TMP1]], [[BB1]] ], [ [[TMP2]], [[BB2]] ]36; CHECK-NEXT:    [[TMP4:%.*]] = catchswitch within none [label %bb5] unwind label [[BB7:%.*]]37; CHECK:       bb5:38; CHECK-NEXT:    [[TMP5:%.*]] = catchpad within [[TMP4]] [ptr null]39; CHECK-NEXT:    invoke void @foo() [ "funclet"(token [[TMP5]]) ]40; CHECK-NEXT:            to label [[BB6:%.*]] unwind label [[BB7]]41; CHECK:       bb6:42; CHECK-NEXT:    unreachable43; CHECK:       bb7:44; CHECK-NEXT:    [[TMP6:%.*]] = cleanuppad within none []45; CHECK-NEXT:    call void @bar(ptr nonnull [[TMP3]]) [ "funclet"(token [[TMP6]]) ]46; CHECK-NEXT:    unreachable47;48bb:49  %tmp0 = alloca %struct.blam, align 450  br i1 %c1, label %bb1, label %bb251 52bb1:                                              ; preds = %bb53  %tmp1 = getelementptr inbounds %struct.blam, ptr %tmp0, i32 0, i32 154  invoke void @foo()55  to label %bb3 unwind label %bb456 57bb2:                                              ; preds = %bb58  %tmp2 = getelementptr inbounds %struct.blam, ptr %tmp0, i32 0, i32 159  invoke void @foo()60  to label %bb3 unwind label %bb461 62bb3:                                              ; preds = %bb2, %bb163  unreachable64 65bb4:                                              ; preds = %bb2, %bb166  ; This PHI should not be combined into a non-PHI instruction, because67  ; catchswitch BB cannot have any non-PHI instruction other than catchswitch68  ; itself.69  %tmp3 = phi ptr [ %tmp1, %bb1 ], [ %tmp2, %bb2 ]70  %tmp4 = catchswitch within none [label %bb5] unwind label %bb771 72bb5:                                              ; preds = %bb473  %tmp5 = catchpad within %tmp4 [ptr null]74  invoke void @foo() [ "funclet"(token %tmp5) ]75  to label %bb6 unwind label %bb776 77bb6:                                              ; preds = %bb578  unreachable79 80bb7:                                              ; preds = %bb5, %bb481  %tmp6 = cleanuppad within none []82  call void @bar(ptr %tmp3) [ "funclet"(token %tmp6) ]83  unreachable84}85 86; Test that slicing-up of illegal integer type PHI does not happen in catchswitch87; BBs, which can't have any non-PHI instruction before the catchswitch.88define void @test1() personality ptr @__gxx_wasm_personality_v0 {89; CHECK-LABEL: @test1(90; CHECK-NEXT:  entry:91; CHECK-NEXT:    invoke void @foo()92; CHECK-NEXT:            to label [[INVOKE_CONT:%.*]] unwind label [[CATCH_DISPATCH1:%.*]]93; CHECK:       invoke.cont:94; CHECK-NEXT:    [[CALL:%.*]] = invoke i32 @baz()95; CHECK-NEXT:            to label [[INVOKE_CONT1:%.*]] unwind label [[CATCH_DISPATCH:%.*]]96; CHECK:       invoke.cont1:97; CHECK-NEXT:    [[TOBOOL_INIT:%.*]] = icmp ne i32 [[CALL]], 098; CHECK-NEXT:    br i1 [[TOBOOL_INIT]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]99; CHECK:       if.then:100; CHECK-NEXT:    br label [[IF_END]]101; CHECK:       if.end:102; CHECK-NEXT:    invoke void @foo()103; CHECK-NEXT:            to label [[INVOKE_CONT2:%.*]] unwind label [[CATCH_DISPATCH]]104; CHECK:       invoke.cont2:105; CHECK-NEXT:    br label [[TRY_CONT:%.*]]106; CHECK:       catch.dispatch:107; CHECK-NEXT:    [[AP_1:%.*]] = phi i1 [ [[TOBOOL_INIT]], [[IF_END]] ], [ false, [[INVOKE_CONT]] ]108; CHECK-NEXT:    [[TMP0:%.*]] = catchswitch within none [label %catch.start] unwind label [[CATCH_DISPATCH1]]109; CHECK:       catch.start:110; CHECK-NEXT:    [[TMP1:%.*]] = catchpad within [[TMP0]] [ptr null]111; CHECK-NEXT:    br i1 false, label [[CATCH:%.*]], label [[RETHROW:%.*]]112; CHECK:       catch:113; CHECK-NEXT:    catchret from [[TMP1]] to label [[TRY_CONT]]114; CHECK:       rethrow:115; CHECK-NEXT:    invoke void @llvm.wasm.rethrow() #[[ATTR0:[0-9]+]] [ "funclet"(token [[TMP1]]) ]116; CHECK-NEXT:            to label [[UNREACHABLE:%.*]] unwind label [[CATCH_DISPATCH1]]117; CHECK:       catch.dispatch1:118; CHECK-NEXT:    [[TOBOOL1:%.*]] = phi i1 [ [[AP_1]], [[CATCH_DISPATCH]] ], [ [[AP_1]], [[RETHROW]] ], [ false, [[ENTRY:%.*]] ]119; CHECK-NEXT:    [[TMP2:%.*]] = catchswitch within none [label %catch.start1] unwind to caller120; CHECK:       catch.start1:121; CHECK-NEXT:    [[TMP3:%.*]] = catchpad within [[TMP2]] [ptr null]122; CHECK-NEXT:    br i1 [[TOBOOL1]], label [[IF_THEN1:%.*]], label [[IF_END1:%.*]]123; CHECK:       if.then1:124; CHECK-NEXT:    br label [[IF_END1]]125; CHECK:       if.end1:126; CHECK-NEXT:    catchret from [[TMP3]] to label [[TRY_CONT]]127; CHECK:       try.cont:128; CHECK-NEXT:    ret void129; CHECK:       unreachable:130; CHECK-NEXT:    unreachable131;132entry:133  invoke void @foo()134  to label %invoke.cont unwind label %catch.dispatch1135 136invoke.cont:                                      ; preds = %entry137  %call = invoke i32 @baz()138  to label %invoke.cont1 unwind label %catch.dispatch139 140invoke.cont1:                                     ; preds = %invoke.cont141  %tobool = icmp ne i32 %call, 0142  br i1 %tobool, label %if.then, label %if.end143 144if.then:                                          ; preds = %invoke.cont1145  br label %if.end146 147if.end:                                           ; preds = %if.then, %invoke.cont1148  %ap.0 = phi i8 [ 1, %if.then ], [ 0, %invoke.cont1 ]149  invoke void @foo()150  to label %invoke.cont2 unwind label %catch.dispatch151 152invoke.cont2:                                     ; preds = %if.end153  br label %try.cont154 155catch.dispatch:                                   ; preds = %if.end, %invoke.cont156  ; %ap.2 in catch.dispatch1 BB has an illegal integer type (i8) in the data157  ; layout, and it is only used by trunc or trunc(lshr) operations. In this case158  ; InstCombine will split this PHI in its predecessors, which include this159  ; catch.dispatch BB. This splitting involves creating non-PHI instructions,160  ; such as 'and' or 'icmp' in this BB, which is not valid for a catchswitch BB.161  ; So if one of sliced-up PHI's predecessor is a catchswitch block, we don't162  ; optimize that case and bail out. This BB should be preserved intact after163  ; InstCombine and the pass shouldn't produce invalid code.164  %ap.1 = phi i8 [ %ap.0, %if.end ], [ 0, %invoke.cont ]165  %tmp0 = catchswitch within none [label %catch.start] unwind label %catch.dispatch1166 167catch.start:                                      ; preds = %catch.dispatch168  %tmp1 = catchpad within %tmp0 [ptr null]169  br i1 0, label %catch, label %rethrow170 171catch:                                            ; preds = %catch.start172  catchret from %tmp1 to label %try.cont173 174rethrow:                                          ; preds = %catch.start175  invoke void @llvm.wasm.rethrow() #0 [ "funclet"(token %tmp1) ]176  to label %unreachable unwind label %catch.dispatch1177 178catch.dispatch1:                                  ; preds = %rethrow, %catch.dispatch, %entry179  %ap.2 = phi i8 [ %ap.1, %catch.dispatch ], [ %ap.1, %rethrow ], [ 0, %entry ]180  %tmp2 = catchswitch within none [label %catch.start1] unwind to caller181 182catch.start1:                                     ; preds = %catch.dispatch1183  %tmp3 = catchpad within %tmp2 [ptr null]184  %tobool1 = trunc i8 %ap.2 to i1185  br i1 %tobool1, label %if.then1, label %if.end1186 187if.then1:                                         ; preds = %catch.start1188  br label %if.end1189 190if.end1:                                          ; preds = %if.then1, %catch.start1191  catchret from %tmp3 to label %try.cont192 193try.cont:                                         ; preds = %if.end1, %catch, %invoke.cont2194  ret void195 196unreachable:                                      ; preds = %rethrow197  unreachable198}199 200attributes #0 = { noreturn }201