[llvm] [IROutliner] do not outline non-uniform constants (PR #195450)

Arda Serdar Pektezol via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 19 10:58:41 PDT 2026


pektezol wrote:

> Have you tried the testcases from #179885 against this PR?
> 
> I started looking at the implementation of `canReplaceOperandWithVariable` and I'm pretty confused by the `if (!isa<Constant, InlineAsm>(Op))` check, which is looking at the operand intending to be replaced, which doesn't make much sense to me, but maybe I'm thinking about it wrong.
> 
> I'd have to go over the original failure in detail again, to understand what's going on with the GVN ids, and the InstructionData and similar, to see if this can be extended to constants (which are not `Instruction`s).
> 
> One reason I slightly gave up is that even if this bug is squashed, the IR Outliner is so restricted in what it can actually outline that it's a little pointless to enable, IMO. I don't have the time to prioritise work on it so we told our users who were enabling it manually not to.

The test fails:

```
Command Output (stdout):
--
# RUN: at line 2
/home/pektezol/dev/llvm-fork/build-194733/bin/opt -S -passes=verify,iroutliner -ir-outlining-no-cost < /home/pektezol/dev/llvm-fork/llvm/test/Transforms/IROutliner/a.ll | /home/pektezol/dev/llvm-fork/build-194733/bin/FileCheck /home/pektezol/dev/llvm-fork/llvm/test/Transforms/IROutliner/a.ll
# executed command: /home/pektezol/dev/llvm-fork/build-194733/bin/opt -S -passes=verify,iroutliner -ir-outlining-no-cost
# .---command stderr------------
# | opt: /home/pektezol/dev/llvm-fork/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From*) [with To = Constant; From = Value]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /home/pektezol/dev/llvm-fork/build-194733/bin/opt -S -passes=verify,iroutliner -ir-outlining-no-cost
# | 1.	Running pass "iroutliner" on module "<stdin>"
# |  #0 0x0000555779820b62 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x19a0b62)
# |  #1 0x000055577981d1e9 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
# |  #2 0x00007f574883e8f0 (/usr/lib/libc.so.6+0x3e8f0)
# |  #3 0x00007f574889a29c (/usr/lib/libc.so.6+0x9a29c)
# |  #4 0x00007f574883e7d0 raise (/usr/lib/libc.so.6+0x3e7d0)
# |  #5 0x00007f5748825681 abort (/usr/lib/libc.so.6+0x25681)
# |  #6 0x00007f5748826700 (/usr/lib/libc.so.6+0x26700)
# |  #7 0x00007f5748836532 __assert_fail (/usr/lib/libc.so.6+0x36532)
# |  #8 0x000055577a1767d8 (anonymous namespace)::Mapper::mapValue(llvm::Value const*) (.cold) ValueMapper.cpp:0:0
# |  #9 0x000055577a17c7d7 (anonymous namespace)::Mapper::remapInstruction(llvm::Instruction*) ValueMapper.cpp:0:0
# | #10 0x000055577a17d9a8 (anonymous namespace)::Mapper::remapFunction(llvm::Function&) ValueMapper.cpp:0:0
# | #11 0x000055577a17e797 llvm::ValueMapper::remapFunction(llvm::Function&) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x22fe797)
# | #12 0x000055577bc600ac replaceConstants(llvm::OutlinableRegion&) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x3de00ac)
# | #13 0x000055577bc68935 llvm::IROutliner::fillOverallFunction(llvm::Module&, OutlinableGroup&, std::vector<llvm::DenseMap<llvm::Value*, llvm::BasicBlock*, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, llvm::BasicBlock*>>, std::allocator<llvm::DenseMap<llvm::Value*, llvm::BasicBlock*, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, llvm::BasicBlock*>>>>&, std::vector<llvm::Function*, std::allocator<llvm::Function*>>&) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x3de8935)
# | #14 0x000055577bc68f74 llvm::IROutliner::deduplicateExtractedSections(llvm::Module&, OutlinableGroup&, std::vector<llvm::Function*, std::allocator<llvm::Function*>>&, unsigned int&) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x3de8f74)
# | #15 0x000055577bc72a4f llvm::IROutliner::doOutline(llvm::Module&) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x3df2a4f)
# | #16 0x000055577bc73adf llvm::IROutlinerPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x3df3adf)
# | #17 0x000055577b73baff llvm::detail::PassModel<llvm::Module, llvm::IROutlinerPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilder.cpp:0:0
# | #18 0x0000555779ae64ad llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x1c664ad)
# | #19 0x000055577b550a82 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, bool) (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x36d0a82)
# | #20 0x00005557797fe55f optMain (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x197e55f)
# | #21 0x00007f5748827741 (/usr/lib/libc.so.6+0x27741)
# | #22 0x00007f5748827879 __libc_start_main (/usr/lib/libc.so.6+0x27879)
# | #23 0x00005557797ec3e5 _start (/home/pektezol/dev/llvm-fork/build-194733/bin/opt+0x196c3e5)
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /home/pektezol/dev/llvm-fork/build-194733/bin/FileCheck /home/pektezol/dev/llvm-fork/llvm/test/Transforms/IROutliner/a.ll
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/pektezol/dev/llvm-fork/build-194733/bin/FileCheck /home/pektezol/dev/llvm-fork/llvm/test/Transforms/IROutliner/a.ll
# `-----------------------------
# error: command failed with exit status: 2
```

https://github.com/llvm/llvm-project/pull/195450


More information about the llvm-commits mailing list