Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt < %s -instcombine -S | FileCheck %s
      2 
      3 define float @test1(float %A, float %B, i1 %C) {
      4 EntryBlock:
      5   ;; A*(1 - uitofp i1 C) -> select C, 0, A
      6   %cf = uitofp i1 %C to float
      7   %mc = fsub float 1.000000e+00, %cf
      8   %p1 = fmul fast float %A, %mc
      9   ret float %p1
     10 ; CHECK-LABEL: @test1(
     11 ; CHECK: select i1 %C, float -0.000000e+00, float %A
     12 }
     13 
     14 define float @test2(float %A, float %B, i1 %C) {
     15 EntryBlock:
     16   ;; B*(uitofp i1 C) -> select C, B, 0
     17   %cf = uitofp i1 %C to float
     18   %p2 = fmul fast float %B, %cf
     19   ret float %p2
     20 ; CHECK-LABEL: @test2(
     21 ; CHECK: select i1 %C, float %B, float -0.000000e+00
     22 }
     23 
     24 define float @test3(float %A, float %B, i1 %C) {
     25 EntryBlock:
     26   ;;  select C, 0, B + select C, A, 0 -> select C, A, B
     27   %cf = uitofp i1 %C to float
     28   %s1 = select i1 %C, float 0.000000e+00, float %B
     29   %s2 = select i1 %C, float %A, float 0.000000e+00
     30   %sum = fadd fast float %s1, %s2
     31   ret float %sum
     32 ; CHECK-LABEL: @test3(
     33 ; CHECK: select i1 %C, float %A, float %B
     34 }
     35 
     36 define float @test4(float %A, float %B, i1 %C) {
     37 EntryBlock:
     38   ;;  B*(uitofp i1 C) + A*(1 - uitofp i1 C) -> select C, A, B
     39   %cf = uitofp i1 %C to float
     40   %mc = fsub fast float 1.000000e+00, %cf
     41   %p1 = fmul fast float %A, %mc
     42   %p2 = fmul fast float %B, %cf
     43   %s1 = fadd fast float %p2, %p1
     44   ret float %s1
     45 ; CHECK-LABEL: @test4(
     46 ; CHECK: select i1 %C, float %B, float %A
     47 }
     48 
     49 define float @test5(float %A, float %B, i1 %C) {
     50 EntryBlock:
     51   ;; A*(1 - uitofp i1 C) + B*(uitofp i1 C) -> select C, A, B
     52   %cf = uitofp i1 %C to float
     53   %mc = fsub fast float 1.000000e+00, %cf
     54   %p1 = fmul fast float %A, %mc
     55   %p2 = fmul fast float %B, %cf
     56   %s1 = fadd fast float %p1, %p2
     57   ret float %s1
     58 ; CHECK-LABEL: @test5(
     59 ; CHECK: select i1 %C, float %B, float %A
     60 }
     61 
     62 ; PR15952
     63 define float @test6(float %A, float %B, i32 %C) {
     64   %cf = uitofp i32 %C to float
     65   %mc = fsub float 1.000000e+00, %cf
     66   %p1 = fmul fast float %A, %mc
     67   ret float %p1
     68 ; CHECK-LABEL: @test6(
     69 ; CHECK: uitofp
     70 }
     71 
     72 define float @test7(float %A, float %B, i32 %C) {
     73   %cf = uitofp i32 %C to float
     74   %p2 = fmul fast float %B, %cf
     75   ret float %p2
     76 ; CHECK-LABEL: @test7(
     77 ; CHECK: uitofp
     78 }
     79 
     80 define <4 x float> @test8(<4 x float> %A, <4 x float> %B, <4 x i1> %C) {
     81   ;;  B*(uitofp i1 C) + A*(1 - uitofp i1 C) -> select C, A, B
     82   %cf = uitofp <4 x i1> %C to <4 x float>
     83   %mc = fsub fast <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>, %cf
     84   %p1 = fmul fast <4 x float> %A, %mc
     85   %p2 = fmul fast <4 x float> %B, %cf
     86   %s1 = fadd fast <4 x float> %p2, %p1
     87   ret <4 x float> %s1
     88 ; CHECK-LABEL: @test8(
     89 ; CHECK: select <4 x i1> %C, <4 x float> %B, <4 x float> %A
     90 }
     91 
     92 define <4 x float> @test9(<4 x float> %A, <4 x float> %B, <4 x i1> %C) {
     93   ;; A*(1 - uitofp i1 C) + B*(uitofp i1 C) -> select C, A, B
     94   %cf = uitofp <4 x i1> %C to <4 x float>
     95   %mc = fsub fast <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>, %cf
     96   %p1 = fmul fast <4 x float> %A, %mc
     97   %p2 = fmul fast <4 x float> %B, %cf
     98   %s1 = fadd fast <4 x float> %p1, %p2
     99   ret <4 x float> %s1
    100 ; CHECK-LABEL: @test9
    101 ; CHECK: select <4 x i1> %C, <4 x float> %B, <4 x float> %A
    102 }
    103