1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Check that no freeze instruction gets inserted before landingpad in a basic block
3 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
5 define i32 @propagate_freeze_in_landingpad() personality ptr null {
6 ; CHECK-LABEL: @propagate_freeze_in_landingpad(
8 ; CHECK-NEXT: br label [[INVOKE_BB1:%.*]]
10 ; CHECK-NEXT: [[X:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[NORMAL_RETURN:%.*]] ]
11 ; CHECK-NEXT: [[RES0:%.*]] = invoke i32 @foo()
12 ; CHECK-NEXT: to label [[INVOKE_BB2:%.*]] unwind label [[EXCEPTIONAL_RETURN:%.*]]
14 ; CHECK-NEXT: [[RES1:%.*]] = invoke i32 @foo()
15 ; CHECK-NEXT: to label [[NORMAL_RETURN]] unwind label [[EXCEPTIONAL_RETURN]]
16 ; CHECK: normal_return:
17 ; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[X]], 1
18 ; CHECK-NEXT: br label [[INVOKE_BB1]]
19 ; CHECK: exceptional_return:
20 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[X]], [[INVOKE_BB1]] ], [ 0, [[INVOKE_BB2]] ]
21 ; CHECK-NEXT: [[LANDING_PAD:%.*]] = landingpad { ptr, i32 }
23 ; CHECK-NEXT: [[FR:%.*]] = freeze i32 [[PHI]]
24 ; CHECK-NEXT: [[RES:%.*]] = shl i32 [[FR]], 1
25 ; CHECK-NEXT: ret i32 [[RES]]
30 invoke.bb1: ; preds = %normal_return, %entry
31 %x = phi i32 [ 0, %entry ], [ %inc, %normal_return ]
32 %res0 = invoke i32 @foo()
33 to label %invoke.bb2 unwind label %exceptional_return
35 invoke.bb2: ; preds = %invoke.bb1
36 %res1 = invoke i32 @foo()
37 to label %normal_return unwind label %exceptional_return
39 normal_return: ; preds = %invoke.bb2
40 %inc = add nuw nsw i32 %x, 1
43 exceptional_return: ; preds = %invoke.bb2, %invoke.bb1
44 %phi = phi i32 [ %x, %invoke.bb1 ], [ 0, %invoke.bb2 ]
45 %landing_pad = landingpad { ptr, i32 }
48 %res = add i32 %fr, %phi