Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt -S -instcombine < %s | FileCheck %s
      2 
      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
     10   ret float %sel
     11 }
     12 
     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
     20   ret float %sel
     21 }
     22 
     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
     30   ret float %sel
     31 }
     32 
     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
     40   ret float %sel
     41 }
     42 
     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
     50   ret float %sel
     51 }
     52 
     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
     60   ret float %sel
     61 }
     62 
     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
     70   ret float %sel
     71 }
     72 
     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
     80   ret float %sel
     81 }
     82 
     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
     90   ret float %sel
     91 }
     92 
     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
    100   ret float %sel
    101 }
    102 
    103 declare void @foo(i1)
    104 
    105 ; CHECK-LABEL: @select_max_ugt_2_use_cmp(
    106 ; CHECK: fcmp ugt
    107 ; CHECK-NOT: fcmp
    108 ; CHECK: ret
    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
    113   ret float %sel
    114 }
    115 
    116 ; CHECK-LABEL: @select_min_uge_2_use_cmp(
    117 ; CHECK: fcmp uge
    118 ; CHECK-NOT: fcmp
    119 ; CHECK: ret
    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
    124   ret float %sel
    125 }
    126