Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script: also dump cost-model when generating optimized ll #355

Closed
wants to merge 0 commits into from
Closed

script: also dump cost-model when generating optimized ll #355

wants to merge 0 commits into from

Conversation

goldsteinn
Copy link
Collaborator

@goldsteinn goldsteinn commented Mar 10, 2024

Didnt do a full test of regening, but the idea is it will be easier to check for regressions. Rather than eye-balling diff, this can give a reasonable estimate.

Might also be useful to dump -passes=instcount -stats

Edit: To be clear, the only think I tested was the regex.

@dtcxzyw dtcxzyw self-requested a review March 10, 2024 09:45
@dtcxzyw
Copy link
Owner

dtcxzyw commented Mar 10, 2024

Unknown type!
UNREACHABLE executed at /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/CodeGen/ValueTypes.cpp:590!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:

  1.  Program arguments: ../LLVM/llvm-build/bin/opt -passes=default<O3>,print<cost-model> -disable-loop-unrolling -vectorize-loops=false -force-vector-interleave=1 -force-vector-width=1 bench/mold/original/arch-riscv.cc.RV64LE.cc.ll -S -o bench/mold/optimized/arch-riscv.cc.RV64LE.cc.ll.bench_tmp.ll
    

#0 0x00007faa94fe9300 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x1e9300)
#1 0x00007faa94fe670f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x1e670f)
#2 0x00007faa94fe6865 SignalHandler(int) Signals.cpp:0:0
#3 0x00007faa94a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007faa94a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007faa94a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007faa94a969fc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007faa94a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007faa94a287f3 abort ./stdlib/abort.c:81:7
#9 0x00007faa94f01e3e (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x101e3e)
#10 0x00007faa91d3f685 (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCodeGen.so.19.0git+0x73f685)
#11 0x00007faa91d3f75c llvm::EVT::getEVT(llvm::Type*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCodeGen.so.19.0git+0x73f75c)
#12 0x00007faa93e09fef llvm::BasicTTIImplBasellvm::X86TTIImpl::getTypeLegalizationCost(llvm::Type*) const (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0x409fef)
#13 0x00007faa93e15e35 llvm::BasicTTIImplBasellvm::X86TTIImpl::getCmpSelInstrCost(unsigned int, llvm::Type*, llvm::Type*, llvm::CmpInst::Predicate, llvm::TargetTransformInfo::TargetCostKind, llvm::Instruction const*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0x415e35)
#14 0x00007faa93e036ca llvm::TargetTransformInfoImplCRTPBasellvm::X86TTIImpl::getInstructionCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>, llvm::TargetTransformInfo::TargetCostKind) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0x4036ca)
#15 0x00007faa8fe6cb75 llvm::TargetTransformInfo::getInstructionCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>, llvm::TargetTransformInfo::TargetCostKind) const (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.19.0git+0x46cb75)
#16 0x00007faa8fb580c8 llvm::CostModelPrinterPass::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.19.0git+0x1580c8)
#17 0x00007faa9226ed96 llvm::detail::PassModel<llvm::Function, llvm::CostModelPrinterPass, llvm::AnalysisManagerllvm::Function>::run(llvm::Function&, llvm::AnalysisManagerllvm::Function&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.19.0git+0x6ed96)
#18 0x00007faa8f7175ab llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x3175ab)
#19 0x00007faa93aa6946 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManagerllvm::Module>::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0xa6946)
#20 0x00007faa8f715421 llvm::PassManager<llvm::Module, llvm::AnalysisManagerllvm::Module>::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x315421)
#21 0x00007faa953ba4c5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRefllvm::PassPlugin, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x234c5)
#22 0x00007faa953c5096 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x2e096)
#23 0x00007faa94a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#24 0x00007faa94a29e40 call_init ./csu/../csu/libc-start.c:128:20
#25 0x00007faa94a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#26 0x0000564531881095 _start (../LLVM/llvm-build/bin/opt+0x1095)

