1 ; RUN: opt -S -instcombine < %s | FileCheck %s
3 ; CHECK-LABEL: @select_max_ugt(
4 ; CHECK: %cmp.inv = fcmp ole float %a, %b
5 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %b, float %a
6 ; CHECK-NEXT: ret float %sel
7 define float @select_max_ugt(float %a, float %b) {
8 %cmp = fcmp ugt float %a, %b
9 %sel = select i1 %cmp, float %a, float %b
13 ; CHECK-LABEL: @select_max_uge(
14 ; CHECK: %cmp.inv = fcmp olt float %a, %b
15 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %b, float %a
16 ; CHECK-NEXT: ret float %sel
17 define float @select_max_uge(float %a, float %b) {
18 %cmp = fcmp uge float %a, %b
19 %sel = select i1 %cmp, float %a, float %b
23 ; CHECK-LABEL: @select_min_ugt(
24 ; CHECK: %cmp.inv = fcmp ole float %a, %b
25 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %a, float %b
26 ; CHECK-NEXT: ret float %sel
27 define float @select_min_ugt(float %a, float %b) {
28 %cmp = fcmp ugt float %a, %b
29 %sel = select i1 %cmp, float %b, float %a
33 ; CHECK-LABEL: @select_min_uge(
34 ; CHECK: %cmp.inv = fcmp olt float %a, %b
35 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %a, float %b
36 ; CHECK-NEXT: ret float %sel
37 define float @select_min_uge(float %a, float %b) {
38 %cmp = fcmp uge float %a, %b
39 %sel = select i1 %cmp, float %b, float %a
43 ; CHECK-LABEL: @select_max_ult(
44 ; CHECK: %cmp.inv = fcmp oge float %a, %b
45 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %a, float %b
46 ; CHECK-NEXT: ret float %sel
47 define float @select_max_ult(float %a, float %b) {
48 %cmp = fcmp ult float %a, %b
49 %sel = select i1 %cmp, float %b, float %a
53 ; CHECK-LABEL: @select_max_ule(
54 ; CHECK: %cmp.inv = fcmp ogt float %a, %b
55 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %a, float %b
56 ; CHECK: ret float %sel
57 define float @select_max_ule(float %a, float %b) {
58 %cmp = fcmp ule float %a, %b
59 %sel = select i1 %cmp, float %b, float %a
63 ; CHECK-LABEL: @select_min_ult(
64 ; CHECK: %cmp.inv = fcmp oge float %a, %b
65 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %b, float %a
66 ; CHECK-NEXT: ret float %sel
67 define float @select_min_ult(float %a, float %b) {
68 %cmp = fcmp ult float %a, %b
69 %sel = select i1 %cmp, float %a, float %b
73 ; CHECK-LABEL: @select_min_ule(
74 ; CHECK: %cmp.inv = fcmp ogt float %a, %b
75 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %b, float %a
76 ; CHECK-NEXT: ret float %sel
77 define float @select_min_ule(float %a, float %b) {
78 %cmp = fcmp ule float %a, %b
79 %sel = select i1 %cmp, float %a, float %b
83 ; CHECK-LABEL: @select_fcmp_une(
84 ; CHECK: %cmp.inv = fcmp oeq float %a, %b
85 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %b, float %a
86 ; CHECK-NEXT: ret float %sel
87 define float @select_fcmp_une(float %a, float %b) {
88 %cmp = fcmp une float %a, %b
89 %sel = select i1 %cmp, float %a, float %b
93 ; CHECK-LABEL: @select_fcmp_ueq
94 ; CHECK: %cmp.inv = fcmp one float %a, %b
95 ; CHECK-NEXT: %sel = select i1 %cmp.inv, float %b, float %a
96 ; CHECK-NEXT: ret float %sel
97 define float @select_fcmp_ueq(float %a, float %b) {
98 %cmp = fcmp ueq float %a, %b
99 %sel = select i1 %cmp, float %a, float %b
103 declare void @foo(i1)
105 ; CHECK-LABEL: @select_max_ugt_2_use_cmp(
109 define float @select_max_ugt_2_use_cmp(float %a, float %b) {
110 %cmp = fcmp ugt float %a, %b
111 call void @foo(i1 %cmp)
112 %sel = select i1 %cmp, float %a, float %b
116 ; CHECK-LABEL: @select_min_uge_2_use_cmp(
120 define float @select_min_uge_2_use_cmp(float %a, float %b) {
121 %cmp = fcmp uge float %a, %b
122 call void @foo(i1 %cmp)
123 %sel = select i1 %cmp, float %b, float %a