1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -keep-loops=0 < %s | FileCheck %s
4 ; Merge 2 undefined incoming values.
6 define i32 @undef_merge(i32 %x) {
7 ; CHECK-LABEL: @undef_merge(
9 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT:%.*]] [
10 ; CHECK-NEXT: i32 4, label [[G:%.*]]
11 ; CHECK-NEXT: i32 12, label [[G]]
14 ; CHECK-NEXT: [[K3:%.*]] = phi i64 [ undef, [[ENTRY:%.*]] ], [ [[K3]], [[G]] ], [ undef, [[ENTRY]] ]
15 ; CHECK-NEXT: br label [[G]]
17 ; CHECK-NEXT: ret i32 undef
20 switch i32 %x, label %exit [
26 %k2 = phi i64 [ %k3, %g ], [ undef, %entry ]
30 %k3 = phi i64 [ %k2, %loop ], [ undef, %entry ]
37 ; Merge 2 poison incoming values.
39 define i32 @poison_merge(i32 %x) {
40 ; CHECK-LABEL: @poison_merge(
42 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT:%.*]] [
43 ; CHECK-NEXT: i32 4, label [[G:%.*]]
44 ; CHECK-NEXT: i32 12, label [[G]]
47 ; CHECK-NEXT: [[K3:%.*]] = phi i64 [ poison, [[ENTRY:%.*]] ], [ [[K3]], [[G]] ], [ poison, [[ENTRY]] ]
48 ; CHECK-NEXT: br label [[G]]
50 ; CHECK-NEXT: ret i32 undef
53 switch i32 %x, label %exit [
59 %k2 = phi i64 [ %k3, %g ], [ poison, %entry ]
63 %k3 = phi i64 [ %k2, %loop ], [ poison, %entry ]
70 ; Merge equal defined incoming values.
72 define i32 @defined_merge(i32 %x) {
73 ; CHECK-LABEL: @defined_merge(
75 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT:%.*]] [
76 ; CHECK-NEXT: i32 4, label [[G:%.*]]
77 ; CHECK-NEXT: i32 12, label [[G]]
80 ; CHECK-NEXT: [[K3:%.*]] = phi i64 [ 42, [[ENTRY:%.*]] ], [ [[K3]], [[G]] ], [ 42, [[ENTRY]] ]
81 ; CHECK-NEXT: br label [[G]]
83 ; CHECK-NEXT: ret i32 undef
86 switch i32 %x, label %exit [
92 %k2 = phi i64 [ %k3, %g ], [ 42, %entry ]
96 %k3 = phi i64 [ %k2, %loop ], [ 42, %entry ]
103 ; Merge defined and undef incoming values.
105 define i32 @defined_and_undef_merge(i32 %x) {
106 ; CHECK-LABEL: @defined_and_undef_merge(
108 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT:%.*]] [
109 ; CHECK-NEXT: i32 4, label [[G:%.*]]
110 ; CHECK-NEXT: i32 12, label [[G]]
113 ; CHECK-NEXT: [[K3:%.*]] = phi i64 [ 42, [[ENTRY:%.*]] ], [ [[K3]], [[G]] ], [ 42, [[ENTRY]] ]
114 ; CHECK-NEXT: br label [[G]]
116 ; CHECK-NEXT: ret i32 undef
119 switch i32 %x, label %exit [
125 %k2 = phi i64 [ %k3, %g ], [ undef, %entry ]
129 %k3 = phi i64 [ %k2, %loop ], [ 42, %entry ]
136 ; Merge defined and poison incoming values.
138 define i32 @defined_and_poison_merge(i32 %x) {
139 ; CHECK-LABEL: @defined_and_poison_merge(
141 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT:%.*]] [
142 ; CHECK-NEXT: i32 4, label [[G:%.*]]
143 ; CHECK-NEXT: i32 12, label [[G]]
146 ; CHECK-NEXT: [[K3:%.*]] = phi i64 [ 42, [[ENTRY:%.*]] ], [ [[K3]], [[G]] ], [ 42, [[ENTRY]] ]
147 ; CHECK-NEXT: br label [[G]]
149 ; CHECK-NEXT: ret i32 undef
152 switch i32 %x, label %exit [
158 %k2 = phi i64 [ %k3, %g ], [ poison, %entry ]
162 %k3 = phi i64 [ %k2, %loop ], [ 42, %entry ]
169 ; Do not crash trying to merge poison and undef into a single phi.
171 define i32 @PR49218(i32 %x) {
172 ; CHECK-LABEL: @PR49218(
174 ; CHECK-NEXT: switch i32 [[X:%.*]], label [[EXIT:%.*]] [
175 ; CHECK-NEXT: i32 4, label [[G:%.*]]
176 ; CHECK-NEXT: i32 12, label [[G]]
179 ; CHECK-NEXT: [[K3:%.*]] = phi i64 [ undef, [[ENTRY:%.*]] ], [ [[K3]], [[G]] ], [ undef, [[ENTRY]] ]
180 ; CHECK-NEXT: br label [[G]]
182 ; CHECK-NEXT: ret i32 undef
185 switch i32 %x, label %exit [
191 %k2 = phi i64 [ %k3, %g ], [ undef, %entry ]
195 %k3 = phi i64 [ %k2, %loop ], [ poison, %entry ]