[AMDGPU] SILowerControlFlow::optimizeEndCF should remove empty basic block
authoralex-t <alexander.timofeev@amd.com>
Mon, 7 Sep 2020 15:57:27 +0000 (18:57 +0300)
committeralex-t <alexander.timofeev@amd.com>
Mon, 7 Sep 2020 16:37:27 +0000 (19:37 +0300)
commit2480a31e5d69a5c2e8e900be3a7f706d77f5a5cc
tree949b9e217960f2f2ad5221e3b67d7ba560e40a42
parenteb482afaf5bbf3abf9d02c3810e418945c68a936
[AMDGPU] SILowerControlFlow::optimizeEndCF should remove empty basic block

optimizeEndCF removes EXEC restoring instruction case this instruction is the only one except the branch to the single successor and that successor contains EXEC mask restoring instruction that was lowered from END_CF belonging to IF_ELSE.
As a result of such optimization we get the basic block with the only one instruction that is a branch to the single successor.
In case the control flow can reach such an empty block from S_CBRANCH_EXEZ/EXECNZ it might happen that spill/reload instructions that were inserted later by register allocator are placed under exec == 0 condition and never execute.
Removing empty block solves the problem.

This change require further work to re-implement LIS updates. Recently, LIS is always nullptr in this pass. To enable it we need another patch to fix many places across the codegen.

Reviewed By: rampitec

Differential Revision: https://reviews.llvm.org/D86634
llvm/lib/Target/AMDGPU/SILowerControlFlow.cpp
llvm/test/CodeGen/AMDGPU/collapse-endcf.mir