[llvm-commits] Fold multiply by 0 and 1 when in UnsafeFPMath mode in SelectionDAG::getNode()

Chandler Carruth chandlerc at google.com
Fri Sep 7 16:59:29 PDT 2012


On Fri, Sep 7, 2012 at 7:55 PM, Michael Ilseman <milseman at apple.com> wrote:

> Thanks for the comment. New patch attached. I'm not too familiar with
> SDValue/SDNode, so if you see a way that it can be cleaned up further, let
> me know!
>

Hmm, I would have assumed (naively, and without running the compiler over
it) that you could write this as:

      } else if (Opcode == ISD::FMUL) {
        ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1);
        SDNode *Arg = N2;

        // If the first operand isn't the constant, try the second
        if (!CFP) {
          CFP = dyn_cast<ConstantFPSDNode>(N2);
          Arg = N1;
        }

        if (CFP) {
          // 0*x --> 0
          if (CFP->isZero())
            return CFP;
          // 1*x --> x
          if (CFP->isExactlyValue(1.0))
            return Arg;
        }

If that doesn't work, your version seems fine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120907/79ad1b82/attachment.html>


More information about the llvm-commits mailing list