This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Fix exponential compile-time with selects.
ClosedPublic

Authored by efriedma on Jan 23 2018, 3:46 PM.

Details

Summary

If you have a long chain of select instructions created from something like int* p = &g; if (foo()) p += 4; if (foo2()) p += 4; etc., a naive recursive visitor will recursively visit each select twice, which is O(2^N) in the number of select instructions. Use the visited set to cut off recursion in this case.

(No testcase because this doesn't actually change the behavior, just the time.)

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Jan 23 2018, 3:46 PM
mzolotukhin accepted this revision.Jan 26 2018, 3:03 PM

The change looks reasonable to me. Though I wonder if it's possible to trigger a similar exponential behavior with GEP instructions - if that's possible, we should put them to VisitedUsers too.

Thanks,
Michael

This revision is now accepted and ready to land.Jan 26 2018, 3:03 PM
davide accepted this revision.Jan 26 2018, 4:51 PM

LGTM, thanks Eli.
BTW, does this happen on real code?

Though I wonder if it's possible to trigger a similar exponential behavior with GEP instructions

I don't think so; a GEP has exactly one pointer operand.

does this happen on real code

I ran into this problem compiling a proprietary codebase.

This revision was automatically updated to reflect the committed changes.