1; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes=loop-simplifycfg %s | FileCheck %s 2; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require<domtree>,loop(loop-simplifycfg)' %s | FileCheck %s 3 4declare ptr @fake_personality_function() 5declare void @foo() 6 7define i32 @test_remove_lpad(i1 %exitcond) personality ptr @fake_personality_function { 8; CHECK-LABEL: @test_remove_lpad( 9entry: 10 br label %for.body 11 12for.body: 13 br i1 0, label %never, label %next 14 15next: 16 br label %latch 17 18latch: 19 br i1 %exitcond, label %exit, label %for.body 20 21exit: 22 ret i32 0 23 24never: 25 invoke void @foo() to label %next unwind label %never-unwind 26 27never-unwind: 28; CHECK: never-unwind: 29; CHECK-NEXT: unreachable 30 %res = landingpad token cleanup 31 unreachable 32} 33 34define i32 @test_remove_phi_lpad(i1 %exitcond) personality ptr @fake_personality_function { 35; CHECK-LABEL: @test_remove_phi_lpad( 36entry: 37 br label %for.body 38 39for.body: 40 br i1 0, label %never, label %next 41 42next: 43 br label %latch 44 45latch: 46 br i1 %exitcond, label %exit, label %for.body 47 48exit: 49 ret i32 0 50 51never: 52 invoke void @foo() to label %next unwind label %never-unwind 53 54never-unwind: 55; CHECK: never-unwind: 56; CHECK-NEXT: ret i32 poison 57 %p = phi i32 [1, %never] 58 %res = landingpad token cleanup 59 ret i32 %p 60} 61 62define i32 @test_split_remove_phi_lpad_(i1 %exitcond) personality ptr @fake_personality_function { 63; CHECK-LABEL: @test_split_remove_phi_lpad_( 64entry: 65 invoke void @foo() to label %for.body unwind label %unwind-bb 66 67for.body: 68 br i1 0, label %never, label %next 69 70next: 71 br label %latch 72 73latch: 74 br i1 %exitcond, label %exit, label %for.body 75 76exit: 77 ret i32 0 78 79never: 80 invoke void @foo() to label %next unwind label %unwind-bb 81 82unwind-bb: 83; CHECK: unwind-bb.loopexit: 84; CHECK-NEXT: br label %unwind-bb 85 %p = phi i32 [1, %never], [2, %entry] 86 %res = landingpad token cleanup 87 ret i32 %p 88} 89