Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Clang hangs with -O1 on switches #18897

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR18898
Status NEW
Importance P normal
Reported by skvadrik@gmail.com
Reported on 2014-02-19 06:57:26 -0800
Last modified on 2014-02-24 05:49:22 -0800
Version 3.4
Hardware PC Linux
CC geek4civic@gmail.com, hans@chromium.org, hfinkel@anl.gov, llvm-bugs@lists.llvm.org, llvm@sunfishcode.online, rnk@google.com
Fixed by commit(s)
Attachments utf16_group_C.w.cpp (944465 bytes, text/x-c++src)
Blocks
Blocked by
See also
Created attachment 12088
re2c-generated C++ source file, contains big 'switch' statemants.

This hangs infinitely:

$ clang++ -O1 utf16_group_C.w.cpp

This .cpp file is autogenerated by RE2C scanner generator. RE2C can generate
either 'switch' statements or nested 'if' statements that express the same
logic.
Clang hangs on 'switch'es, but doesn't hang on 'if's. Clang hangs with -O1 or
higher level of optimisations, but not with -O0.
Quuxplusone commented 10 years ago

Attached utf16_group_C.w.cpp (944465 bytes, text/x-c++src): re2c-generated C++ source file, contains big 'switch' statemants.

Quuxplusone commented 10 years ago
Here's a backtrace. It seems we're stuck in the loop in
Loop::hasDedicatedExits().

#0  0x00000000010e499d in llvm::PredIterator<llvm::BasicBlock,
llvm::value_use_iterator<llvm::User> >::operator== (this=0x7fffffffb5a0, x=...)
    at /usr/local/google/work/llvm/include/llvm/Support/CFG.h:52
#1  0x00000000010e395f in llvm::PredIterator<llvm::BasicBlock,
llvm::value_use_iterator<llvm::User> >::operator!= (this=0x7fffffffb5a0, x=...)
    at /usr/local/google/work/llvm/include/llvm/Support/CFG.h:53
#2  0x000000000312e15a in llvm::Loop::hasDedicatedExits (this=0x63eb410)
    at /usr/local/google/work/llvm/lib/Analysis/LoopInfo.cpp:341
#3  0x0000000002efa681 in (anonymous namespace)::LICM::runOnLoop (
    this=0x653b3c0, L=0x63eb410, LPM=...)
    at /usr/local/google/work/llvm/lib/Transforms/Scalar/LICM.cpp:281
#4  0x000000000313a29f in llvm::LPPassManager::runOnFunction (this=0x653a7a0,
    F=...) at /usr/local/google/work/llvm/lib/Analysis/LoopPass.cpp:232
#5  0x00000000032d35b4 in llvm::FPPassManager::runOnFunction (this=0x6534a60,
    F=...) at /usr/local/google/work/llvm/lib/IR/LegacyPassManager.cpp:1537
#6  0x00000000030a4360 in (anonymous namespace)::CGPassManager::RunPassOnSCC (
    this=0x6532ad0, P=0x6534a60, CurSCC=..., CG=...,
    CallGraphUpToDate=@0x7fffffffbb0f: true,
    DevirtualizedCall=@0x7fffffffbc1f: false)
    at /usr/local/google/work/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp:148
#7  0x00000000030a515b in (anonymous
namespace)::CGPassManager::RunAllPassesOnSCC (this=0x6532ad0, CurSCC=...,
CG=...,
    DevirtualizedCall=@0x7fffffffbc1f: false)
    at /usr/local/google/work/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp:405
#8  0x00000000030a54af in (anonymous namespace)::CGPassManager::runOnModule (
    this=0x6532ad0, M=...)
    at /usr/local/google/work/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp:460
#9  0x00000000032d3a78 in (anonymous namespace)::MPPassManager::runOnModule (
    this=0x652c170, M=...)
    at /usr/local/google/work/llvm/lib/IR/LegacyPassManager.cpp:1615
#10 0x00000000032d4088 in llvm::legacy::PassManagerImpl::run (this=0x652be80,
    M=...) at /usr/local/google/work/llvm/lib/IR/LegacyPassManager.cpp:1710
#11 0x00000000032d4293 in llvm::legacy::PassManager::run (this=0x58ed510,
    M=...) at /usr/local/google/work/llvm/lib/IR/LegacyPassManager.cpp:1745
#12 0x0000000000f4a237 in (anonymous
namespace)::EmitAssemblyHelper::EmitAssembly (this=0x7fffffffbf40,
Action=clang::Backend_EmitObj, OS=0x5917b00)
    at /usr/local/google/work/llvm/tools/clang/lib/CodeGen/BackendUtil.cpp:599
#13 0x0000000000f4a35f in clang::EmitBackendOutput (Diags=..., CGOpts=...,
    TOpts=..., LOpts=..., TDesc=..., M=0x591f3d0,
    Action=clang::Backend_EmitObj, OS=0x5917b00)
Quuxplusone commented 10 years ago
It is reproducible with "clang -O0 -emit-llvm -S | opt -O1"

...and it is not infinite loop. I hit LICM at first.

===-------------------------------------------------------------------------===
                      ... Pass execution timing report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 2516.2075 seconds (2516.6312 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
  685.5958 ( 27.2%)   0.0000 (  0.0%)  685.5958 ( 27.2%)  685.7107 ( 27.2%)  Delete dead loops
  454.4459 ( 18.1%)   0.0000 (  0.0%)  454.4459 ( 18.1%)  454.5218 ( 18.1%)  Block Frequency Analysis
  349.6658 ( 13.9%)   0.0000 (  0.0%)  349.6658 ( 13.9%)  349.7282 ( 13.9%)  Loop Invariant Code Motion
  345.2845 ( 13.7%)   0.0000 (  0.0%)  345.2845 ( 13.7%)  345.3420 ( 13.7%)  Unswitch loops
  340.6992 ( 13.5%)   0.0000 (  0.0%)  340.6992 ( 13.5%)  340.7560 ( 13.5%)  Loop Vectorization
  340.0083 ( 13.5%)   0.0000 (  0.0%)  340.0083 ( 13.5%)  340.0651 ( 13.5%)  Induction Variable Simplification
(snip)