1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; Make sure instcombine don't fold select into operands. We don't want to emit
5 ; select of two integers unless it's selecting 0 / 1.
7 define i32 @t1(i32 %c, i32 %x) {
9 ; CHECK-NEXT: [[T1:%.*]] = icmp eq i32 [[C:%.*]], 0
10 ; CHECK-NEXT: [[T2:%.*]] = lshr i32 [[X:%.*]], 18
11 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T1]], i32 [[T2]], i32 [[X]]
12 ; CHECK-NEXT: ret i32 [[T3]]
14 %t1 = icmp eq i32 %c, 0
16 %t3 = select i1 %t1, i32 %t2, i32 %x
20 define i32 @t2(i32 %c, i32 %x) {
22 ; CHECK-NEXT: [[T1:%.*]] = icmp eq i32 [[C:%.*]], 0
23 ; CHECK-NEXT: [[T2:%.*]] = and i32 [[X:%.*]], 18
24 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T1]], i32 [[T2]], i32 [[X]]
25 ; CHECK-NEXT: ret i32 [[T3]]
27 %t1 = icmp eq i32 %c, 0
29 %t3 = select i1 %t1, i32 %t2, i32 %x
33 define float @t3(float %x, float %y) {
35 ; CHECK-NEXT: [[T1:%.*]] = fcmp ogt float [[X:%.*]], [[Y:%.*]]
36 ; CHECK-NEXT: [[X_OP:%.*]] = fadd fast float [[X]], 1.000000e+00
37 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T1]], float [[X_OP]], float 2.000000e+00
38 ; CHECK-NEXT: ret float [[T3]]
40 %t1 = fcmp ogt float %x, %y
41 %t2 = select i1 %t1, float %x, float 1.0
42 %t3 = fadd fast float %t2, 1.0
46 define i8 @ashr_exact_poison_constant_fold(i1 %b, i8 %x) {
47 ; CHECK-LABEL: @ashr_exact_poison_constant_fold(
48 ; CHECK-NEXT: [[X_OP:%.*]] = ashr exact i8 [[X:%.*]], 3
49 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 5
50 ; CHECK-NEXT: ret i8 [[R]]
52 %s = select i1 %b, i8 %x, i8 42
53 %r = ashr exact i8 %s, 3
57 define i8 @ashr_exact(i1 %b, i8 %x) {
58 ; CHECK-LABEL: @ashr_exact(
59 ; CHECK-NEXT: [[X_OP:%.*]] = ashr exact i8 [[X:%.*]], 3
60 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 2
61 ; CHECK-NEXT: ret i8 [[R]]
63 %s = select i1 %b, i8 %x, i8 16
64 %r = ashr exact i8 %s, 3
68 define i8 @shl_nsw_nuw_poison_constant_fold(i1 %b, i8 %x) {
69 ; CHECK-LABEL: @shl_nsw_nuw_poison_constant_fold(
70 ; CHECK-NEXT: [[X_OP:%.*]] = shl nuw nsw i8 16, [[X:%.*]]
71 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 -128, i8 [[X_OP]]
72 ; CHECK-NEXT: ret i8 [[R]]
74 %s = select i1 %b, i8 3, i8 %x
75 %r = shl nsw nuw i8 16, %s
79 define i8 @shl_nsw_nuw(i1 %b, i8 %x) {
80 ; CHECK-LABEL: @shl_nsw_nuw(
81 ; CHECK-NEXT: [[X_OP:%.*]] = shl nuw nsw i8 7, [[X:%.*]]
82 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 56, i8 [[X_OP]]
83 ; CHECK-NEXT: ret i8 [[R]]
85 %s = select i1 %b, i8 3, i8 %x
86 %r = shl nsw nuw i8 7, %s
90 define i8 @add_nsw_poison_constant_fold(i1 %b, i8 %x) {
91 ; CHECK-LABEL: @add_nsw_poison_constant_fold(
92 ; CHECK-NEXT: [[X_OP:%.*]] = add nsw i8 [[X:%.*]], 64
93 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 -127
94 ; CHECK-NEXT: ret i8 [[R]]
96 %s = select i1 %b, i8 %x, i8 65
97 %r = add nsw i8 %s, 64
101 define i8 @add_nsw(i1 %b, i8 %x) {
102 ; CHECK-LABEL: @add_nsw(
103 ; CHECK-NEXT: [[X_OP:%.*]] = add nsw i8 [[X:%.*]], 64
104 ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], i8 [[X_OP]], i8 71
105 ; CHECK-NEXT: ret i8 [[R]]
107 %s = select i1 %b, i8 %x, i8 7
108 %r = add nsw i8 %s, 64