The patch is to enable ExitValue rewrite (In IndVarSimplify pass) only when the cost of expansion is low, just like LinearFunctionTestReplace does right now. The problem is described in https://llvm.org/bugs/show_bug.cgi?id=23538.
It includes these changes:
- Add an option. -replexitval=cheap is the default. -replexitval - Choose the strategy to replace exit value in IndVarSimplify =never - never replace exit value =cheap - only replace exit value when the cost is cheap =always - always replace exit value whenever possible
- The existing logic of SCEVExpander::isHighCostExpansionHelper is problematic. It cannot find out the udiv operator inside SCEVNAryExpr other than SCEVAddExpr. It doesn't check the sub SCEV inside SCEVTruncateExpr/SCEVZeroExtendExpr/SCEVSignExtendExpr. Like the SCEV: (-12 + (-12 * ((-12 + %len) /u 12)) + %len), SCEVExpander::isHighCostExpansionHelper will return false for it now. Fix the logic.
The patch improved an internal benchmark by 10%. It improved bzip2 in spec2000 by 1%.