This is an archive of the discontinued LLVM Phabricator instance.

[DAGComine] (fadd x, undef) -> undef and (fmul x, undef) -> undef
Needs RevisionPublic

Authored by deadalnix on Jun 3 2017, 7:49 AM.

Details

Summary

As per title. It doesn't canonicalize properly when x is a constant.

Event Timeline

deadalnix created this revision.Jun 3 2017, 7:49 AM
spatel edited edge metadata.

We don't have these folds in IR (InstSimplify).

  1. Is that an oversight or are we intentionally avoiding FP undef folding?
  2. 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?
  3. If this is valid, then why limit it to fmul+fadd? Are fsub and fdiv/frem different?
zvi edited edge metadata.Jun 4 2017, 11:36 AM

I'm asking without deep understanding in how bugpoint works: does this combine affect bugpoint's ability to minimize modules in 'run-llc' mode?

  1. My best guess is that it is an oversight, but there would be a reason I'm not aware of.
  2. Yes because of legalization.
  3. 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.

efriedma edited edge metadata.Jun 5 2017, 12:10 PM
efriedma added a subscriber: nlopes.

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 ?

RKSimon resigned from this revision.Oct 26 2017, 11:54 AM
deadalnix updated this revision to Diff 122280.Nov 9 2017, 11:10 AM

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.

spatel requested changes to this revision.May 26 2020, 6:11 AM

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.

This revision now requires changes to proceed.May 26 2020, 6:11 AM
sanjoy resigned from this revision.Jan 29 2022, 5:44 PM