From adf7043a9fbafc35add555b8542a198c1c678cb7 Mon Sep 17 00:00:00 2001 From: Carl Ritson Date: Wed, 6 Oct 2021 09:53:52 +0900 Subject: [PATCH] [AMDGPU] Only remove branches in SIInstrInfo::removeBranch Without this change _term instructions can be removed during critical edge splitting. Reviewed By: foad Differential Revision: https://reviews.llvm.org/D111126 --- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 9 ++++++--- llvm/test/CodeGen/AMDGPU/artificial-terminators.mir | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp index 42c3b6f65c22..d72fbe9b1c57 100644 --- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -2460,9 +2460,12 @@ unsigned SIInstrInfo::removeBranch(MachineBasicBlock &MBB, unsigned RemovedSize = 0; while (I != MBB.end()) { MachineBasicBlock::iterator Next = std::next(I); - RemovedSize += getInstSizeInBytes(*I); - I->eraseFromParent(); - ++Count; + // Skip over artificial terminators when removing instructions. + if (I->isBranch() || I->isReturn()) { + RemovedSize += getInstSizeInBytes(*I); + I->eraseFromParent(); + ++Count; + } I = Next; } diff --git a/llvm/test/CodeGen/AMDGPU/artificial-terminators.mir b/llvm/test/CodeGen/AMDGPU/artificial-terminators.mir index edf0ace463e0..d1075fa9796c 100644 --- a/llvm/test/CodeGen/AMDGPU/artificial-terminators.mir +++ b/llvm/test/CodeGen/AMDGPU/artificial-terminators.mir @@ -38,6 +38,7 @@ body: | ; CHECK-NEXT: {{ $}} ; CHECK-NEXT: [[V_CMP_LT_I32_e64_:%[0-9]+]]:sreg_32 = V_CMP_LT_I32_e64 [[V_ADD_U32_e64_3]], [[S_MOV_B32_1]], implicit $exec ; CHECK-NEXT: [[S_XOR_B32_:%[0-9]+]]:sreg_32 = S_XOR_B32 $exec_lo, [[V_CMP_LT_I32_e64_]], implicit-def $scc + ; CHECK-NEXT: $exec_lo = S_MOV_B32_term [[S_XOR_B32_]] ; CHECK-NEXT: S_CBRANCH_EXECNZ %bb.2, implicit $exec ; CHECK-NEXT: {{ $}} ; CHECK-NEXT: bb.5: