This is an archive of the discontinued LLVM Phabricator instance.

[Verifier] enable and limit llvm.experimental.noalias.scope.decl dominance checking
ClosedPublic

Authored by jeroen.dobbelaere on Jan 25 2021, 1:35 AM.

Details

Summary

Checking the llvm.experimental.noalias.scope.decl dominance can be worstcase O(N^2).
Limit the dominance check to N=32.

Diff Detail

Event Timeline

jeroen.dobbelaere requested review of this revision.Jan 25 2021, 1:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2021, 1:35 AM

For what it's worth, the number '1000' comes from experiments triggering the worst case behavior. With 1000 basic blocks and scope declarations, the time for parsing and checking on my testmachine was roughly 0.1 seconds. (Going to approx 1 second for 4000 blocks and declarations).

For a stage2 release build and the test-suite, the largest amount of noalias scope decls for a function is 1075 (triggered by llvm/unittests/ADT/SmallVectorTest.cpp). Everything else is <1000. The largest amount of same scope declarations seen was 5.

nikic added inline comments.Jan 25 2021, 6:15 AM
llvm/lib/IR/Verifier.cpp
5588

I wouldn't bother with the EXPENSIVE_CHECKS part and add a hardcoded limit of ItNext - ItCurrent < 32 or so here (only the case where there are many declares for the same scope is problematic).

It would be better to instead sort by DomTree DFS In number here and thus avoid a quadratic number of checks, but I don't think it's really worthwhile (the concern is a purely theoretical one).

fhahn added inline comments.Jan 25 2021, 6:17 AM
llvm/lib/IR/Verifier.cpp
5588

I wouldn't bother with the EXPENSIVE_CHECKS part and add a hardcoded limit of ItNext - ItCurrent < 32 or so here (only the case where there are many declares for the same scope is problematic).

SGTM

It would be better to instead sort by DomTree DFS In number here and thus avoid a quadratic number of checks, but I don't think it's really worthwhile (the concern is a purely theoretical one).

I was thinking about suggesting this was well, but it's probably more trouble than it is worth.

jeroen.dobbelaere edited the summary of this revision. (Show Details)

Adapted to comments.

fhahn accepted this revision.Jan 25 2021, 7:17 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jan 25 2021, 7:17 AM

I disabled the dominance check by default in rG3b5d36ece21f. Several buildbots show examples where this triggers, indicating there are still passes not taking care of proper handling the noalias scopes.

See:

There seems to be a problem with bad duplication in the MemorySanitizerLegacyPass.

There seems to be a problem with bad duplication in the MemorySanitizerLegacyPass.

After having reduced at least one issue, the problem originates from LoopPeel.cpp not taking care of the scopes after cloning.
I'll create a fix + testcase.

@jdoerfert I also noticed that LoopPeel.cpp is not doing anything for assumptions.