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

[regression] Assertion `(I.atEnd() || std::next(I) == def_instr_end()) && "getVRegDef assumes a single definition or no definition"' failed #28079

Closed
llvmbot opened this issue May 10, 2016 · 9 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla llvm:codegen

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented May 10, 2016

Bugzilla Link 27705
Resolution FIXED
Resolved on May 21, 2016 10:31
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @MatzeB

Extended Description

Compiling https://gist.github.com/vedranmiletic/3a836854abdf13c60db4 like

$ llc -march=amdgcn -mcpu=bonaire < gmx-OpenCL-kernel-AMD.ll

gives

; Kernel info:
; codeLenInByte = 76
; NumSgprs: 14
; NumVgprs: 4
; FloatMode: 192
; IeeeMode: 0
; ScratchSize: 0
; LDSByteSize: 0 bytes/workgroup (compile time only)
; ReservedVGPRFirst: 0
; ReservedVGPRCount: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 2
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
llc: /home/vedranm/workspace/llvm/lib/CodeGen/MachineRegisterInfo.cpp:339: llvm::MachineInstr* llvm::MachineRegisterInfo::getVRegDef(unsigned int) const: Assertion `(I.atEnd() || std::next(I) == def_instr_end()) && "getVRegDef assumes a single definition or no definition"' failed.
#​0 0x00007ff7d25d97c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/vedranm/workspace/llvm/lib/Support/Unix/Signals.inc:322:0
#​1 0x00007ff7d25d9b3f PrintStackTraceSignalHandler(void*) /home/vedranm/workspace/llvm/lib/Support/Unix/Signals.inc:380:0
#​2 0x00007ff7d25d82a8 llvm::sys::RunSignalHandlers() /home/vedranm/workspace/llvm/lib/Support/Signals.cpp:44:0
#​3 0x00007ff7d25d92ca SignalHandler(int) /home/vedranm/workspace/llvm/lib/Support/Unix/Signals.inc:210:0
#​4 0x00007ff7d0fdc180 __restore_rt (/lib64/libc.so.6+0x36180)
#​5 0x00007ff7d0fdc0f8 __GI_raise (/lib64/libc.so.6+0x360f8)
#​6 0x00007ff7d0fddd0a __GI_abort (/lib64/libc.so.6+0x37d0a)
#​7 0x00007ff7d0fd4967 __assert_fail_base (/lib64/libc.so.6+0x2e967)
#​8 0x00007ff7d0fd4a12 (/lib64/libc.so.6+0x2ea12)
#​9 0x00007ff7d4c6568f llvm::MachineRegisterInfo::getVRegDef(unsigned int) const /home/vedranm/workspace/llvm/lib/CodeGen/MachineRegisterInfo.cpp:338:0
#​10 0x00007ff7d4cad20d (anonymous namespace)::MachineVerifier::visitMachineFunctionAfter() /home/vedranm/workspace/llvm/lib/CodeGen/MachineVerifier.cpp:1518:0
#​11 0x00007ff7d4ca73b9 (anonymous namespace)::MachineVerifier::verify(llvm::MachineFunction&) /home/vedranm/workspace/llvm/lib/CodeGen/MachineVerifier.cpp:412:0
#​12 0x00007ff7d4ca6bb5 llvm::MachineFunction::verify(llvm::Pass*, char const*, bool) const /home/vedranm/workspace/llvm/lib/CodeGen/MachineVerifier.cpp:292:0
#​13 0x00007ff7d4b96b6c llvm::LiveRangeCalc::findReachingDefs(llvm::LiveRange&, llvm::MachineBasicBlock&, llvm::SlotIndex, unsigned int) /home/vedranm/workspace/llvm/lib/CodeGen/LiveRangeCalc.cpp:292:0
#​14 0x00007ff7d4b96930 llvm::LiveRangeCalc::extend(llvm::LiveRange&, llvm::SlotIndex, unsigned int) /home/vedranm/workspace/llvm/lib/CodeGen/LiveRangeCalc.cpp:255:0
#​15 0x00007ff7d4b9656b llvm::LiveRangeCalc::extendToUses(llvm::LiveRange&, unsigned int, unsigned int) /home/vedranm/workspace/llvm/lib/CodeGen/LiveRangeCalc.cpp:208:0
#​16 0x00007ff7d4b7a659 llvm::LiveRangeCalc::extendToUses(llvm::LiveRange&, unsigned int) /home/vedranm/workspace/llvm/lib/CodeGen/LiveRangeCalc.h:185:0
#​17 0x00007ff7d4b961ca llvm::LiveRangeCalc::constructMainRangeFromSubranges(llvm::LiveInterval&) /home/vedranm/workspace/llvm/lib/CodeGen/LiveRangeCalc.cpp:145:0
#​18 0x00007ff7d4b79c9a llvm::LiveIntervals::constructMainRangeFromSubranges(llvm::LiveInterval&) /home/vedranm/workspace/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1593:0
#​19 0x00007ff7d4b87e2f llvm::ConnectedSubRegClasses::computeMainRangesFixFlags(llvm::IntEqClasses const&, llvm::SmallVectorImplllvm::ConnectedSubRegClasses::SubRangeInfo const&, llvm::SmallVectorImplllvm::LiveInterval* const&) const /home/vedranm/workspace/llvm/lib/CodeGen/LiveInterval.cpp:1436:0
#​20 0x00007ff7d4b86c6d llvm::ConnectedSubRegClasses::renameComponents(llvm::LiveInterval&) const /home/vedranm/workspace/llvm/lib/CodeGen/LiveInterval.cpp:1289:0
#​21 0x00007ff7d4b79be7 llvm::LiveIntervals::renameDisconnectedComponents() /home/vedranm/workspace/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1585:0
#​22 0x00007ff7d4c6bada llvm::ScheduleDAGMILive::enterRegion(llvm::MachineBasicBlock*, llvm::MachineInstrBundleIteratorllvm::MachineInstr, llvm::MachineInstrBundleIteratorllvm::MachineInstr, unsigned int) /home/vedranm/workspace/llvm/lib/CodeGen/MachineScheduler.cpp:900:0
#​23 0x00007ff7d4c69c51 (anonymous namespace)::MachineSchedulerBase::scheduleRegions(llvm::ScheduleDAGInstrs&, bool) /home/vedranm/workspace/llvm/lib/CodeGen/MachineScheduler.cpp:474:0
#​24 0x00007ff7d4c69348 (anonymous namespace)::MachineScheduler::runOnMachineFunction(llvm::MachineFunction&) /home/vedranm/workspace/llvm/lib/CodeGen/MachineScheduler.cpp:359:0
#​25 0x00007ff7d4c16cac llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/vedranm/workspace/llvm/lib/CodeGen/MachineFunctionPass.cpp:60:0
#​26 0x00007ff7d4225159 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/vedranm/workspace/llvm/lib/IR/LegacyPassManager.cpp:1526:0
#​27 0x00007ff7d42252d0 llvm::FPPassManager::runOnModule(llvm::Module&) /home/vedranm/workspace/llvm/lib/IR/LegacyPassManager.cpp:1547:0
#​28 0x00007ff7d422561d (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/vedranm/workspace/llvm/lib/IR/LegacyPassManager.cpp:1603:0
#​29 0x00007ff7d4225cd1 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/vedranm/workspace/llvm/lib/IR/LegacyPassManager.cpp:1706:0
#​30 0x00007ff7d4225ec9 llvm::legacy::PassManager::run(llvm::Module&) /home/vedranm/workspace/llvm/lib/IR/LegacyPassManager.cpp:1738:0
#​31 0x000000000041d8da compileModule(char**, llvm::LLVMContext&) /home/vedranm/workspace/llvm/tools/llc/llc.cpp:445:0
#​32 0x000000000041c3f1 main /home/vedranm/workspace/llvm/tools/llc/llc.cpp:221:0
#​33 0x00007ff7d0fc6721 __libc_start_main (/lib64/libc.so.6+0x20721)
#​34 0x000000000041ac09 _start (/home/vedranm/workspace/llvm/build/bin/llc+0x41ac09)
Stack dump:
0. Program arguments: ./bin/llc -march=amdgcn -mcpu=bonaire

  1. Running pass 'Function Pass Manager' on module ''.
  2. Running pass 'Machine Instruction Scheduler' on function '@nbnxn_kernel_ElecEw_VdwLJ_F_opencl'
    Aborted (core dumped)

