[CodeGen] Fix partial phi input removal in TailDuplicator. #158265
Merged
+8
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tail duplicator removes the first PHI income from the predecessor basic block, while it should remove all operands for this block.
PHI instructions happen to have duplicated values for the same predecessor block:
UnreachableMachineBlockElimassumes that PHI instruction might have duplicates:llvm-project/llvm/lib/CodeGen/UnreachableBlockElim.cpp
Line 160 in 7289f2c
AArch64directly states that PHI instruction might have duplicates:llvm-project/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
Line 244 in 7289f2c
Hexagon:llvm-project/llvm/lib/Target/Hexagon/HexagonConstPropagation.cpp
Line 844 in 7289f2c
We have caught the bug on custom out-of-tree backend.
TailDuplicatorshould remove all operands corresponding to the removing block.Please note, that bug likely does not affect in-tree backends, because:
early-tailduplicationpass which declines partial tail duplication viacanCompletelyDuplicateBBcheck, because it usesTailDuplicator::tailDuplicateBlockspublic API.So, bug happens only in the case of pre-ra partial tail duplication if backend uses
TailDuplicator::tailDuplicatepublic API directly.That's why I can not add reproducer test for in-tree backends.