Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[regression 9.0.0] -mllvm -polly-parallel is crashing clang after r362257 #42134

Closed Quuxplusone closed 4 years ago

Quuxplusone commented 5 years ago
Bugzilla Link PR43164
Status RESOLVED FIXED
Importance P release blocker
Reported by Sylvestre Ledru (sylvestre@debian.org)
Reported on 2019-08-29 06:59:45 -0700
Last modified on 2019-12-02 12:00:42 -0800
Version unspecified
Hardware PC Linux
CC hans@chromium.org, llvm-bugs@lists.llvm.org, llvm@meinersbur.de, lukebenes@hotmail.com, tobias@grosser.es, tstellar@redhat.com
Fixed by commit(s) rL372188, rG1c4b5a8
Attachments
Blocks PR43360
Blocked by
See also
This code works with clang 8

echo "
#define N 1536
float A[N][N];
float B[N][N];
float C[N][N];

void init_array()
{
    int i, j;
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) {
            A[i][j] = (1+(i*j)%1024)/2.0;
            B[i][j] = (1+(i*j)%1024)/2.0;
        }
    }
}

int main()
{
    int i, j, k;
    double t_start, t_end;
    init_array();
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) {
            C[i][j] = 0;
            for (k = 0; k < N; k++)
                C[i][j] = C[i][j] + A[i][k] * B[k][j];
        }
    }
    return 0;
}
" > foo.c
clang-$VERSION -O3 -mllvm -polly foo.c
=> works

clang-$VERSION -O3 -mllvm -polly -mllvm -polly-parallel foo.c
=> crashes with

Stack dump:
0.  Program arguments: /usr/lib/llvm-9/bin/clang -cc1 -triple x86_64-pc-linux-
gnu -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-
file-name foo.c -mrelocation-model static -mthread-model posix -fmath-errno -
masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu
x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/llvm-
9/lib/clang/9.0.0 -internal-isystem /usr/local/include -internal-isystem
/usr/lib/llvm-9/lib/clang/9.0.0/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-
externc-isystem /usr/include -O3 -fdebug-compilation-dir
/home/sylvestre/dev/debian/pkg-llvm/llvm-toolchain/branches/9 -ferror-limit 19 -
fmessage-length 0 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-
diagnostics -vectorize-loops -vectorize-slp -mllvm -polly -mllvm -polly-
parallel -faddrsig -o /tmp/foo-f16d16.o -x c foo.c
1.  <eof> parser at end of file
2.  Per-module optimization passes
3.  Running pass 'Function Pass Manager' on module 'foo.c'.
4.  Running pass 'Region Pass Manager' on function '@main'
5.  Running pass 'Polly - Create LLVM-IR from SCoPs' on basic block '%9'
 #0 0x00007fcb76737dff llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0xb74dff)
 #1 0x00007fcb76736210 llvm::sys::RunSignalHandlers() (/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0xb73210)
 #2 0x00007fcb76738201 (/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0xb75201)
 #3 0x00007fcb7c403730 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
 #4 0x00007fcb774a3bad llvm::RegionBase<llvm::RegionTraits<llvm::Function> >::blocks() (/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0x18e0bad)
 #5 0x00000000005729d7 addReferencesFromStmt(polly::ScopStmt const*, void*, bool) (/usr/lib/llvm-9/bin/clang+0x5729d7)
 #6 0x00000000005733ca IslNodeBuilder::getReferencesInSubtree(isl_ast_node*, llvm::SetVector<llvm::Value*, std::vector<llvm::Value*, std::allocator<llvm::Value*> >, llvm::DenseSet<llvm::Value*, llvm::DenseMapInfo<llvm::Value*> > >&, llvm::SetVector<llvm::Loop const*, std::vector<llvm::Loop const*, std::allocator<llvm::Loop const*> >, llvm::DenseSet<llvm::Loop const*, llvm::DenseMapInfo<llvm::Loop const*> > >&) (/usr/lib/llvm-9/bin/clang+0x5733ca)
 #7 0x0000000000575910 IslNodeBuilder::createForParallel(isl_ast_node*) (/usr/lib/llvm-9/bin/clang+0x575910)
 #8 0x00000000005775fd IslNodeBuilder::createBlock(isl_ast_node*) (/usr/lib/llvm-9/bin/clang+0x5775fd)
 #9 0x0000000000575188 IslNodeBuilder::createForSequential(isl::noexceptions::ast_node, bool) (/usr/lib/llvm-9/bin/clang+0x575188)
