Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt -S -instcombine < %s | FileCheck %s
      2 
      3 ; (-0.0 - X) * C => X * -C
      4 define float @test1(float %x) {
      5   %sub = fsub float -0.000000e+00, %x
      6   %mul = fmul float %sub, 2.0e+1
      7   ret float %mul
      8 
      9 ; CHECK-LABEL: @test1(
     10 ; CHECK: fmul float %x, -2.000000e+01
     11 }
     12 
     13 ; (0.0 - X) * C => X * -C
     14 define float @test2(float %x) {
     15   %sub = fsub nsz float 0.000000e+00, %x
     16   %mul = fmul float %sub, 2.0e+1
     17   ret float %mul
     18 
     19 ; CHECK-LABEL: @test2(
     20 ; CHECK: fmul float %x, -2.000000e+01
     21 }
     22 
     23 ; (-0.0 - X) * (-0.0 - Y) => X * Y
     24 define float @test3(float %x, float %y) {
     25   %sub1 = fsub float -0.000000e+00, %x
     26   %sub2 = fsub float -0.000000e+00, %y
     27   %mul = fmul float %sub1, %sub2
     28   ret float %mul
     29 ; CHECK-LABEL: @test3(
     30 ; CHECK: fmul float %x, %y
     31 }
     32 
     33 ; (0.0 - X) * (0.0 - Y) => X * Y
     34 define float @test4(float %x, float %y) {
     35   %sub1 = fsub nsz float 0.000000e+00, %x
     36   %sub2 = fsub nsz float 0.000000e+00, %y
     37   %mul = fmul float %sub1, %sub2
     38   ret float %mul
     39 ; CHECK-LABEL: @test4(
     40 ; CHECK: fmul float %x, %y
     41 }
     42 
     43 ; (-0.0 - X) * Y => -0.0 - (X * Y)
     44 define float @test5(float %x, float %y) {
     45   %sub1 = fsub float -0.000000e+00, %x
     46   %mul = fmul float %sub1, %y
     47   ret float %mul
     48 ; CHECK-LABEL: @test5(
     49 ; CHECK: %1 = fmul float %x, %y
     50 ; CHECK: %mul = fsub float -0.000000e+00, %1
     51 }
     52 
     53 ; (0.0 - X) * Y => 0.0 - (X * Y)
     54 define float @test6(float %x, float %y) {
     55   %sub1 = fsub nsz float 0.000000e+00, %x
     56   %mul = fmul float %sub1, %y
     57   ret float %mul
     58 ; CHECK-LABEL: @test6(
     59 ; CHECK: %1 = fmul float %x, %y
     60 ; CHECK: %mul = fsub float -0.000000e+00, %1
     61 }
     62 
     63 ; "(-0.0 - X) * Y => -0.0 - (X * Y)" is disabled if expression "-0.0 - X"
     64 ; has multiple uses.
     65 define float @test7(float %x, float %y) {
     66   %sub1 = fsub float -0.000000e+00, %x
     67   %mul = fmul float %sub1, %y
     68   %mul2 = fmul float %mul, %sub1
     69   ret float %mul2
     70 ; CHECK-LABEL: @test7(
     71 ; CHECK: fsub float -0.000000e+00, %x
     72 }
     73