In the recent change (http://reviews.llvm.org/D10782) Sanjoy updated cost estimation for the RewriteLoopExitValues to consider complicated SCEV expressions as cheap if there already exists llvm-ir expression which computes same value.
However if such expression is wrapped in a several other expressions we will still consider it as high cost.
For example this is considered high cost:
{-2,+,1} + (zext (<expr>)), where <expr> is high cost expression already defined in the IR.
In this change I updated cost estimation to evaluate such nested expressions as cheap. Turns out it is fairly important on one of our benchmarks (~20% performance).
In order to do that I have added new method "TryToGetValueForSCEVAt" into SCEVExpander, which tries to look for pre-existing llvm ir value. This method is used inside "ExpandSCEVIfNeeded" and inside "isHighCostExpansionHelper"
It would be natural to add "InsertedExpressions" lookup into this method, but I am not sure if there is really need for this. Also it is possible to use this method during "SCEVExpander::expand", but I am worried about having to much impact on the unrelated areas with no good reason.
Nit: spacing around =.