The revision which broke this is:

commit e607e01
Author: Matthias Braun matze@braunis.de
Date: Tue May 10 04:51:14 2016 +0000

LiveIntervalAnalysis: Rework constructMainRangeFromSubranges()

We now use LiveRangeCalc::extendToUses() instead of a specially designed
algorithm in constructMainRangeFromSubranges():
- The original motivation for constructMainRangeFromSubranges() were
  differences between the main liverange and subranges because of hidden
  dead definitions. This case however cannot happen anymore with the
  DetectDeadLaneMasks pass in place.
- It simplifies the code.
- This fixes a longstanding bug where we did not properly create new SSA
  values on merging control flow (the MachineVerifier missed most of
  these cases).
- Move constructMainRangeFromSubranges() to LiveIntervalAnalysis and
  LiveRangeCalc to better match the implementation/available helper
  functions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269016 91177308-0d34-0410-b5e6-96231b3b80d8
@llvmbot
Copy link
Collaborator Author

llvmbot commented May 10, 2016

assigned to @MatzeB

@MatzeB
Copy link
Contributor

MatzeB commented May 11, 2016

reduced

@MatzeB
Copy link
Contributor

MatzeB commented May 11, 2016

  • Just uploaded a bugpoint reduced version of the problem.

  • The assert itself is a bug in the MachineVerifier error reporting code which I fixed in r269239. That lets it report the error without crashing, it is not a fix for the error yet.

  • The actual problem switching constructMainRangeFromSubranges() to use liveness computation logic. Liveness computation expects to find a definition for every value (the definition may be an IMPLICIT_DEF instruction). With subregister assignments we can construct cases where removing copies in the register coalescer makes values undefined on some paths in the program. These values were previously part of a bigger register with other lanes being valid so it wasn't obvious that the subregister is undefined and lacks a definition on a path.

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 12, 2016

  • The assert itself is a bug in the MachineVerifier error reporting code
    which I fixed in r269239. That lets it report the error without crashing, it
    is not a fix for the error yet.

