llvm / llvm-project

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

LSR takes a long time to build a c file with -O2 #7948

Open llvmbot opened 14 years ago

llvmbot commented 14 years ago
Bugzilla Link 7576
Version trunk
OS Linux
Attachments Intermediate source from clang compile
Reporter LLVM Bugzilla Contributor
CC @sunfishcode

Extended Description

The NetSurf project (http://netsurf-browser.org/) has a single file which takes an unusually long time to compile with -O2 optimisation turned on.

The smallest test case I can currently reproduce the issue with is building the file (/content/urldb.c within our codebase) as part of the test suite.

Here are the tests showing the compile time for clang and gcc with and without -O2

$ clang --version clang version 2.0 (trunk 106560) Target: x86_64-unknown-linux-gnu Thread model: posix

$ gcc --version gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ time clang -std=c99 -g -O2 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I.. pkg-config --cflags libxml-2.0 libcurl ../content/urldb.c ../utils/url.c ../utils/utils.c ../utils/messages.c ../utils/hashtable.c ../utils/filename.c ../test/urldbtest.c -o urldbtest pkg-config --libs libxml-2.0 libcurl

real 1m55.421s user 1m49.927s sys 0m1.228s $ time clang -std=c99 -g -O0 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I.. pkg-config --cflags libxml-2.0 libcurl ../content/urldb.c ../utils/url.c ../utils/utils.c ../utils/messages.c ../utils/hashtable.c ../utils/filename.c ../test/urldbtest.c -o urldbtest pkg-config --libs libxml-2.0 libcurl

real 0m1.577s user 0m1.200s sys 0m0.192s $ time gcc -std=c99 -g -O2 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I.. pkg-config --cflags libxml-2.0 libcurl ../content/urldb.c ../utils/url.c ../utils/utils.c ../utils/messages.c ../utils/hashtable.c ../utils/filename.c ../test/urldbtest.c -o urldbtest pkg-config --libs libxml-2.0 libcurl

real 0m3.229s user 0m2.696s sys 0m0.308s $ time gcc -std=c99 -g -O0 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I.. pkg-config --cflags libxml-2.0 libcurl ../content/urldb.c ../utils/url.c ../utils/utils.c ../utils/messages.c ../utils/hashtable.c ../utils/filename.c ../test/urldbtest.c -o urldbtest pkg-config --libs libxml-2.0 libcurl

real 0m1.242s user 0m0.920s sys 0m0.196s

The specific file that is taking the time is content/urldb.c

$ time clang -std=c99 -c -g -O2 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I.. pkg-config --cflags libxml-2.0 libcurl ../content/urldb.c

real 1m50.883s user 1m47.823s sys 0m0.764s $ time clang -std=c99 -c -g -O0 -D_BSD_SOURCE -D_POSIX_C_SOURCE -I.. pkg-config --cflags libxml-2.0 libcurl ../content/urldb.c

real 0m0.649s user 0m0.520s sys 0m0.060s

I saved the intermediate files (-save-temps) from the previous compile (attached) and re-tested

time clang -c -O0 urldb.i

real 0m0.645s user 0m0.512s sys 0m0.028s [16:49 vince@derik ~/netsurf/netsurf-trunk/test]$ time clang -c -O2 urldb.i

real 1m52.981s user 1m48.683s sys 0m0.892s

sunfishcode commented 14 years ago

LSR is failing to recognize that there's nothing to be gained in digging through those 20 or so chained loops for reassociation candidates.

llvmbot commented 14 years ago

The code generator is taking all the time (you can see this by adding -emit-llvm : it then compiles quickly; passing the resulting LLVM IR to llc then results in llc taking a long time).