Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Compile time extremely long while compiling template #18114

Closed Quuxplusone closed 3 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR18115
Status RESOLVED FIXED
Importance P normal
Reported by Eric Kiander (ekiander@netherrealm.com)
Reported on 2013-12-02 13:32:56 -0800
Last modified on 2021-02-26 17:46:44 -0800
Version trunk
Hardware Other MacOS X
CC anton@korobeynikov.info, dgregor@apple.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com, rafael@espindo.la, richard-llvm@metafoo.co.uk, rnk@google.com
Fixed by commit(s)
Attachments ClangOptBug.rar (4308 bytes, application/octet-stream)
ClangOptBug.ii (891519 bytes, application/octet-stream)
Blocks
Blocked by
See also
Created attachment 11646
Code snippet to revela compiler bug

We noticed this bug while compiling Scaleform for the PS4 and iOS. At first we
thought it might be an SN system bug but then the same bug shows up with XCode
on iOS so we now assume it's something wrong with clang.

Anyways while compiling a file containing mostly templates, the compiler would
hang for a very long time and it would take hours to compile the file. We do
have a workaround by compiling the single file without generating debug info
and also no optimizations. We also duplicated the behavior via a code snippet
which I have attached.
Quuxplusone commented 10 years ago
Here's what I see with a build from trunk (this is an unoptimized clang binary
with asserts, so the absolute times aren't very interesting, but give an upper
bound on compile time):

  -O0: 3.06s
  -O0 -g: 3.75s
  -O3: 24.39s
  -O3 -g: 42.27s

How does this compare with what you see for the reduced testcase with Clang 3.3?
Quuxplusone commented 10 years ago

Hmmmm, we'll we actually tried our test code on the Mac and couldn't reproduce it with the Xcode's version of clang. We could possibly give you PS4 timings but we were hesitant because we were thinking it was a custom version of clang. I could try to get those if that will help?

I believe there is a bug open with SN systems too.

The wierd thing is that the particular Scaleform .cpp file causes both the PS4 and Xcode clang compilers to choke, eating up tons of memeory and taking forever to complete.

Quuxplusone commented 10 years ago
(In reply to comment #2)
> Hmmmm, we'll we actually tried our test code on the Mac and couldn't
> reproduce it with the Xcode's version of clang.
> ...
> The wierd thing is that the
> particular Scaleform .cpp file causes both the PS4 and Xcode clang compilers
> to choke, eating up tons of memeory and taking forever to complete.

Sorry... you are, or are not, able to reproduce this with Xcode?

> We could possibly give you
> PS4 timings but we were hesitant because we were thinking it was a custom
> version of clang. I could try to get those if that will help?

That compiler is somewhat customized but for compile-time performance
issues the most relevant customizations are the command-line options,
and the most relevant of those are usually:
  -fno-exceptions -fno-rtti -fPIC
Also note that the currently released PS4 compiler is based on LLVM 3.2.

So, if you could be explicit about what options you use, and when you
do and don't see the problem, and what version of Xcode you are using,
that would help.

> I believe there is a bug open with SN systems too.

Yes there is.
Quuxplusone commented 10 years ago

Sorry... you are, or are not, able to reproduce this with Xcode?

With that code snippet I attached it seems we can not reproduce the long compile time in XCode 5.0.2, but we still see long compile times with XCode 5.0.2 when we compile the Scaleform .cpp file that originally brought this to our attention initially. I'll keep messing around with XCode to see if I can get an easy example case, as you stated it may be just certain flags that exhibit the behavior. AS this is an Unreal integration I'll have to pull the build appart a bit to see what exactly is causing it.

I do have a ticket open with Adobe/Scaleform with no replies from them unfortunately.

We do however see the bug always with the SN system version of clang, with the attached code snippet and the Scaleform.cpp.

Quuxplusone commented 10 years ago
(In reply to comment #3)
> So, if you could be explicit about what options you use, and when you
> do and don't see the problem, and what version of Xcode you are using,
> that would help.

Well I did get it to repro with the XCode 5.0.2 clang compiler. This was the
basic command line I used

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-c -arch armv7 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk
-O3 -gdwarf-2 -fno-exceptions -fno-rtti ClangOptBug.cpp

The key is -fno-exceptions and -fno-rtti. If I add those options with an
optimized build it will take an extremely long time here are some timings from
our Mac.

-O0 -g0
0.438-

-O3 - gdwarf-2
4.197 secs

-O0 -g0 -fno-exceptions -fno-rtti
0.439

-O3 -gdwarf-2  -fno-exceptions -fno-rtti
13m 39seconds
Quuxplusone commented 10 years ago

Attached ClangOptBug.rar (4308 bytes, application/octet-stream): Code snippet to revela compiler bug

Quuxplusone commented 10 years ago

Attached ClangOptBug.ii (891519 bytes, application/octet-stream): preprocessed file

Quuxplusone commented 10 years ago
This is slow, but much better on trunk:

$ time clang -cc1 -triple thumbv7-apple-ios7.0.0 -S -target-abi apcs-gnu -g -O2
-fblocks ClangOptBug.ii

real    1m35.015s
user    1m27.564s
sys 0m4.733s

$ time
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-cc1 -triple thumbv7-apple-ios7.0.0 -S -target-abi apcs-gnu -g -O2 -fblocks
ClangOptBug.ii

real    14m14.983s
user    14m9.464s
sys 0m4.459s
Quuxplusone commented 10 years ago
perf says:

    24.84%      llc  llc                  [.] llvm::LiveDebugVariables::emitDebugValues(llvm::VirtRegMap*)
    18.74%      llc  llc                  [.] llvm::LiveDebugVariables::splitRegister(unsigned int, llvm::ArrayRef<unsigned int>, llvm::LiveIntervals&)
     6.45%      llc  llc                  [.] llvm::MachineOperand::isIdenticalTo(llvm::MachineOperand const&) const
Quuxplusone commented 3 years ago

I have a faster machine, but now this example takes 0m21.393s to compile for me. We can close this out.