Skip to content

Commit

Permalink
[AArch64] Fix the crash for PR79756
Browse files Browse the repository at this point in the history
this crash is exposes when there is MOVKWi instruction in the head of a block,
but without MOVZWi
  • Loading branch information
vfdff committed Jan 30, 2024
1 parent 75bd338 commit 46ea657
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,9 @@ bool AArch64LoadStoreOpt::isMatchingMovConstInsn(MachineInstr &MemMI,
// movz + movk hold a large offset of a Ld/St instruction.
MachineBasicBlock::iterator B = MI.getParent()->begin();
MachineBasicBlock::iterator MBBI = &MI;
// Skip the scene when the MI is the first instruction of a block.
if (MBBI == B)
return false;
MBBI = prev_nodbg(MBBI, B);
MachineInstr &MovzMI = *MBBI;
if (MovzMI.getOpcode() == AArch64::MOVZWi) {
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/AArch64/large-offset-ldr-merge.mir
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ body: |
renamable $w0 = LDRBBroX killed renamable $x0, renamable $x8, 0, 0
RET undef $lr, implicit $w0
...

# Negative test: No MOVZWi used for the const offset
---
name: LdOffset_missing_MOVZ
tracksRegLiveness: true
liveins:
- { reg: '$x0', virtual-reg: '' }
body: |
bb.0.entry:
liveins: $x0
; CHECK-LABEL: name: LdOffset_missing_MOVZ
; CHECK: liveins: $x0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: renamable $w8 = MOVKWi $w8, 15, 16, implicit-def $x8
; CHECK-NEXT: renamable $w0 = LDRBBroX killed renamable $x0, killed renamable $x8, 0, 0
; CHECK-NEXT: RET undef $lr, implicit $w0
renamable $w8 = MOVKWi $w8, 15, 16, implicit-def $x8
renamable $w0 = LDRBBroX killed renamable $x0, killed renamable $x8, 0, 0
RET undef $lr, implicit $w0

0 comments on commit 46ea657

Please sign in to comment.