llvm-project/llvm/lib/CodeGen/SelectionDAG
Nick Desaulniers 5bc291be71 [SelectionDAG] fix predecessor list for INLINEASM_BRs' parent
Summary:
A bug report mentioned that LLVM was producing jumps off the end of a
function when using "asm goto with outputs". Further digging pointed to
MachineBasicBlocks that had their address taken and were indirect
targets of INLINEASM_BR being removed by BranchFolder, because their
 predecessor list was empty, so they appeared to have no entry.

This was a cascading failure caused earlier, during Pre-RA instruction
scheduling. We have a few special cases in Pre-RA instruction scheduling
where we split a MachineBasicBlock in two.  This requires careful
handing of predecessor and successor lists for a MachineBasicBlock that
was split, and careful handing of PHI MachineInstrs that referred to the
MachineBasicBlock before it was split.

The clue that led to this fix was the observation that many callers of
MachineBasicBlock::splice() frequently call
MachineBasicBlock::transferSuccessorsAndUpdatePHIs() to update their PHI
nodes after a splice. We don't want to reuse that method, as we have
custom successor transferring logic for this block split.

This patch fixes 2 pre-existing bugs, and adds tests.

The first bug was that MachineBasicBlock::splice() correctly handles
updating most successors and predecessors; we don't need to do anything
more than removing the previous fallthrough block from the first half of
the split block post splice. Previously, we were updating the successor
list incorrectly (updating successors updates predecessors).

The second bug was that PHI nodes that needed registers from the first
half of the split block were not having entries populated.  The register
live out information was correct, and the FuncInfo->PHINodesToUpdate was
correct. Specifically, the check in SelectionDAGISel::FinishBasicBlock:

    for (unsigned i = 0, e = FuncInfo->PHINodesToUpdate.size(); i != e; ++i) {
      MachineInstrBuilder PHI(*MF, FuncInfo->PHINodesToUpdate[i].first);
      if (!FuncInfo->MBB->isSuccessor(PHI->getParent()))
        continue;
      PHI.addReg(FuncInfo->PHINodesToUpdate[i].second).addMBB(FuncInfo->MBB);

was `continue`ing because FuncInfo->MBB tracks the second half of
the post-split block; no one was updating PHI entries for the first half
of the post-split block.

SelectionDAGBuilder::UpdateSplitBlock() already expects to perform
special handling for MachineBasicBlocks that were split post calls to
ScheduleDAGSDNodes::EmitSchedule(), so I'm confident that it's both
correct for ScheduleDAGSDNodes::EmitSchedule() to return the second half
of the split block `CopyBB` which updates `FuncInfo->MBB` (ie. the
current MachineBasicBlock being processed), and perform special handling
for this in SelectionDAGBuilder::UpdateSplitBlock().

Reviewers: void, craig.topper, efriedma

Reviewed By: void, efriedma

Subscribers: hfinkel, fhahn, MatzeB, efriedma, hiraditya, llvm-commits, srhines

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D76961
2020-04-06 13:46:39 -07:00
..
CMakeLists.txt [cmake] Explicitly mark libraries defined in lib/ as "Component Libraries" 2019-11-21 10:48:08 -08:00
DAGCombiner.cpp DAG: Combine extract_vector_elt of concat_vectors 2020-04-06 09:26:29 -04:00
FastISel.cpp [Alignment][NFC] Deprecate InstrTypes getRetAlignment/getParamAlignment 2020-04-03 13:21:58 +00:00
FunctionLoweringInfo.cpp [Alignment][NFC] Use TFL::getStackAlign() 2020-03-23 13:48:29 +01:00
InstrEmitter.cpp CodeGen: Convert some TII hooks to use Register 2020-04-03 14:52:54 -04:00
InstrEmitter.h [SelectionDAG] Enhance the simplification of `copyto` from `implicit-def`. 2019-05-27 18:26:29 +00:00
LLVMBuild.txt
LegalizeDAG.cpp No longer generate calls to *_finite 2020-02-28 10:07:37 +01:00
LegalizeFloatTypes.cpp [LegalizeTypes] Add SoftenFloatRes_FREEZE 2020-03-31 10:16:38 +09:00
LegalizeIntegerTypes.cpp [LegalizeTypes][RISCV] Correctly sign-extend comparison for ATOMIC_CMP_XCHG 2020-04-01 15:51:26 +01:00
LegalizeTypes.cpp Revert "[DAG] Fix PR45049: LegalizeTypes crash" 2020-04-04 13:47:22 -06:00
LegalizeTypes.h Revert "[DAG] Fix PR45049: LegalizeTypes crash" 2020-04-04 13:47:22 -06:00
LegalizeTypesGeneric.cpp [SelDag] Add FREEZE 2020-03-24 23:04:58 +09:00
LegalizeVectorOps.cpp [SDAG] Add SDNode::values() = make_range(values_begin(), values_end()) 2020-02-26 12:07:38 -06:00
LegalizeVectorTypes.cpp [Alignment][NFC] Transitionning more getMachineMemOperand call sites 2020-03-31 11:04:10 +00:00
ResourcePriorityQueue.cpp
SDNodeDbgValue.h
ScheduleDAGFast.cpp Finish moving TargetRegisterInfo::isVirtualRegister() and friends to llvm::Register as started by r367614. NFC 2019-08-01 23:27:28 +00:00
ScheduleDAGRRList.cpp [ScheduleDAG] When a node is cloned, add an edge between the nodes. 2019-10-04 19:51:40 +00:00
ScheduleDAGSDNodes.cpp [SelectionDAG] fix predecessor list for INLINEASM_BRs' parent 2020-04-06 13:46:39 -07:00
ScheduleDAGSDNodes.h Prune Analysis includes from SelectionDAG.h 2019-10-19 01:07:48 +00:00
ScheduleDAGVLIW.cpp Prune Analysis includes from SelectionDAG.h 2019-10-19 01:07:48 +00:00
SelectionDAG.cpp Fix "result of 32-bit shift implicitly converted to 64 bits" MSVC warning. NFCI. 2020-04-02 12:02:04 +01:00
SelectionDAGAddressAnalysis.cpp Prune a LegacyDivergenceAnalysis and MachineLoopInfo include each 2019-10-19 01:31:09 +00:00
SelectionDAGBuilder.cpp [SelectionDAG] fix predecessor list for INLINEASM_BRs' parent 2020-04-06 13:46:39 -07:00
SelectionDAGBuilder.h [FPEnv] Fix chain handling regression after 04a8696 2020-01-14 14:10:57 +01:00
SelectionDAGDumper.cpp [X86] Move combineLoopMAddPattern and combineLoopSADPattern to an IR pass before SelecitonDAG. 2020-03-26 14:10:20 -07:00
SelectionDAGISel.cpp [Alignment][NFC] Transition to MachineFrameInfo::getObjectAlign() 2020-04-01 14:08:28 +00:00
SelectionDAGPrinter.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
SelectionDAGTargetInfo.cpp
StatepointLowering.cpp Remove the additional constant which requires an extra register for statepoint lowering. 2020-04-05 11:22:09 -04:00
StatepointLowering.h [FastISel] Fix crash for gc.relocate lowring 2019-04-05 05:41:08 +00:00
TargetLowering.cpp [Alignment][NFC] Deprecate InstrTypes getRetAlignment/getParamAlignment 2020-04-03 13:21:58 +00:00