[PowerPC] assertion failure with complicated BitInt
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Live Reproducer: https://godbolt.org/z/xv1McW6aj
Compiling the following C code for `powerpc64` with `clang -O2` crashes with assertion failure.
```c
typedef unsigned _BitInt(63) uint63_t;
typedef unsigned _BitInt(65) uint65_t;
typedef _BitInt(113) int113_t;
typedef unsigned _BitInt(127) uint127_t;
typedef unsigned __int128 uint128_t;
typedef __int128 int128_t;
long long safe_add_i64(long long a, long long b) { long long r; return __builtin_add_overflow(a, b, &r) ? : r; }
long long safe_shl_i64(long long a, long long b) { unsigned s = (b % 64); return (a < 0 || a > (0x7fffffffffffffffLL >> s)) ? : 0; }
_BitInt(127) safe_mul_i127(_BitInt(127) a, _BitInt(127) b) { _BitInt(127) r; return __builtin_mul_overflow(a, b, &r) ? : r; }
uint128_t safe_div_u128(uint128_t, uint128_t);
extern signed char f1(void);
extern unsigned long long opq(void);
static int128_t a1[8];
static int113_t g2;
typedef struct {
uint65_t f0 : 34;
uint65_t f1;
} S0;
int main(void) {
uint127_t x5 = opq();
S0 s0;
while (f1())
x5 = 0;
for (unsigned w8 = 0U; f1() && w8 < 8U; w8++)
g2 = s0.f1 = opq();
uint63_t amt = (g2 > 0) ? 0 : x5;
s0.f0 = opq();
x5 = safe_add_i64(safe_shl_i64(s0.f0, amt), safe_mul_i127(s0.f1, x5));
unsigned n13 = opq();
for (unsigned i14 = 0U; i14 < n13; i14++) {
a1[0] = 1 << safe_div_u128(1, ((a1[x5 & 7U] != 0) ? 0 : s0.f1));
}
}
```
clang command:
```sh
clang --target=powerpc64-linux-gnu -O2 repro.c
```
The compiler crashes with the following output:
```
The register $carry needs to be live in to %bb.12, but is missing from the live-in list.
fatal error: error in backend: Invalid global physical register
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics --target=powerpc64-linux-gnu -O2
1. parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module ''.
4. Running pass 'Machine Instruction Scheduler' on function '@main'
#0 0x000000000449a958 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x449a958)
#1 0x0000000004497bb4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4497bb4)
#2 0x00000000044981ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44981ec)
#3 0x00000000043d54d6 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43d54d6)
#4 0x000000000448f75e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x448f75e)
#5 0x0000000000d8b0f0 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
#6 0x00000000043def23 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43def23)
#7 0x00000000043df081 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43df081)
#8 0x000000000364df87 llvm::LiveRangeCalc::findReachingDefs(llvm::LiveRange&, llvm::MachineBasicBlock&, llvm::SlotIndex, llvm::Register, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x364df87)
#9 0x000000000364f0c6 llvm::LiveRangeCalc::extend(llvm::LiveRange&, llvm::SlotIndex, llvm::Register, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x364f0c6)
#10 0x000000000364fc98 llvm::LiveIntervalCalc::extendToUses(llvm::LiveRange&, llvm::Register, llvm::LaneBitmask, llvm::LiveInterval*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x364fc98)
#11 0x000000000362f481 llvm::LiveIntervals::computeRegUnitRange(llvm::LiveRange&, llvm::MCRegUnit) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x362f481)
#12 0x0000000003635825 llvm::LiveIntervals::HMEditor::updateAllRanges(llvm::MachineInstr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3635825)
#13 0x000000000363a362 llvm::LiveIntervals::handleMove(llvm::MachineInstr&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x363a362)
#14 0x00000000037958e9 llvm::ScheduleDAGMI::moveInstruction(llvm::MachineInstr*, llvm::MachineInstrBundleIterator) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37958e9)
#15 0x00000000037a06fa llvm::ScheduleDAGMILive::scheduleMI(llvm::SUnit*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37a06fa)
#16 0x00000000037ade85 llvm::ScheduleDAGMILive::schedule() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37ade85)
#17 0x000000000379d0f2 llvm::impl_detail::MachineSchedulerBase::scheduleRegions(llvm::ScheduleDAGInstrs&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x379d0f2)
#18 0x000000000379f39c llvm::impl_detail::MachineSchedulerImpl::run(llvm::MachineFunction&, llvm::TargetMachine const&, llvm::impl_detail::MachineSchedulerImpl::RequiredAnalyses const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x379f39c)
#19 0x00000000037a02d3 (anonymous namespace)::MachineSchedulerLegacy::runOnMachineFunction(llvm::MachineFunction&) MachineScheduler.cpp:0:0
#20 0x00000000036efa6d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#21 0x0000000003d6b004 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d6b004)
#22 0x0000000003d6b501 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d6b501)
#23 0x0000000003d6bec9 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d6bec9)
#24 0x0000000005844035 runCodeGenPipelineLegacy(llvm::TargetMachine&, llvm::Module&, llvm::raw_pwrite_stream&, std::unique_ptr>&, llvm::CodeGenFileType, bool, bool) (.constprop.0) RunCodeGen.cpp:0:0
#25 0x000000000584409d llvm::runCodeGenPipeline(llvm::TargetMachine&, llvm::Module&, llvm::raw_pwrite_stream&, std::unique_ptr>&, llvm::CodeGenFileType, bool, bool, llvm::IntrusiveRefCntPtr) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x584409d)
#26 0x00000000048d445b (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#27 0x00000000048d4a1c clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48d4a1c)
#28 0x0000000004fad447 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4fad447)
#29 0x0000000006de8afc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6de8afc)
#30 0x0000000004fad878 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4fad878)
#31 0x00000000052cde58 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52cde58)
#32 0x000000000525b95d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x525b95d)
#33 0x00000000053a262d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x53a262d)
```
clang version:
```text
clang version 24.0.0git (https://github.com/llvm/llvm-project 05fa66e6624e6b14346e559cd7b692aaf48f3ca7)
```
This reproduces with current LLVM trunk.
Contributor guide
Research direction
Run the provided repro.c with clang --target=powerpc64-linux-gnu -O2 and confirm the assertion. Start with the Machine Instruction Scheduler and the MachineScheduler.cpp stack entry, then trace the missing $carry live-in diagnostic. Done means the reproducer compiles without the backend crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100