We should fix this before landing the patch :(

@dtcxzyw
Copy link
Owner

dtcxzyw commented Mar 10, 2024

I will file an issue later.

@dtcxzyw
Copy link
Owner

dtcxzyw commented Mar 10, 2024

Reproducer:

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @_ZNSt8__detail8_ScannerIcEC2EPKcS3_NSt15regex_constants18syntax_option_typeESt6locale(ptr %this, i1 %call2, { i64, i64 } %0) {
entry:
  %cond = select i1 %call2, { i64, i64 } %0, { i64, i64 } zeroinitializer
  %cond.elt1 = extractvalue { i64, i64 } %cond, 1
  store i64 %cond.elt1, ptr %this, align 8
  ret void
}
> opt -passes="print<cost-model>" -S test.ll
Printing analysis 'Cost Model Analysis' for function '_ZNSt8__detail8_ScannerIcEC2EPKcS3_NSt15regex_constants18syntax_option_typeESt6locale':
Unknown type!
UNREACHABLE executed at /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/CodeGen/ValueTypes.cpp:590!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: bin/opt -passes=print<cost-model> reduced.ll
 #0 0x00007f6cb39e9300 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x1e9300)
 #1 0x00007f6cb39e670f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x1e670f)
 #2 0x00007f6cb39e6865 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f6cb3442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f6cb34969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f6cb34969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f6cb34969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f6cb3442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f6cb34287f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f6cb3901e3e (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x101e3e)
#10 0x00007f6cb073f685 (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCodeGen.so.19.0git+0x73f685)
#11 0x00007f6cb073f75c llvm::EVT::getEVT(llvm::Type*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCodeGen.so.19.0git+0x73f75c)
#12 0x00007f6cb2809fef llvm::BasicTTIImplBase<llvm::X86TTIImpl>::getTypeLegalizationCost(llvm::Type*) const (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0x409fef)
#13 0x00007f6cb2815e35 llvm::BasicTTIImplBase<llvm::X86TTIImpl>::getCmpSelInstrCost(unsigned int, llvm::Type*, llvm::Type*, llvm::CmpInst::Predicate, llvm::TargetTransformInfo::TargetCostKind, llvm::Instruction const*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0x415e35)
#14 0x00007f6cb28036ca llvm::TargetTransformInfoImplCRTPBase<llvm::X86TTIImpl>::getInstructionCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>, llvm::TargetTransformInfo::TargetCostKind) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0x4036ca)
#15 0x00007f6cae86cb75 llvm::TargetTransformInfo::getInstructionCost(llvm::User const*, llvm::ArrayRef<llvm::Value const*>, llvm::TargetTransformInfo::TargetCostKind) const (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.19.0git+0x46cb75)
#16 0x00007f6cae5580c8 llvm::CostModelPrinterPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.19.0git+0x1580c8)
#17 0x00007f6cb0c6ed96 llvm::detail::PassModel<llvm::Function, llvm::CostModelPrinterPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.19.0git+0x6ed96)
#18 0x00007f6cae1188b1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x3188b1)
#19 0x00007f6cb24a5556 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0xa5556)
#20 0x00007f6cae1175ab llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x3175ab)
#21 0x00007f6cb24a6946 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0xa6946)
#22 0x00007f6cae115421 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x315421)
#23 0x00007f6cb3d674c5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x234c5)
#24 0x00007f6cb3d72096 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x2e096)
#25 0x00007f6cb3429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#26 0x00007f6cb3429e40 call_init ./csu/../csu/libc-start.c:128:20
#27 0x00007f6cb3429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#28 0x000055d247b26095 _start (bin/opt+0x1095)
Aborted (core dumped)

@goldsteinn
Copy link
Collaborator Author

What also might be interesting, is to use -passes=instcount -stats, then if there is a regession, call llvm-reduce with the interesting condition being that count(before) - count(after) == diff_in_full_file.

@dtcxzyw
Copy link
Owner

dtcxzyw commented May 6, 2024

key = (add, sub)
if key in diff_pattern:
continue
diff_pattern.add(key)

I hope this simple strategy works :)

@goldsteinn goldsteinn closed this Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants