This was found during the course of Compact String work. This manifests in Integer.toString and Long.toString changes there.
It boils down to this. When there is a strength reduction opportunity to reduce multiplication to shift, it fails when we have a
non-trivial control flow preceding the argument. The breakage would only happen if the alternative branch is not folded into
uncommon trap.
int idx;
boolean flag;
@Benchmark
public void mult() {
doMult();
}
@CompilerControl(CompilerControl.Mode.DONT_INLINE)
private int doMult() {
int mult = flag ? 1 : 2;
return idx * mult;
}
Complete benchmark, some performance data and generated code:
http://cr.openjdk.java.net/~shade/8130273/StrengthReduction.java
Runnable JAR:
http://cr.openjdk.java.net/~shade/8130273/benchmarks.jar