#10 0x0000000000576a98 IslNodeBuilder::createFor(isl_ast_node*) (/usr/lib/llvm-
9/bin/clang+0x576a98)
#11 0x000000000057488d IslNodeBuilder::createMark(isl_ast_node*) (/usr/lib/llvm-
9/bin/clang+0x57488d)
#12 0x00000000005748b7 IslNodeBuilder::createMark(isl_ast_node*) (/usr/lib/llvm-
9/bin/clang+0x5748b7)
#13 0x000000000057761c IslNodeBuilder::createBlock(isl_ast_node*)
(/usr/lib/llvm-9/bin/clang+0x57761c)
#14 0x000000000053a3e3 (/usr/lib/llvm-9/bin/clang+0x53a3e3)
#15 0x00007fcb774aa9f1 llvm::RGPassManager::runOnFunction(llvm::Function&)
(/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0x18e79f1)
#16 0x00007fcb768358a6 llvm::FPPassManager::runOnFunction(llvm::Function&)
(/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0xc728a6)
#17 0x00007fcb76835b53 llvm::FPPassManager::runOnModule(llvm::Module&)
(/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0xc72b53)
#18 0x00007fcb76836000 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/usr/lib/x86_64-linux-gnu/libLLVM-9.so.1+0xc73000)
#19 0x00007fcb7b1808b2 clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout
const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >) (/usr/lib/x86_64-linux-
gnu/libclang-cpp.so.9+0x125e8b2)
#20 0x00007fcb7b3b248d (/usr/lib/x86_64-linux-gnu/libclang-cpp.so.9+0x149048d)
#21 0x00007fcb7a71bd53 clang::ParseAST(clang::Sema&, bool, bool)
(/usr/lib/x86_64-linux-gnu/libclang-cpp.so.9+0x7f9d53)
#22 0x00007fcb7b980a48 clang::FrontendAction::Execute() (/usr/lib/x86_64-linux-
gnu/libclang-cpp.so.9+0x1a5ea48)
#23 0x00007fcb7b9405e0
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/x86_64-
linux-gnu/libclang-cpp.so.9+0x1a1e5e0)
#24 0x00007fcb7b9e35b0
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/x86_64-
linux-gnu/libclang-cpp.so.9+0x1ac15b0)
#25 0x00000000004a3f6b cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/lib/llvm-9/bin/clang+0x4a3f6b)
#26 0x00000000004a2291 main (/usr/lib/llvm-9/bin/clang+0x4a2291)
#27 0x00007fcb756af09b __libc_start_main (/lib/x86_64-linux-
gnu/libc.so.6+0x2409b)
#28 0x000000000049f70a _start (/usr/lib/llvm-9/bin/clang+0x49f70a)
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 9.0.0-+rc2-1~exp2 (tags/RELEASE_900/rc2)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to
https://bugs.llvm.org/ and include the crash backtrace, preprocessed source,
and associated run script.
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/foo-e49ed6.c
clang: note: diagnostic msg: /tmp/foo-e49ed6.sh
clang: note: diagnostic msg:

********************
Quuxplusone commented 5 years ago

I think this is showing up too late to block the release on.

It might be a good candidate for 9.0.1.

Quuxplusone commented 4 years ago
I bisected this regression to
http://llvm.org/viewvc/llvm-project?view=revision&revision=362257
     [ScheduleOptimizer] Hoist extension nodes after schedule optimization.

Michael Kruse,
Could you please take a look at this?
Quuxplusone commented 4 years ago

The change "causes" that SCoPs with extension nodes (in particular introduced by the matrix-matrix multiplication detection) can now be parallelized. The parallel outlining does not handle "copy statements" that have been added using those extension nodes.

I already have patch in the works. I am currently on a conference so not the fastest atm.

Quuxplusone commented 4 years ago

Should be fixed in r372188.

Quuxplusone commented 4 years ago

Reopening to track merging to 9.0.1.

Quuxplusone commented 4 years ago

Michael, Is this safe to merge:

https://reviews.llvm.org/rL372188

Quuxplusone commented 4 years ago
(In reply to Tom Stellard from comment #6)
> Michael, Is this safe to merge:
>
> https://reviews.llvm.org/rL372188

Yes
Quuxplusone commented 4 years ago

Merged: 1c4b5a8

Quuxplusone commented 4 years ago
Michael,
After your fix r372188, the crash has been fixed, but the reproducer still
fails to build with the following error:

$ clang -O3 -mllvm -polly foo.c
$ clang -O3 -mllvm -polly -mllvm -polly-parallel foo.c
/tmp/foo-5793f3.o: In function `main':
foo.c:(.text+0xe4): undefined reference to `GOMP_parallel_loop_runtime_start'
foo.c:(.text+0xf1): undefined reference to `GOMP_parallel_end'
...
foo.c:(.text+0x2ae): undefined reference to `GOMP_parallel_loop_runtime_start'
foo.c:(.text+0x2bb): undefined reference to `GOMP_parallel_end'
/tmp/foo-5793f3.o: In function `main_polly_subfn':
foo.c:(.text+0x2e7): undefined reference to `GOMP_loop_runtime_next'
foo.c:(.text+0x3f3): undefined reference to `GOMP_loop_runtime_next'
foo.c:(.text+0x408): undefined reference to `GOMP_loop_end_nowait'
/tmp/foo-5793f3.o: In function `main_polly_subfn_1':
...
/tmp/foo-5793f3.o: In function `main_polly_subfn_4':
foo.c:(.text+0x739): undefined reference to `GOMP_loop_runtime_next'
foo.c:(.text+0xa61): undefined reference to `GOMP_loop_runtime_next'
foo.c:(.text+0xa6e): undefined reference to `GOMP_loop_end_nowait'
clang-10: error: linker command failed with exit code 1 (use -v to see
invocation)
$ clang --version
clang version 10.0.0 (https://github.com/llvm/llvm-project.git
241b02e762872173dcb5bd27ff9fe3eb7dce1db2)

This issue persists in current master: 19fd8925a4afe6efd248688cce06aceff50efe0c

Could you please look into this?
Quuxplusone commented 4 years ago

Polly uses the OpenMP library for parallelism, hence it must added to the linker: either -lgomp or -lomp.

Quuxplusone commented 4 years ago
Michael,
Yes,-lgomp fixes the linker error in Clang 10. The last working commit,
r362256, neither -lgomp nor -lomp were required for a successful build. Is this
change in behavior expected?
Quuxplusone commented 4 years ago

This is because Polly could not parallelize this before r362257. Without parallelization, no OpenMP needed.