llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.57k stars 11.81k forks source link

[Loop vectorizer] Run-time failures in test-suite with AVX512F #31019

Closed llvmbot closed 7 years ago

llvmbot commented 7 years ago
Bugzilla Link 31671
Resolution FIXED
Resolved on Jan 21, 2017 23:42
Version trunk
OS Windows NT
Attachments test compiled with TOT clang -marh=knl -S -emit-llvm, test compiled with TOT clang + revert r282418 -march=knl -S -emit-llvm
Reporter LLVM Bugzilla Contributor
CC @ayalz,@delena,@ZviRackover

Extended Description

The tests:

test-suite MultiSource/Benchmarks/TSVC/LoopRerolling-dbl/LoopRerolling-dbl test-suite MultiSource/Benchmarks/TSVC/LoopRerolling-flt/LoopRerolling-flt

fail in runtime (wrong output) when built with AVX512 (and executed on KNL target) - specifically the function s351() returns a wrong result.

Initially, it seems that is started failing due to the combination of r290810 and r284779. But these are actually just changes to the cost model and enabling interleaved memory accesses by default for X86. Bisecting the erroneous function while compiling with force-vector-width and enable-interleaved-mem-accesses seems to lead to r282418.

I've attached the .ll files produced by compiling with -march=knl using TOT clang VS TOT+revert-r282418.

The C code that contains the diff in IR is: int s351() { ... TYPE alpha = c[0]; for (int nl = 0; nl < 8ntimes; nl++) { for (int i = 0; i < LEN; i += 5) { a[i] += alpha b[i]; a[i + 1] += alpha b[i + 1]; a[i + 2] += alpha b[i + 2]; a[i + 3] += alpha b[i + 3]; a[i + 4] += alpha b[i + 4]; } dummy(a, b, c, d, e, aa, bb, cc, 0.); } .. check(1); return 0; }

Putting aside the fact the the loop wasn't re-rolled, from the diff it looks like the generated IR is doing something wrong(See that attached files for a full context):

TOT: %10 = add <16 x i64> %broadcast.splat, <i64 1, i64 6, i64 11, i64 16, i64 21, i64 26, i64 31, i64 36, i64 41, i64 46, i64 51, i64 56, i64 61, i64 66, i64 71, i64 76> ... %VectorGep86 = getelementptr inbounds %struct.GlobalData, %struct.GlobalData @​global_data, i64 0, i32 0, <16 x i64> %10 call void @​llvm.masked.scatter.v16f32(<16 x float> %15, <16 x float> %VectorGep86

TOT+revert: %10 = or i64 %offset.idx, 1 %broadcast.splatinsert86 = insertelement <16 x i64> undef, i64 %10, i32 0 %broadcast.splat87 = shufflevector <16 x i64> %broadcast.splatinsert86, <16 x i64> undef, <16 x i32> zeroinitializer ... %VectorGep88 = getelementptr inbounds %struct.GlobalData, %struct.GlobalData @​global_data, i64 0, i32 0, <16 x i64> %broadcast.splat87 call void @​llvm.masked.scatter.v16f32(<16 x float> %14, <16 x float> %VectorGep88

In the latter it seems that the scatter writes to a splat of the i+1 instead of <i+1,i+6,i+11,..,i+76>

llvmbot commented 7 years ago

Patch committed in r292254. Please let me know if this doesn't resolve the problem.

llvmbot commented 7 years ago

Patch submitted for review: https://reviews.llvm.org/D28819.

llvmbot commented 7 years ago

Thanks for reporting, Elad. I'll take a look.