Skip to content

Commit 46ea657

Browse files
committed
[AArch64] Fix the crash for PR79756
this crash is exposes when there is MOVKWi instruction in the head of a block, but without MOVZWi
1 parent 75bd338 commit 46ea657

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,9 @@ bool AArch64LoadStoreOpt::isMatchingMovConstInsn(MachineInstr &MemMI,
22132213
// movz + movk hold a large offset of a Ld/St instruction.
22142214
MachineBasicBlock::iterator B = MI.getParent()->begin();
22152215
MachineBasicBlock::iterator MBBI = &MI;
2216+
// Skip the scene when the MI is the first instruction of a block.
2217+
if (MBBI == B)
2218+
return false;
22162219
MBBI = prev_nodbg(MBBI, B);
22172220
MachineInstr &MovzMI = *MBBI;
22182221
if (MovzMI.getOpcode() == AArch64::MOVZWi) {

llvm/test/CodeGen/AArch64/large-offset-ldr-merge.mir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,23 @@ body: |
4545
renamable $w0 = LDRBBroX killed renamable $x0, renamable $x8, 0, 0
4646
RET undef $lr, implicit $w0
4747
...
48+
49+
# Negative test: No MOVZWi used for the const offset
50+
---
51+
name: LdOffset_missing_MOVZ
52+
tracksRegLiveness: true
53+
liveins:
54+
- { reg: '$x0', virtual-reg: '' }
55+
body: |
56+
bb.0.entry:
57+
liveins: $x0
58+
59+
; CHECK-LABEL: name: LdOffset_missing_MOVZ
60+
; CHECK: liveins: $x0
61+
; CHECK-NEXT: {{ $}}
62+
; CHECK-NEXT: renamable $w8 = MOVKWi $w8, 15, 16, implicit-def $x8
63+
; CHECK-NEXT: renamable $w0 = LDRBBroX killed renamable $x0, killed renamable $x8, 0, 0
64+
; CHECK-NEXT: RET undef $lr, implicit $w0
65+
renamable $w8 = MOVKWi $w8, 15, 16, implicit-def $x8
66+
renamable $w0 = LDRBBroX killed renamable $x0, killed renamable $x8, 0, 0
67+
RET undef $lr, implicit $w0

0 commit comments

Comments
 (0)