This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Fix remaining zext() assertions in SelectionDAG
ClosedPublic

Authored by scott.linder on Aug 13 2018, 12:05 PM.

Details

Summary

Includes remaining cases not committed in https://reviews.llvm.org/D49574

This introduces what appear to be the first unittests for SelectionDAG. Lit tests do not directly test the problem cases in these functions, so I think unittests are easier to write and audit here.

Diff Detail

Event Timeline

scott.linder created this revision.Aug 13 2018, 12:05 PM

Can anyone comment if the unit test is the way to go for these? It's proving tricky to expose the potential issue with regular lit tests.

I guess this approach is okay, specifically for testing the SelectionDAG analysis helpers.

unittests/CodeGen/SelectionDAGTest.cpp
39

This seems bad; the test silently fails to run if the AArch64 target isn't built?

scott.linder added inline comments.Aug 31 2018, 9:38 AM
unittests/CodeGen/SelectionDAGTest.cpp
39

This does seem bad, but as far as I can tell there is no appealing alternative. Not that it absolves me of this, but other tests (e.g. CodeGen/GlobalISel/LegalizerHelperTest.h) do the same. The core issue is not having a "generic target" always available for unittests.

Is there anything better to do in this case?

efriedma added inline comments.Aug 31 2018, 11:17 AM
unittests/CodeGen/SelectionDAGTest.cpp
39

How hard would it be to make a fake target for SelectionDAG unittests? A skeleton implementation of a Target, a TargetMachine, and a TargetSubtargetInfo is hopefully not that much code. But maybe it's not quite that simple...

That said, I'm not really that worried about the part where the test only runs if the aarch64 target is enabled; we have target-specific tests all over. Maybe enough to just rename SelectionDAGTest to AArch64SelectionDAGTest so someone doesn't accidentally add a new test without running it.

Update test name to be clear it only runs when aarch64 is available.

I added a FIXME about creating a fake target for unittests, but I do not have the experience right now to know how much work would be involved, and whether a fake target is acceptable to add to begin with.

This revision is now accepted and ready to land.Aug 31 2018, 3:03 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Sep 6 2018, 10:54 AM
thakis added inline comments.
llvm/trunk/unittests/CodeGen/AArch64SelectionDAGTest.cpp
164 ↗(On Diff #163851)

Are you intentionally adding a main() here? add_llvm_unittests should provide one already, no?

scott.linder added inline comments.Sep 6 2018, 11:19 AM
llvm/trunk/unittests/CodeGen/AArch64SelectionDAGTest.cpp
164 ↗(On Diff #163851)

It was intentional, but probably better to move the Initialize* calls into a SetUpTestCase instead. I will update in an NFC commit.

scott.linder added inline comments.Sep 6 2018, 11:43 AM
llvm/trunk/unittests/CodeGen/AArch64SelectionDAGTest.cpp
164 ↗(On Diff #163851)

Fixed in r341574