1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -simplifycfg -forward-switch-cond=false -S | FileCheck %s --check-prefix=NO_FWD
3 ; RUN: opt < %s -simplifycfg -forward-switch-cond=true -S | FileCheck %s --check-prefix=FWD
5 ; RUN: opt < %s -passes='simplify-cfg<no-forward-switch-cond>' -S | FileCheck %s --check-prefix=NO_FWD
6 ; RUN: opt < %s -passes='simplify-cfg<forward-switch-cond>' -S | FileCheck %s --check-prefix=FWD
10 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
11 target triple = "i386-pc-linux-gnu"
13 define i32 @t(i32 %m) nounwind readnone {
16 ; NO_FWD-NEXT: switch i32 [[M:%.*]], label [[SW_BB4:%.*]] [
17 ; NO_FWD-NEXT: i32 0, label [[RETURN:%.*]]
18 ; NO_FWD-NEXT: i32 1, label [[SW_BB1:%.*]]
19 ; NO_FWD-NEXT: i32 2, label [[SW_BB2:%.*]]
20 ; NO_FWD-NEXT: i32 3, label [[SW_BB3:%.*]]
23 ; NO_FWD-NEXT: br label [[RETURN]]
25 ; NO_FWD-NEXT: br label [[RETURN]]
27 ; NO_FWD-NEXT: br label [[RETURN]]
29 ; NO_FWD-NEXT: br label [[RETURN]]
31 ; NO_FWD-NEXT: [[RETVAL_0:%.*]] = phi i32 [ 4, [[SW_BB4]] ], [ 3, [[SW_BB3]] ], [ 2, [[SW_BB2]] ], [ 1, [[SW_BB1]] ], [ 0, [[ENTRY:%.*]] ]
32 ; NO_FWD-NEXT: ret i32 [[RETVAL_0]]
36 ; FWD-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[M:%.*]], 4
37 ; FWD-NEXT: [[M_:%.*]] = select i1 [[SWITCH]], i32 [[M]], i32 4
38 ; FWD-NEXT: ret i32 [[M_]]
41 switch i32 %m, label %sw.bb4 [
48 sw.bb0: ; preds = %entry
51 sw.bb1: ; preds = %entry
54 sw.bb2: ; preds = %entry
57 sw.bb3: ; preds = %entry
60 sw.bb4: ; preds = %entry
63 return: ; preds = %entry, %sw.bb4, %sw.bb3, %sw.bb2, %sw.bb1
64 %retval.0 = phi i32 [ 4, %sw.bb4 ], [ 3, %sw.bb3 ], [ 2, %sw.bb2 ], [ 1, %sw.bb1 ], [ 0, %sw.bb0 ]
68 ; If 1 incoming phi value is a case constant of a switch, convert it to the switch condition:
69 ; https://bugs.llvm.org/show_bug.cgi?id=34471
70 ; This then subsequently should allow squashing of the other trivial case blocks.
72 define i32 @PR34471(i32 %x) {
73 ; NO_FWD-LABEL: @PR34471(
75 ; NO_FWD-NEXT: switch i32 [[X:%.*]], label [[ELSE3:%.*]] [
76 ; NO_FWD-NEXT: i32 17, label [[RETURN:%.*]]
77 ; NO_FWD-NEXT: i32 19, label [[IF19:%.*]]
78 ; NO_FWD-NEXT: i32 42, label [[IF42:%.*]]
81 ; NO_FWD-NEXT: br label [[RETURN]]
83 ; NO_FWD-NEXT: br label [[RETURN]]
85 ; NO_FWD-NEXT: br label [[RETURN]]
87 ; NO_FWD-NEXT: [[R:%.*]] = phi i32 [ [[X]], [[IF19]] ], [ [[X]], [[IF42]] ], [ 0, [[ELSE3]] ], [ 17, [[ENTRY:%.*]] ]
88 ; NO_FWD-NEXT: ret i32 [[R]]
90 ; FWD-LABEL: @PR34471(
92 ; FWD-NEXT: switch i32 [[X:%.*]], label [[ELSE3:%.*]] [
93 ; FWD-NEXT: i32 17, label [[RETURN:%.*]]
94 ; FWD-NEXT: i32 19, label [[RETURN]]
95 ; FWD-NEXT: i32 42, label [[RETURN]]
98 ; FWD-NEXT: br label [[RETURN]]
100 ; FWD-NEXT: [[R:%.*]] = phi i32 [ 0, [[ELSE3]] ], [ [[X]], [[ENTRY:%.*]] ], [ [[X]], [[ENTRY]] ], [ [[X]], [[ENTRY]] ]
101 ; FWD-NEXT: ret i32 [[R]]
104 switch i32 %x, label %else3 [
105 i32 17, label %return
120 %r = phi i32 [ %x, %if19 ], [ %x, %if42 ], [ 0, %else3 ], [ 17, %entry ]