This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] LegalizerHelper: Lower (G_FSUB X, Y) to (G_FADD X, (G_FNEG Y))
ClosedPublic

Authored by volkan on Mar 9 2017, 11:34 AM.

Diff Detail

Event Timeline

volkan created this revision.Mar 9 2017, 11:34 AM
qcolombet accepted this revision.Mar 9 2017, 6:29 PM

LGTM with nitpicks

lib/CodeGen/GlobalISel/LegalizerHelper.cpp
574

Period at the end of sentence

577

I would call the variable X and Y or change the names in the comment to RHS and LHS to have both the code and the comment to match.

580

FNEG could be illegal and thus it may be legalized into FSUB.
With that in mind, that means we could theoretically end up with an endless loop.
How do you think we should address that?
Note: I don't expect we solve the problem as part of this commit, but we would need a solution at some point.

This revision is now accepted and ready to land.Mar 9 2017, 6:29 PM
kristof.beyls added inline comments.Mar 9 2017, 11:28 PM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
580

My feeling is that it's probably better not to try to define generically how G_FSUB should be lowered if the target doesn't support it.
This patch in the generic code indeed assumes that G_FADD and G_FNEG will be legal when G_FSUB isn't.
I just think it's better not to make these assumptions in the generic code and just move this to target specific code.

qcolombet added inline comments.Mar 10 2017, 9:39 AM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
580

I believe it has value to be in the generic code.
Maybe we should check that FADD and FNEG are legal before applying that transformation and the problem is solved.

FWIW, this is how SDISel does is. (See ~LegalizeDAG.cpp:3236)

volkan added inline comments.Mar 10 2017, 9:45 AM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
580

That's what I thought. We can simply return UnableToLegalize for that case.

qcolombet added inline comments.Mar 10 2017, 9:52 AM
lib/CodeGen/GlobalISel/LegalizerHelper.cpp
580

Agreed.

volkan updated this revision to Diff 91380.Mar 10 2017, 10:59 AM

Check if G_FNEG is marked as Lower to avoid ending up with an infinite loop.

volkan marked 3 inline comments as done.Mar 10 2017, 10:59 AM
volkan closed this revision.Mar 10 2017, 1:37 PM