LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 25416 - clang hangs when compile a large c file.
Summary: clang hangs when compile a large c file.
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: LLVM Codegen (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: yunlian
URL:
Keywords:
Depends on:
Blocks: 24345
  Show dependency tree
 
Reported: 2015-11-05 13:23 PST by yunlian
Modified: 2016-09-09 15:17 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
test case for it. (539 bytes, application/x-shellscript)
2015-11-05 14:29 PST, yunlian
Details
reduced test (56.08 KB, text/x-csrc)
2015-11-05 15:02 PST, Rafael Ávila de Espíndola
Details

Note You need to log in before you can comment on or make changes to this bug.
Description yunlian 2015-11-05 13:23:25 PST
We have a c file like this
It contains a jmp statement for every 4K nop. There are over
4M instructions in the asm. gcc compile it within one second.
Clang hangs.
The command line is
 clang iTLB_benchmark_function.c -c -o iTLB_benchmark_function.o


void iTLB_bechmark_function() {
  __asm__ (
    "1:jmp 1f\n\t"
    "nop\n\t"
    "nop\n\t"
       .
       .
       .
    "1:nop\n\t"
  );
}
Comment 1 Rafael Ávila de Espíndola 2015-11-05 13:46:55 PST
Is clang -S slow too or just clang -c?

Can you attach the file?
Comment 2 yunlian 2015-11-05 14:29:32 PST
Created attachment 15227 [details]
test case for it.

The test c file is generated by the script attached.
One may run
./generateBenchmarkFunction.sh 4096 1024 > test.c

after that, one can run
clang -c test.c to reproduce this problem.
Comment 3 yunlian 2015-11-05 14:30:17 PST
(In reply to comment #1)
> Is clang -S slow too or just clang -c?
> 
> Can you attach the file?

The -S is slow too. gcc actually compile it within 3 seconds.
Comment 4 Rafael Ávila de Espíndola 2015-11-05 15:02:54 PST
Created attachment 15229 [details]
reduced test

This is really a clang bug. In this "small" version of the test:

* clang -cc1 test.c -emit-llvm -o t.ll: takes about 3s
* llvm-as/llvm-dis/llc/llvm-mc are "instantaneous"
* gcc/gas are "instantaneous"
Comment 5 yunlian 2015-11-05 17:43:38 PST
Most of time is spend on 
static llvm::MDNode *getAsmSrcLocInfo

in the loop 
 if (!StrVal.empty()) {
    const SourceManager &SM = CGF.CGM.getContext().getSourceManager();
    const LangOptions &LangOpts = CGF.CGM.getLangOpts();

    // Add the location of the start of each subsequent line of the asm to the
    // MDNode.

    for (unsigned i = 0, e = StrVal.size()-1; i != e; ++i) {
Comment 6 Nick Lewycky 2016-09-09 15:17:57 PDT
This was fixed by the reporter back in r255198. Thanks for the patch!