Avoid backtracking in "deref_of_address" MIR optimization #78368
Labels
A-mir-opt
Area: MIR optimizations
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The current implementation of "deref_of_address" introduced in #76683 uses a backtracking algorithm.
That is, it first tries to locate a dereference of a local, e.g.
_2 = (*_1)
. It then backtracks the previous statements for a definition of_1
. The current implementation has an heuristic look-back value of 6, which is arbitrarily chosen.We should instead walk the statements in the order they appear in the basic blocks, keeping track of places where the optimization could be applied. This should both be faster since we only look at each statement once. And it will apply more optimizations as the heuristic look-back value is gone.
The text was updated successfully, but these errors were encountered: