This is an archive of the discontinued LLVM Phabricator instance.

Optimize DeadCodeEliminationPass
ClosedPublic

Authored by escha on Sep 28 2015, 12:09 PM.

Details

Summary

This pass is currently doing an O(N) search of a vector on each iteration; let's rewrite it to work the same way as simplifyInstructionsInBlock.

Diff Detail

Repository
rL LLVM

Event Timeline

escha updated this revision to Diff 35898.Sep 28 2015, 12:09 PM
escha retitled this revision from to Optimize DeadCodeEliminationPass.
escha updated this object.
escha set the repository for this revision to rL LLVM.
escha added a subscriber: llvm-commits.

I should note, this is not a widely used pass (at least in-tree); as far as I can tell, everything uses ADCE instead except for the NVPTX backend. But with this patch, it should be faster than ADCE, making it perhaps slightly more useful as an alternative.

reames accepted this revision.Sep 28 2015, 7:01 PM
reames edited edge metadata.

LGTM

This revision is now accepted and ready to land.Sep 28 2015, 7:01 PM
escha added a comment.Sep 28 2015, 8:29 PM

Some numbers for this optimization (before and after, on our perf test suite):

Before: 76.1k cycles
After: 47.5k cycles

(standard deviation is +/- a few hundred cycles)

sanjoy added a subscriber: sanjoy.Sep 28 2015, 9:34 PM

Minor generic comments inline.

lib/Transforms/Scalar/DCE.cpp
102

I think this can be a range for loop, like

for (Use &Op : I->uses()) {
  ...
112

I find auto *OpI better -- that way you'll not repeat the type name.

136

Can you use inst_range here?

reames added inline comments.Sep 29 2015, 5:57 AM
lib/Transforms/Scalar/DCE.cpp
136

I'd prefer you didn't use inst_range here since the iterator update is somewhat subtle and inst_range might hide that.

escha added inline comments.Sep 29 2015, 10:40 AM
lib/Transforms/Scalar/DCE.cpp
102

Is this a good idea? It feels iterating over the operands is a bit iffy given that we're modifying the operand list as we go.

reames added inline comments.Sep 29 2015, 10:42 AM
lib/Transforms/Scalar/DCE.cpp
102

I'd agree.

escha closed this revision.Sep 30 2015, 10:51 AM