llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

AArch64 global isel "Assertion failed: (HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry && "Scope imbalance!")" on valid code #60516

Open regehr opened 1 year ago

regehr commented 1 year ago

This function:

target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-linux-gnu"

define i32 @f() {
  %1 = icmp sge i16 0, 0
  %2 = sext i1 true to i8
  %3 = sext i8 %2 to i32
  %4 = sext i1 %1 to i32
  %5 = udiv i32 %3, %4
  %6 = sext i1 %1 to i32
  %7 = sext i1 true to i32
  %8 = urem i32 %6, %7
  %9 = trunc i32 %8 to i8
  %10 = zext i32 %5 to i64
  %11 = sext i8 %9 to i64
  %12 = or i64 %10, %11
  %13 = trunc i64 %12 to i32
  ret i32 %13
}

is causing Global Isel to assert out:

Johns-MacBook-Pro:tmp regehr$ llc -global-isel reduced.ll 
Assertion failed: (HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry && "Scope imbalance!"), function ~ScopedHashTableScope, file ScopedHashTable.h, line 244.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: llc -global-isel reduced.ll
1.  Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.  Running pass 'Machine Common Subexpression Elimination' on function '@f'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVMSupport.dylib     0x000000010c981594 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  libLLVMSupport.dylib     0x000000010c980418 llvm::sys::RunSignalHandlers() + 112
2  libLLVMSupport.dylib     0x000000010c981c20 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001876742a4 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000187645cec pthread_kill + 288
5  libsystem_c.dylib        0x000000018757e2c8 abort + 180
6  libsystem_c.dylib        0x000000018757d620 err + 0
7  libLLVMCodeGen.dylib     0x000000010d15f780 llvm::ScopedHashTableScope<llvm::MachineInstr*, unsigned int, llvm::MachineInstrExpressionTrait, llvm::RecyclingAllocator<llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>, llvm::ScopedHashTableVal<llvm::MachineInstr*, unsigned int>, 32ul, 8ul>>::~ScopedHashTableScope() + 440
8  libLLVMCodeGen.dylib     0x000000010d15f550 (anonymous namespace)::MachineCSE::ExitScope(llvm::MachineBasicBlock*) + 360
9  libLLVMCodeGen.dylib     0x000000010d15bc5c (anonymous namespace)::MachineCSE::runOnMachineFunction(llvm::MachineFunction&) + 9932
10 libLLVMCodeGen.dylib     0x000000010d194b2c llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 616
11 libLLVMCore.dylib        0x000000010e21e298 llvm::FPPassManager::runOnFunction(llvm::Function&) + 704
12 libLLVMCore.dylib        0x000000010e224fc8 llvm::FPPassManager::runOnModule(llvm::Module&) + 60
13 libLLVMCore.dylib        0x000000010e21e86c llvm::legacy::PassManagerImpl::run(llvm::Module&) + 764
14 llc                      0x0000000104b7d208 compileModule(char**, llvm::LLVMContext&) + 5672
15 llc                      0x0000000104b7b594 main + 1128
16 dyld                     0x000000018731be50 start + 2544
Abort trap: 6
Johns-MacBook-Pro:tmp regehr$ 
llvmbot commented 1 year ago

@llvm/issue-subscribers-backend-aarch64

aemerson commented 1 year ago

Seems we're inserting the G_UDIVREM in the incorrect place, causing a use-before-def.

aemerson commented 1 year ago

Proposed fix https://reviews.llvm.org/D144336