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

Michael Ilseman milseman at apple.com
Fri Sep 7 17:07:08 PDT 2012


I should mention my return type is SDValue, so I'm trying to go from SDNode to SDValue in this case.

On Sep 7, 2012, at 5:04 PM, Peter Cooper <peter_cooper at apple.com> wrote:

> N1.getNode() will do it too.
> 
> Pete
> On Sep 7, 2012, at 5:03 PM, Michael Ilseman <milseman at apple.com> wrote:
> 
>> Unfortunately, CFP is an SDNode: the assignment statement with dyncast ends up calling the SDValue's *operator. I could probably call the SDValue constructor on CFP, and in that case would the resno just be 0?
>> 
>> On Sep 7, 2012, at 4:59 PM, Chandler Carruth <chandlerc at google.com> wrote:
>> 
>>> 
>>> 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.
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120907/94c58cd6/attachment.html>


More information about the llvm-commits mailing list