Skip to content

Commit

Permalink
[GlobalISel][Legalizer] Support reducing load/store width in big endi…
Browse files Browse the repository at this point in the history
…an order
  • Loading branch information
0x59616e authored and arsenm committed Feb 8, 2022
1 parent 0fe419f commit 146c782
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Expand Up @@ -4096,13 +4096,14 @@ LegalizerHelper::reduceLoadStoreWidth(GLoadStore &LdStMI, unsigned TypeIdx,
// is a load, return the new registers in ValRegs. For a store, each elements
// of ValRegs should be PartTy. Returns the next offset that needs to be
// handled.
bool isBigEndian = MIRBuilder.getDataLayout().isBigEndian();
auto MMO = LdStMI.getMMO();
auto splitTypePieces = [=](LLT PartTy, SmallVectorImpl<Register> &ValRegs,
unsigned Offset) -> unsigned {
unsigned NumParts, unsigned Offset) -> unsigned {
MachineFunction &MF = MIRBuilder.getMF();
unsigned PartSize = PartTy.getSizeInBits();
for (unsigned Idx = 0, E = NumParts; Idx != E && Offset < TotalSize;
Offset += PartSize, ++Idx) {
++Idx) {
unsigned ByteOffset = Offset / 8;
Register NewAddrReg;

Expand All @@ -4118,16 +4119,19 @@ LegalizerHelper::reduceLoadStoreWidth(GLoadStore &LdStMI, unsigned TypeIdx,
} else {
MIRBuilder.buildStore(ValRegs[Idx], NewAddrReg, *NewMMO);
}
Offset = isBigEndian ? Offset - PartSize : Offset + PartSize;
}

return Offset;
};

unsigned HandledOffset = splitTypePieces(NarrowTy, NarrowRegs, 0);
unsigned Offset = isBigEndian ? TotalSize - NarrowTy.getSizeInBits() : 0;
unsigned HandledOffset =
splitTypePieces(NarrowTy, NarrowRegs, NumParts, Offset);

// Handle the rest of the register if this isn't an even type breakdown.
if (LeftoverTy.isValid())
splitTypePieces(LeftoverTy, NarrowLeftoverRegs, HandledOffset);
splitTypePieces(LeftoverTy, NarrowLeftoverRegs, NumLeftover, HandledOffset);

if (IsLoad) {
insertParts(ValReg, ValTy, NarrowTy, NarrowRegs,
Expand Down
12 changes: 6 additions & 6 deletions llvm/test/CodeGen/M68k/GlobalISel/legalize-load-store.mir
Expand Up @@ -78,16 +78,16 @@ body: |
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 3
; CHECK-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
; CHECK-NEXT: G_STORE [[C]](s32), [[LOAD]](p0) :: (store (s32), align 16)
; CHECK-NEXT: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
; CHECK-NEXT: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
; CHECK-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[LOAD]], [[C4]](s32)
; CHECK-NEXT: G_STORE [[C1]](s32), [[PTR_ADD]](p0) :: (store (s32) into unknown-address + 4)
; CHECK-NEXT: G_STORE [[C]](s32), [[PTR_ADD]](p0) :: (store (s32) into unknown-address + 12)
; CHECK-NEXT: [[C5:%[0-9]+]]:_(s32) = G_CONSTANT i32 8
; CHECK-NEXT: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[LOAD]], [[C5]](s32)
; CHECK-NEXT: G_STORE [[C2]](s32), [[PTR_ADD1]](p0) :: (store (s32) into unknown-address + 8, align 8)
; CHECK-NEXT: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 12
; CHECK-NEXT: G_STORE [[C1]](s32), [[PTR_ADD1]](p0) :: (store (s32) into unknown-address + 8, align 8)
; CHECK-NEXT: [[C6:%[0-9]+]]:_(s32) = G_CONSTANT i32 4
; CHECK-NEXT: [[PTR_ADD2:%[0-9]+]]:_(p0) = G_PTR_ADD [[LOAD]], [[C6]](s32)
; CHECK-NEXT: G_STORE [[C3]](s32), [[PTR_ADD2]](p0) :: (store (s32) into unknown-address + 12)
; CHECK-NEXT: G_STORE [[C2]](s32), [[PTR_ADD2]](p0) :: (store (s32) into unknown-address + 4)
; CHECK-NEXT: G_STORE [[C3]](s32), [[LOAD]](p0) :: (store (s32), align 16)
; CHECK-NEXT: RTS
%1:_(p0) = G_FRAME_INDEX %fixed-stack.0
%0:_(p0) = G_LOAD %1(p0) :: (load (p0) from %fixed-stack.0, align 8)
Expand Down

0 comments on commit 146c782

Please sign in to comment.