llvm.org GIT mirror llvm / 80ce0ad
[InstSimplify] add tests for select+fcmp; NFC These are translated from InstCombine's test file with the same name. We should move the transform from InstCombine to InstSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346168 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 11 months ago
1 changed file(s) with 102 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
2
3 ; X == 42.0 ? X : 42.0 --> 42.0
4
5 define double @oeq(double %x) {
6 ; CHECK-LABEL: @oeq(
7 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq double [[X:%.*]], 4.200000e+01
8 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double 4.200000e+01
9 ; CHECK-NEXT: ret double [[COND]]
10 ;
11 %cmp = fcmp oeq double %x, 42.0
12 %cond = select i1 %cmp, double %x, double 42.0
13 ret double %cond
14 }
15
16 ; X == 42.0 ? 42.0 : X --> X
17
18 define float @oeq_swapped(float %x) {
19 ; CHECK-LABEL: @oeq_swapped(
20 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[X:%.*]], 4.200000e+01
21 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], float 4.200000e+01, float [[X]]
22 ; CHECK-NEXT: ret float [[COND]]
23 ;
24 %cmp = fcmp oeq float %x, 42.0
25 %cond = select i1 %cmp, float 42.0, float %x
26 ret float %cond
27 }
28
29 ; x != y ? x : y -> x if it's the right kind of != and at least
30 ; one of x and y is not negative zero.
31
32 ; X != 42.0 ? X : 42.0 --> X
33
34 define double @une(double %x) {
35 ; CHECK-LABEL: @une(
36 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], 4.200000e+01
37 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double 4.200000e+01
38 ; CHECK-NEXT: ret double [[COND]]
39 ;
40 %cmp = fcmp une double %x, 42.0
41 %cond = select i1 %cmp, double %x, double 42.0
42 ret double %cond
43 }
44
45 ; X != 42.0 ? 42.0 : X --> 42.0
46
47 define double @une_swapped(double %x) {
48 ; CHECK-LABEL: @une_swapped(
49 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], 4.200000e+01
50 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double 4.200000e+01, double [[X]]
51 ; CHECK-NEXT: ret double [[COND]]
52 ;
53 %cmp = fcmp une double %x, 42.0
54 %cond = select i1 %cmp, double 42.0, double %x
55 ret double %cond
56 }
57
58 define double @une_could_be_negzero(double %x, double %y) {
59 ; CHECK-LABEL: @une_could_be_negzero(
60 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
61 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double [[Y]]
62 ; CHECK-NEXT: ret double [[COND]]
63 ;
64 %cmp = fcmp une double %x, %y
65 %cond = select i1 %cmp, double %x, double %y
66 ret double %cond
67 }
68
69 define double @une_swapped_could_be_negzero(double %x, double %y) {
70 ; CHECK-LABEL: @une_swapped_could_be_negzero(
71 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[X:%.*]], [[Y:%.*]]
72 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[Y]], double [[X]]
73 ; CHECK-NEXT: ret double [[COND]]
74 ;
75 %cmp = fcmp une double %x, %y
76 %cond = select i1 %cmp, double %y, double %x
77 ret double %cond
78 }
79
80 define double @one(double %x) {
81 ; CHECK-LABEL: @one(
82 ; CHECK-NEXT: [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
83 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[X]], double -1.000000e+00
84 ; CHECK-NEXT: ret double [[COND]]
85 ;
86 %cmp = fcmp one double %x, -1.0
87 %cond = select i1 %cmp, double %x, double -1.0
88 ret double %cond
89 }
90
91 define double @one_swapped(double %x) {
92 ; CHECK-LABEL: @one_swapped(
93 ; CHECK-NEXT: [[CMP:%.*]] = fcmp one double [[X:%.*]], -1.000000e+00
94 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], double -1.000000e+00, double [[X]]
95 ; CHECK-NEXT: ret double [[COND]]
96 ;
97 %cmp = fcmp one double %x, -1.0
98 %cond = select i1 %cmp, double -1.0, double %x
99 ret double %cond
100 }
101