1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 ; X == 42.0 ? X : 42.0 --> 42.0
8 define double @oeq(double %x) {
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
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
20 ; X == 42.0 ? 42.0 : X --> X
22 define 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]]
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
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.
37 ; X != 42.0 ? X : 42.0 --> X
39 define double @une(double %x) {
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]]
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
51 ; X != 42.0 ? 42.0 : X --> 42.0
53 define 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
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
65 define 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]]
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
78 define 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]]
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
91 define double @one(double %x) {
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]]
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
104 define 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]]
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