1. Hoist minus sign as high as possible in an attempt to reveal
authorShuxin Yang <shuxin.llvm@gmail.com>
Tue, 15 Jan 2013 21:09:32 +0000 (21:09 +0000)
committerShuxin Yang <shuxin.llvm@gmail.com>
Tue, 15 Jan 2013 21:09:32 +0000 (21:09 +0000)
commite8227452023f85556a4dc4f2dde03927092752cc
treebd32daf880733756ecff230e6af0c8f0bc01e7d0
parent6afb94f9e08b778dbadc3ff3c942be3ee810fcf2
1. Hoist minus sign as high as possible in an attempt to reveal
   some optimization opportunities (in the enclosing supper-expressions).

   rule 1. (-0.0 - X ) * Y => -0.0 - (X * Y)
     if expression "-0.0 - X" has only one reference.

   rule 2. (0.0 - X ) * Y => -0.0 - (X * Y)
     if expression "0.0 - X" has only one reference, and
        the instruction is marked "noSignedZero".

2. Eliminate negation (The compiler was already able to handle these
    opt if the 0.0s are replaced with -0.0.)

   rule 3: (0.0 - X) * (0.0 - Y) => X * Y
   rule 4: (0.0 - X) * C => X * -C
   if the expr is flagged "noSignedZero".

3.
  Rule 5: (X*Y) * X => (X*X) * Y
   if X!=Y and the expression is flagged with "UnsafeAlgebra".

   The purpose of this transformation is two-fold:
    a) to form a power expression (of X).
    b) potentially shorten the critical path: After transformation, the
       latency of the instruction Y is amortized by the expression of X*X,
       and therefore Y is in a "less critical" position compared to what it
      was before the transformation.

4. Remove the InstCombine code about simplifiying "X * select".

   The reasons are following:
    a) The "select" is somewhat architecture-dependent, therefore the
       higher level optimizers are not able to precisely predict if
       the simplification really yields any performance improvement
       or not.

    b) The "select" operator is bit complicate, and tends to obscure
       optimization opportunities. It is btter to keep it as low as
       possible in expr tree, and let CodeGen to tackle the optimization.

llvm-svn: 172551
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/fast-math.ll
llvm/test/Transforms/InstCombine/fmul.ll [new file with mode: 0644]