[PATCH] D18155: Instcombine: try to avoid wasted work in ConstantFold
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 15 18:29:20 PDT 2016
reames added a comment.
In http://reviews.llvm.org/D18155#376087, @escha wrote:
> To try to be more clear, this code appears to:
>
> 1. Drop instructions that are dead.
> 2. If constant, fold the constant. [this step folds ConstExprs as part of its internals, because that's how ConstantFolding works]
> 3. If not constant-foldable, check to see if any ConstExpr operands are foldable [this is where we duplicate work]
> 4. Add to the initial instcombine worklist.
Why not do the following:
1. Drop instructions that are dead.
2. Check to see if any ConstExpr operands are foldable, and update the instruction
3. If constant, fold the constant. [no longer needs to consider constexprs]
4. Add to the initial instcombine worklist.
Also, steps 1-3 are repeated inside the InstCombine run loop. See InstCombiner::run. I believe the code AddReachableCodeToWorklist is merely intended to be an optimization to avoid adding trivially constant instructions to the worklist (i.e. reduce the memory consumed by the worklist).
Repository:
rL LLVM
http://reviews.llvm.org/D18155
More information about the llvm-commits
mailing list