As per title. It doesn't canonicalize properly when x is a constant.
Diff Detail
- Build Status
Buildable 12017 Build 12017: arc lint + arc unit
Event Timeline
We don't have these folds in IR (InstSimplify).
- Is that an oversight or are we intentionally avoiding FP undef folding?
- If it's an oversight, do we still need to do this in the DAG? Or does having the folds in IR avoid the end problem in cases that you are looking at?
- If this is valid, then why limit it to fmul+fadd? Are fsub and fdiv/frem different?
I'm asking without deep understanding in how bugpoint works: does this combine affect bugpoint's ability to minimize modules in 'run-llc' mode?
- My best guess is that it is an oversight, but there would be a reason I'm not aware of.
- Yes because of legalization.
- The problem i intended to solve was the (fadd constant, undef) where it gets flipped again and again. fsub and fdiv/frem are not commutative ops so that problem doesn't occur with them.
As for bugpoint, I don't think it hinder its functioning, in fact this folding is already done for add for instance. However, it may have reduced cases with undef that will now get folded and so these test case may not test what's intended anymore. But that's more or less true of any transform.
fadd NaN, undef -> undef isn't legal: any fadd involving NaN always produces a NaN. Similar reasoning applies to most other floating-point values.
fadd %x, undef -> NaN is legal because fadd %x, NaN -> NaN is legal. I don't think we do this transform at the moment when %x isn't a constant, but this is consistent with the behavior of APFloat.
This is probably an argument in favor of getting rid of undef. :)
So maybe we should change floating point undefs into NaNs and let everything else unfold ?
Make sure we do not transform is x can be Nan, also do the transformation for fsub and add arguments in various tests to make sure they don't get folded and continue to test what they are supposed to.
See SelectionDAG::simplifyFPBinop() - FP with undef operand simplification has been enhanced a few times since this patch was proposed, so I'm not sure where we stand.
Marking as 'request changes' to update/abandon as needed.