1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4declare void @use(i1)
5
6; X == 42.0 ? X : 42.0 --> 42.0
7
8define double @oeq(double %x) {
9; CHECK-LABEL: @oeq(
10; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq double [[X:%.*]], 4.200000e+01
11; CHECK-NEXT:    call void @use(i1 [[CMP]])
12; CHECK-NEXT:    ret double 4.200000e+01
13;
14  %cmp = fcmp oeq double %x, 42.0
15  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
16  %cond = select i1 %cmp, double %x, double 42.0
17  ret double %cond
18}
19
20; X == 42.0 ? 42.0 : X --> X
21
22define float @oeq_swapped(float %x) {
23; CHECK-LABEL: @oeq_swapped(
24; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq float [[X:%.*]], 4.200000e+01
25; CHECK-NEXT:    call void @use(i1 [[CMP]])
26; CHECK-NEXT:    ret float [[X]]
27;
28  %cmp = fcmp oeq float %x, 42.0
29  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
30  %cond = select i1 %cmp, float 42.0, float %x
31  ret float %cond
32}
33
34; x != y ? x : y -> x if it's the right kind of != and at least
35; one of x and y is not negative zero.
36
37; X != 42.0 ? X : 42.0 --> X
38
39define double @une(double %x) {
40; CHECK-LABEL: @une(
41; CHECK-NEXT:    [[CMP:%.*]] = fcmp une double [[X:%.*]], 4.200000e+01
42; CHECK-NEXT:    call void @use(i1 [[CMP]])
43; CHECK-NEXT:    ret double [[X]]
44;
45  %cmp = fcmp une double %x, 42.0
46  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
47  %cond = select i1 %cmp, double %x, double 42.0
48  ret double %cond
49}
50
51; X != 42.0 ? 42.0 : X --> 42.0
52
53define double @une_swapped(double %x) {
54; CHECK-LABEL: @une_swapped(
55; CHECK-NEXT:    [[CMP:%.*]] = fcmp une double [[X:%.*]], 4.200000e+01
56; CHECK-NEXT:    call void @use(i1 [[CMP]])
57; CHECK-NEXT:    ret double 4.200000e+01
58;
59  %cmp = fcmp une double %x, 42.0
60  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
61  %cond = select i1 %cmp, double 42.0, double %x
62  ret double %cond
63}
64
65define double @une_could_be_negzero(double %x, double %y) {
66; CHECK-LABEL: @une_could_be_negzero(
67; CHECK-NEXT:    [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
68; CHECK-NEXT:    call void @use(i1 [[CMP]])
69; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], double [[X]], double [[Y]]
70; CHECK-NEXT:    ret double [[COND]]
71;
72  %cmp = fcmp une double %x, %y
73  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
74  %cond = select i1 %cmp, double %x, double %y
75  ret double %cond
76}
77
78define double @une_swapped_could_be_negzero(double %x, double %y) {
79; CHECK-LABEL: @une_swapped_could_be_negzero(
80; CHECK-NEXT:    [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
81; CHECK-NEXT:    call void @use(i1 [[CMP]])
82; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], double [[Y]], double [[X]]
83; CHECK-NEXT:    ret double [[COND]]
84;
85  %cmp = fcmp une double %x, %y
86  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
87  %cond = select i1 %cmp, double %y, double %x
88  ret double %cond
89}
90
91define double @one(double %x) {
92; CHECK-LABEL: @one(
93; CHECK-NEXT:    [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
94; CHECK-NEXT:    call void @use(i1 [[CMP]])
95; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], double [[X]], double -1.000000e+00
96; CHECK-NEXT:    ret double [[COND]]
97;
98  %cmp = fcmp one double %x, -1.0
99  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
100  %cond = select i1 %cmp, double %x, double -1.0
101  ret double %cond
102}
103
104define double @one_swapped(double %x) {
105; CHECK-LABEL: @one_swapped(
106; CHECK-NEXT:    [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
107; CHECK-NEXT:    call void @use(i1 [[CMP]])
108; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], double -1.000000e+00, double [[X]]
109; CHECK-NEXT:    ret double [[COND]]
110;
111  %cmp = fcmp one double %x, -1.0
112  call void @use(i1 %cmp)      ; extra use to thwart predicate canonicalization
113  %cond = select i1 %cmp, double -1.0, double %x
114  ret double %cond
115}
116
117