1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
4 ; Test that we can thread a simple known condition through switch statements.
12 define void @test1(i32 %V) {
13 ; CHECK-LABEL: @test1(
14 ; CHECK-NEXT: switch i32 [[V:%.*]], label [[A:%.*]] [
15 ; CHECK-NEXT: i32 4, label [[T:%.*]]
16 ; CHECK-NEXT: i32 17, label [[COMMON_RET:%.*]]
19 ; CHECK-NEXT: call void @foo1()
20 ; CHECK-NEXT: call void @foo2()
21 ; CHECK-NEXT: br label [[COMMON_RET]]
23 ; CHECK-NEXT: call void @foo1()
24 ; CHECK-NEXT: br label [[COMMON_RET]]
26 ; CHECK-NEXT: ret void
28 switch i32 %V, label %A [
33 ;; V == 4 if we get here.
36 ;; This switch is always statically determined.
37 switch i32 %V, label %A2 [
46 %cond2 = icmp eq i32 %V, 4 ; <i1> [#uses=1]
47 br i1 %cond2, label %Done, label %C
51 %cond = icmp ne i32 %V, 4 ; <i1> [#uses=1]
52 br i1 %cond, label %Done, label %C
53 Done: ; preds = %B, %A, %A2, %0
58 %cond3 = icmp eq i32 %V, 4 ; <i1> [#uses=1]
59 br i1 %cond3, label %Done, label %C
60 C: ; preds = %B, %A, %A2, %T, %T
66 define void @test2(i32 %V) {
67 ; CHECK-LABEL: @test2(
68 ; CHECK-NEXT: switch i32 [[V:%.*]], label [[A:%.*]] [
69 ; CHECK-NEXT: i32 4, label [[T:%.*]]
70 ; CHECK-NEXT: i32 17, label [[D:%.*]]
71 ; CHECK-NEXT: i32 1234, label [[COMMON_RET:%.*]]
74 ; CHECK-NEXT: call void @foo1()
75 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[V]], 42
76 ; CHECK-NEXT: br i1 [[COND]], label [[D]], label [[COMMON_RET]]
78 ; CHECK-NEXT: ret void
80 ; CHECK-NEXT: call void @foo1()
81 ; CHECK-NEXT: call void @foo1()
82 ; CHECK-NEXT: br label [[COMMON_RET]]
84 ; CHECK-NEXT: call void @foo1()
85 ; CHECK-NEXT: br label [[COMMON_RET]]
87 switch i32 %V, label %A [
92 ;; V != 4, 17, 1234 here.
95 ;; This switch is always statically determined.
96 switch i32 %V, label %E [