Skip to content

Commit

Permalink
[InitUndef] handleSubReg should skip artificial subregs. (#116248)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sdesmalen-arm authored Nov 14, 2024
1 parent d133a3e commit be15fd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions llvm/lib/CodeGen/InitUndef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ bool InitUndef::handleSubReg(MachineFunction &MF, MachineInstr &MI,
TRI->getCoveringSubRegIndexes(*MRI, TargetRegClass, NeedDef,
SubRegIndexNeedInsert);

// It's not possible to create the INIT_UNDEF when there is no register
// class associated for the subreg. This may happen for artificial subregs
// that are not directly addressable.
if (any_of(SubRegIndexNeedInsert, [&](unsigned Ind) -> bool {
return !TRI->getSubRegisterClass(TargetRegClass, Ind);
}))
continue;

Register LatestReg = Reg;
for (auto ind : SubRegIndexNeedInsert) {
Changed = true;
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/AArch64/init-undef.mir
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
# RUN: llc -mtriple=aarch64-- -run-pass=init-undef -o - %s | FileCheck %s
# RUN: llc -mtriple=aarch64-- -aarch64-enable-subreg-liveness-tracking=false -run-pass=init-undef -o - %s | FileCheck %s
# RUN: llc -mtriple=aarch64-- -aarch64-enable-subreg-liveness-tracking=true -run-pass=init-undef -o - %s | FileCheck %s

---
name: test_stxp_undef
Expand Down

0 comments on commit be15fd5

Please sign in to comment.