This is an archive of the discontinued LLVM Phabricator instance.

[IR] Add hasNPredecessors, hasNPredecessorsOrMore to BasicBlock
ClosedPublic

Authored by vsk on Nov 18 2018, 11:36 PM.

Details

Summary

Add methods to BasicBlock which make it easier to efficiently check
whether a block has N (or more) predecessors.

This can be more efficient than using pred_size(), which is a linear
time operation.

We might consider adding similar methods for successors. I haven't done
so in this patch because succ_size() is already O(1).

With this patch applied, I measured a 0.065% compile-time reduction in
user time for running opt -O3 on the sqlite3 amalgamation (30 trials).
The change in mergeStoreIntoSuccessor alone saves 45 million linked list
iterations in a stage2 Release build of llc.

See llvm.org/PR39702 for a harder but more general way of achieving
similar results.

Diff Detail

Repository
rL LLVM

Event Timeline

vsk created this revision.Nov 18 2018, 11:36 PM
rnk accepted this revision.Nov 19 2018, 10:28 AM

Nice! I suppose the same problem doesn't exist in MIR because the predecessor lists are explicit.

lgtm

This revision is now accepted and ready to land.Nov 19 2018, 10:28 AM
davide accepted this revision.Nov 19 2018, 11:17 AM

LGTM

This revision was automatically updated to reflect the committed changes.