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.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
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.
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)
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. |
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. |
lib/Transforms/Scalar/DCE.cpp | ||
---|---|---|
102 | I'd agree. |
I think this can be a range for loop, like