This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][SelectionDAG] Fix tiny bug in ExpandIntRes_UADDSUBO
ClosedPublic

Authored by ibookstein on Sep 27 2019, 2:04 AM.

Details

Summary

Ternary expression checks for ISD::ADD instead of ISD::UADDO inside DAGTypeLegalizer::ExpandIntRes_UADDSUBO.
This means the ternary expression will evaluate to ISD::SUBCARRY for both ISD::UADDO and ISD::USUBO nodes.
Targets are likely to implement both, so impact will be very limited in practice.

Diff Detail

Event Timeline

ibookstein created this revision.Sep 27 2019, 2:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2019, 2:04 AM

Changed diff to be -U999999

As this would only affect a hypothetical target that supports ISD::SUBCARRY but not ISD::ADDCARRY, testing this via IR would seem overkill.
I think the correct level of testing for this would be UT for DAGTypeLegalizer, but the closest thing I could find was some of the things under llvm/unittests/CodeGen, like AArch64SelectionDAGTest.cpp.
Does that sound like it's in the right direction?

Two remarks:

  • Code duplication
  • If this is purely theoretical, can the dead code be simply dropped?
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
2306–2307

this

2335–2336

this

2343–2344

and this do basically the same thing.
At the very least you want to precompute which carry and non-carry opcodes you'll want to use, thus avoiding the bug altogether.

Is this along the lines of what you suggested?

ibookstein marked 3 inline comments as done.Sep 28 2019, 3:59 PM
lebedev.ri accepted this revision.Sep 29 2019, 1:08 AM

That'll do, thanks!

This revision is now accepted and ready to land.Sep 29 2019, 1:09 AM

I failed to mention during the review that I don't have commit access, so could anyone commit this on my behalf?

Ping
Is there anything else I should/could to to land this?

Right.
Now that we have migrated to git, can you paste your Author: name <e@ma.il> that should be used for the patch?

Yeah sure, thanks!
Author: Itay Bookstein <ibookstein@gmail.com>

This revision was automatically updated to reflect the committed changes.