This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] simplify FP binops to undef
ClosedPublic

Authored by spatel on Mar 3 2020, 2:59 PM.

Details

Summary

As discussed in the commit thread for rGa253a2a and D73978, we can do more undef folding for FP ops. The nnan and ninf fast-math-flags specify that if an operand is the disallowed value, the result is poison, so we can produce an undef result.

But this doesn't work as expected (the undef operand cases remain) because of a Flags propagation problem in SelectionDAGBuilder.

I've added DAGCombiner calls to enable these for the other cases because we've shown in other patches that (because of the limited way that SDAG iterates), it is possible to miss simplifications like this if they are done only at node creation time.

Diff Detail

Event Timeline

spatel created this revision.Mar 3 2020, 2:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2020, 2:59 PM
spatel edited the summary of this revision. (Show Details)Mar 3 2020, 3:00 PM
aqjune added inline comments.Mar 3 2020, 9:40 PM
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
7307

Nit: I think it is opposite; poison -> undef is allowed, but undef -> poison is not allowed. LangRef says a poison value may be relaxed into an undef value, which takes an arbitrary bit-pattern.

lebedev.ri accepted this revision.Mar 4 2020, 2:07 AM

LGTM, thank you.
If we don't do this in middle-end, we should.

I'm guessing this is already done for FNEG?
What about FCMP/PHI/SELECT?

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
7307

I think i agree here.

This revision is now accepted and ready to land.Mar 4 2020, 2:07 AM
spatel updated this revision to Diff 248148.Mar 4 2020, 4:43 AM

Patch updated:
Improved code comment.

spatel added a comment.Mar 4 2020, 4:50 AM

LGTM, thank you.
If we don't do this in middle-end, we should.

Yes, that would be a follow-on. There's less risk/reward in making the change here vs. IR, so I started here to be safer.

I'm guessing this is already done for FNEG?
What about FCMP/PHI/SELECT?

FNEG - no. Similarly, we don't do much/anything with opcodes that exist in SDAG but not IR.
FCMP is still in flux. We allow FMF on those currently, but I've been trying to transition away from that. So PHI/SELECT are relatively new to allow FMF in IR, and that has not been extended to SDAG yet.
In summary, we're a long way from complete in either layer.

This revision was automatically updated to reflect the committed changes.