Thanks, looks much nicer now.

  • The actual problem switching constructMainRangeFromSubranges() to use
    liveness computation logic. Liveness computation expects to find a
    definition for every value (the definition may be an IMPLICIT_DEF
    instruction). With subregister assignments we can construct cases where
    removing copies in the register coalescer makes values undefined on some
    paths in the program. These values were previously part of a bigger register
    with other lanes being valid so it wasn't obvious that the subregister is
    undefined and lacks a definition on a path.

So, if I am reading this correctly, the r269016 patch actually uncovered the bug that was already there before but unnoticed?

@MatzeB
Copy link
Contributor

MatzeB commented May 12, 2016

So, if I am reading this correctly, the r269016 patch actually uncovered the bug that was already there before but unnoticed?

While recomputing live ranges does indeed fail because of the pre-existing problem. I believe this was not a problem before because we only computed liveness when coming fresh out of SSA form which mostly a single def per register and all phi inputs having copies in their predecessors. These copies had undef inputs as necessary so there was no problem. The problem only happens after the register coalescer removes some of the useless copies which unfortunately also removes the knowledge about which lanes are undefined at those places. With this patch constructMainRangeFromSubranges() performs liveness calculation after register coalescing which exposed the issues.

I will be on vacation for a week starting tomorrow. I will look into the issue after that. If you are blocked feel free to revert r269016 in the meantime.

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 15, 2016

Matthias, for I am not getting this error anymore on latest LLVM git. I can bisect if you would like to know what fixed it.

@MatzeB
Copy link
Contributor

MatzeB commented May 19, 2016

The commit was reverted in r269344 (thanks Tom) until I have a fix for the problem. That's why you are not seeing the problem anymore right now. This ticket should stay open.

@MatzeB
Copy link
Contributor

MatzeB commented May 21, 2016

Fixed in r270259, r270290. Reapplied the original patch in r270291.

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 21, 2016

Fixed in r270259, r270290. Reapplied the original patch in r270291.

Thanks, it works!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:codegen
Projects
None yet
Development

No branches or pull requests

2 participants