xref: /llvm-project/llvm/test/Transforms/SimplifyCFG/cleanup-phis.ll (revision 8979ae42769e529b0f6fce3268492ffb49bd54b9)
1; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s
2
3target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4target triple = "wasm32-unknown-unknown"
5
6; This is a regression test for a bug in which we used phis() without
7; make_early_inc_range() in a for loop while deleting phi nodes.
8
9define void @cleanup_phis() personality ptr @__gxx_wasm_personality_v0 {
10bb0:
11  invoke void @foo()
12          to label %bb1 unwind label %ehcleanup
13
14bb1:                                              ; preds = %bb0
15  invoke void @foo()
16          to label %invoke.cont unwind label %ehcleanup
17
18invoke.cont:                                      ; preds = %bb1
19  ret void
20
21ehcleanup:                                       ; preds = %bb1, %bb0
22  %phi0 = phi i32 [ 0, %bb0 ], [ 1, %bb1 ]
23  %phi1 = phi i32 [ 2, %bb0 ], [ 3, %bb1 ]
24  %0 = cleanuppad within none []
25  cleanupret from %0 unwind label %catchswitch
26
27; These two phi nodes were originally in ehcleanup. Both phi nodes should be
28; correctly copied to this catchswitch BB.
29; CHECK: catchswitch:
30; CHECK-NEXT:  %phi0 = phi i32 [ 0, %bb0 ], [ 1, %bb1 ]
31; CHECK-NEXT:  %phi1 = phi i32 [ 2, %bb0 ], [ 3, %bb1 ]
32catchswitch:                                      ; preds = %ehcleanup
33  %1 = catchswitch within none [label %catch] unwind to caller
34
35catch:                                            ; preds = %catchswitch
36  %2 = catchpad within %1 [ptr null]
37  call void @bar(i32 %phi0, i32 %phi1)
38  unreachable
39}
40
41declare void @foo()
42declare void @bar(i32, i32)
43declare i32 @__gxx_wasm_personality_v0(...)
44