1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes='default<O1>' -S < %s | FileCheck %s
3 ; RUN: opt -passes='default<O2>' -S < %s | FileCheck %s
4 ; RUN: opt -passes='default<O3>' -S < %s | FileCheck %s
6 ; We are worse at propagating correlation facts when in select form
7 ; as compared to the PHI form, so if we lower switches to early,
8 ; we may make further optimizations problematic.
10 ; propagate value to bb2.
11 define i64 @test1(i64 %x) {
12 ; CHECK-LABEL: @test1(
14 ; CHECK-NEXT: [[SWITCH_SELECTCMP:%.*]] = icmp eq i64 [[X:%.*]], 0
15 ; CHECK-NEXT: [[SWITCH_SELECT:%.*]] = select i1 [[SWITCH_SELECTCMP]], i64 0, i64 10
16 ; CHECK-NEXT: ret i64 [[SWITCH_SELECT]]
19 switch i64 %x, label %bb3 [
26 %0 = icmp eq i64 %x, 100
27 br i1 %0, label %bb4, label %bb5
36 ; propagate value both to bb1 and bb2.
37 define i64 @test2(i64 %x) {
38 ; CHECK-LABEL: @test2(
40 ; CHECK-NEXT: [[SWITCH_SELECTCMP:%.*]] = icmp eq i64 [[X:%.*]], 1
41 ; CHECK-NEXT: [[SWITCH_SELECT:%.*]] = select i1 [[SWITCH_SELECTCMP]], i64 0, i64 10
42 ; CHECK-NEXT: ret i64 [[SWITCH_SELECT]]
45 switch i64 %x, label %bb3 [
50 %0 = icmp eq i64 %x, 100
51 br i1 %0, label %bb4, label %return
55 %1 = icmp eq i64 %x, 101
56 br i1 %1, label %bb4, label %bb5
65 define i64 @test3(i64 %x) {
66 ; CHECK-LABEL: @test3(
68 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i64 [[X:%.*]], 1
69 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[COND]], i64 10, i64 0
70 ; CHECK-NEXT: ret i64 [[SPEC_SELECT]]
73 switch i64 %x, label %bb1 [
79 %0 = icmp eq i64 %x, 100
80 br i1 %0, label %bb4, label %bb5
87 ; bb2 has two predecessors with case value 1 and 2.
88 define i64 @test_fail1(i64 %x) {
89 ; CHECK-LABEL: @test_fail1(
91 ; CHECK-NEXT: [[SWITCH:%.*]] = icmp eq i64 [[X:%.*]], 0
92 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[SWITCH]], i64 0, i64 10
93 ; CHECK-NEXT: ret i64 [[SPEC_SELECT]]
96 switch i64 %x, label %bb3 [
104 %0 = icmp eq i64 %x, 100
105 br i1 %0, label %bb4, label %bb5
114 ; return block has two predecessors.
115 define i64 @test_fail2(i64 %x) {
116 ; CHECK-LABEL: @test_fail2(
118 ; CHECK-NEXT: [[SWITCH_SELECTCMP:%.*]] = icmp eq i64 [[X:%.*]], 0
119 ; CHECK-NEXT: [[SWITCH_SELECT:%.*]] = select i1 [[SWITCH_SELECTCMP]], i64 2, i64 1
120 ; CHECK-NEXT: ret i64 [[SWITCH_SELECT]]
123 switch i64 %x, label %bb2 [
130 %retval.0 = phi i64 [ %x, %entry ], [ 2, %bb1 ]