[PATCH] Allow FMAs in safe math mode in some cases when one operand of the fmul is either exactly 0.0 or exactly 1.0.

Stephen Lin swlin at post.harvard.edu
Tue Jul 9 13:44:04 PDT 2013


Hi,

The attached patch allows FMAs to be formed in DAGCombiner even
without unsafe math mode when one operand is known to be either 0.0 or
1.0 exactly (this is safe because no rounding occurs in the fmul step,
and behavior on all limit case inputs is preserved, as far as I can
tell.)

This allows formation of FMAs in cases like the following:

    extern bool f;

    double foo(bool a, double b, double c, double d, double e) {
     return (b * double(a) + c) + (d * (1.0 - double(a)) + e);
    }

The intent of this patch is to address a subset of the issues which
required r181216 to be partially reverted (tracked as PR16164)
although there are still many other cases affected by that patch which
are not resolved.

Unfortunately, due to SelectionDAG limitations, this transformation
will only be done if the input can be determined to be zero or one
with information only in the same basic block, so depending on
optimization settings and phase ordering, will fail in cases like the
following:

    extern bool f;

    double foo(bool a, double b, double c, double d, double e) {
     if (a)
       return b * double(a) + c;
     else
       return d * (1.0 - double(a)) + e;
    }

Please let me know if you have any feedback.

Thanks,
Stephen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fma-through-zero-or-one.patch
Type: application/octet-stream
Size: 13028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130709/a52fd550/attachment.obj>


More information about the llvm-commits mailing list