Skip to content

Commit c8a82f1

Browse files
author
git apple-llvm automerger
committed
Merge commit '9e16c5bfae6e' from llvm.org/release/11.x into apple/stable/20200714
2 parents 207b4ea + 9e16c5b commit c8a82f1

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,9 +4907,19 @@ AArch64InstructionSelector::selectExtendedSHL(
49074907
return None;
49084908

49094909
unsigned OffsetOpc = OffsetInst->getOpcode();
4910-
if (OffsetOpc != TargetOpcode::G_SHL && OffsetOpc != TargetOpcode::G_MUL)
4911-
return None;
4910+
bool LookedThroughZExt = false;
4911+
if (OffsetOpc != TargetOpcode::G_SHL && OffsetOpc != TargetOpcode::G_MUL) {
4912+
// Try to look through a ZEXT.
4913+
if (OffsetOpc != TargetOpcode::G_ZEXT || !WantsExt)
4914+
return None;
4915+
4916+
OffsetInst = MRI.getVRegDef(OffsetInst->getOperand(1).getReg());
4917+
OffsetOpc = OffsetInst->getOpcode();
4918+
LookedThroughZExt = true;
49124919

4920+
if (OffsetOpc != TargetOpcode::G_SHL && OffsetOpc != TargetOpcode::G_MUL)
4921+
return None;
4922+
}
49134923
// Make sure that the memory op is a valid size.
49144924
int64_t LegalShiftVal = Log2_32(SizeInBytes);
49154925
if (LegalShiftVal == 0)
@@ -4960,20 +4970,23 @@ AArch64InstructionSelector::selectExtendedSHL(
49604970

49614971
unsigned SignExtend = 0;
49624972
if (WantsExt) {
4963-
// Check if the offset is defined by an extend.
4964-
MachineInstr *ExtInst = getDefIgnoringCopies(OffsetReg, MRI);
4965-
auto Ext = getExtendTypeForInst(*ExtInst, MRI, true);
4966-
if (Ext == AArch64_AM::InvalidShiftExtend)
4967-
return None;
4973+
// Check if the offset is defined by an extend, unless we looked through a
4974+
// G_ZEXT earlier.
4975+
if (!LookedThroughZExt) {
4976+
MachineInstr *ExtInst = getDefIgnoringCopies(OffsetReg, MRI);
4977+
auto Ext = getExtendTypeForInst(*ExtInst, MRI, true);
4978+
if (Ext == AArch64_AM::InvalidShiftExtend)
4979+
return None;
49684980

4969-
SignExtend = isSignExtendShiftType(Ext) ? 1 : 0;
4970-
// We only support SXTW for signed extension here.
4971-
if (SignExtend && Ext != AArch64_AM::SXTW)
4972-
return None;
4981+
SignExtend = isSignExtendShiftType(Ext) ? 1 : 0;
4982+
// We only support SXTW for signed extension here.
4983+
if (SignExtend && Ext != AArch64_AM::SXTW)
4984+
return None;
4985+
OffsetReg = ExtInst->getOperand(1).getReg();
4986+
}
49734987

49744988
// Need a 32-bit wide register here.
49754989
MachineIRBuilder MIB(*MRI.getVRegDef(Root.getReg()));
4976-
OffsetReg = ExtInst->getOperand(1).getReg();
49774990
OffsetReg = narrowExtendRegIfNeeded(OffsetReg, MIB);
49784991
}
49794992

llvm/test/CodeGen/AArch64/GlobalISel/load-wro-addressing-modes.mir

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,39 @@ body: |
428428
$x1 = COPY %load(s64)
429429
RET_ReallyLR implicit $x1
430430
...
431+
---
432+
name: zext_shl_LDRWroW
433+
alignment: 4
434+
legalized: true
435+
regBankSelected: true
436+
tracksRegLiveness: true
437+
liveins:
438+
- { reg: '$w0' }
439+
- { reg: '$x1' }
440+
body: |
441+
bb.1:
442+
liveins: $w0, $x1
443+
444+
; We try to look through the G_ZEXT of the SHL here.
445+
446+
; CHECK-LABEL: name: zext_shl_LDRWroW
447+
; CHECK: liveins: $w0, $x1
448+
; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
449+
; CHECK: [[COPY1:%[0-9]+]]:gpr64sp = COPY $x1
450+
; CHECK: [[ANDWri:%[0-9]+]]:gpr32common = ANDWri [[COPY]], 7
451+
; CHECK: [[LDRWroW:%[0-9]+]]:gpr32 = LDRWroW [[COPY1]], [[ANDWri]], 0, 1 :: (load 4)
452+
; CHECK: $w0 = COPY [[LDRWroW]]
453+
; CHECK: RET_ReallyLR implicit $w0
454+
%0:gpr(s32) = COPY $w0
455+
%1:gpr(p0) = COPY $x1
456+
%2:gpr(s32) = G_CONSTANT i32 255
457+
%3:gpr(s32) = G_AND %0, %2
458+
%13:gpr(s64) = G_CONSTANT i64 2
459+
%12:gpr(s32) = G_SHL %3, %13(s64)
460+
%6:gpr(s64) = G_ZEXT %12(s32)
461+
%7:gpr(p0) = G_PTR_ADD %1, %6(s64)
462+
%9:gpr(s32) = G_LOAD %7(p0) :: (load 4)
463+
$w0 = COPY %9(s32)
464+
RET_ReallyLR implicit $w0
465+
466+
...

0 commit comments

Comments
 (0)