Recently we find a defect of post loop vectorization from a fuzzer test. After a few investigation, we created below simple case to reproduce it on CPUs with vector mask support (x86 AVX-512 or AArch64 SVE).
public class Foo {
private static int[] a = new int[100];
private static long val = 0;
private static void bar() {
int i = 0;
for (i = 3; i < 50; i++)
a[i] += 1;
val += i;
}
public static void main(String[] strArr) {
bar();
System.out.println(val);
}
}
$ java Foo
50
$ java -Xcomp -XX:+UnlockDiagnosticVMOptions -XX:CompileOnly=Foo.bar -XX:-TieredCompilation -XX:+UnlockExperimentalVMOptions -XX:+PostLoopMultiversioning Foo
47
In this case, the induction variable `i` is used after the loop and converted and added to a long. The add uses the ConvI2LNode which is not correctly incremented after loop.