Skip to content

Commit e70e334

Browse files
committed
[InitUndef] handleSubReg should skip artificial subregs.
When enabling subreg liveness tracking for AArch64, this pass fails because it tries to get the register class for the artificial subreg `sub_32_hi` of a 64-bit GPR. It tries to create an INIT_UNDEF instruction for the top 32-bits of the 64-bit GPR, which are not directly addressable, so getSubRegisterClass() returns a nullptr, crashing this pass. It should instead just avoid trying to create the INIT_UNDEF instruction.
1 parent 576865a commit e70e334

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

llvm/lib/CodeGen/InitUndef.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ bool InitUndef::handleSubReg(MachineFunction &MF, MachineInstr &MI,
164164
TRI->getCoveringSubRegIndexes(*MRI, TargetRegClass, NeedDef,
165165
SubRegIndexNeedInsert);
166166

167+
// It's not possible to create the INIT_UNDEF when there is no register
168+
// class associated for the subreg. This may happen for artificial subregs
169+
// that are not directly addressable.
170+
if (any_of(SubRegIndexNeedInsert,
171+
[&TRI = TRI, &TargetRegClass](unsigned ind) -> bool {
172+
return !TRI->getSubRegisterClass(TargetRegClass, ind);
173+
}))
174+
continue;
175+
167176
Register LatestReg = Reg;
168177
for (auto ind : SubRegIndexNeedInsert) {
169178
Changed = true;

llvm/test/CodeGen/AArch64/init-undef.mir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2-
# RUN: llc -mtriple=aarch64-- -run-pass=init-undef -o - %s | FileCheck %s
2+
# RUN: llc -mtriple=aarch64-- -aarch64-enable-subreg-liveness-tracking=false -run-pass=init-undef -o - %s | FileCheck %s
3+
# RUN: llc -mtriple=aarch64-- -aarch64-enable-subreg-liveness-tracking=true -run-pass=init-undef -o - %s | FileCheck %s
34

45
---
56
name: test_stxp_undef

0 commit comments

Comments
 (0)