[llvm] bc2cb91 - GlobalISel: Have lowerStore handle some unaligned stores
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 31 07:01:57 PDT 2021
Author: Matt Arsenault
Date: 2021-07-31T10:01:42-04:00
New Revision: bc2cb91a20641f9685df1f3fb2ac4ea06756a252
URL: https://github.com/llvm/llvm-project/commit/bc2cb91a20641f9685df1f3fb2ac4ea06756a252
DIFF: https://github.com/llvm/llvm-project/commit/bc2cb91a20641f9685df1f3fb2ac4ea06756a252.diff
LOG: GlobalISel: Have lowerStore handle some unaligned stores
This is NFC until some of the AMDGPU legalization rules are ripped
out.
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 074e5e6920a4..843d6ae3e074 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -3056,18 +3056,34 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerStore(GStore &StoreMI) {
return Legalized;
}
- if (isPowerOf2_32(MemTy.getSizeInBits()))
- return UnableToLegalize; // Don't know what we're being asked to do.
+ unsigned MemSizeInBits = MemTy.getSizeInBits();
+ uint64_t LargeSplitSize, SmallSplitSize;
+
+ if (!isPowerOf2_32(MemSizeInBits)) {
+ LargeSplitSize = PowerOf2Floor(MemTy.getSizeInBits());
+ SmallSplitSize = MemTy.getSizeInBits() - LargeSplitSize;
+ } else {
+ auto &Ctx = MF.getFunction().getContext();
+ if (TLI.allowsMemoryAccess(Ctx, MIRBuilder.getDataLayout(), MemTy, MMO))
+ return UnableToLegalize; // Don't know what we're being asked to do.
+
+ SmallSplitSize = LargeSplitSize = MemSizeInBits / 2;
+ }
// Extend to the next pow-2. If this store was itself the result of lowering,
// e.g. an s56 store being broken into s32 + s24, we might have a stored type
- // that's wider the stored size.
- const LLT NewSrcTy = LLT::scalar(NextPowerOf2(MemTy.getSizeInBits()));
+ // that's wider than the stored size.
+ unsigned AnyExtSize = PowerOf2Ceil(MemTy.getSizeInBits());
+ const LLT NewSrcTy = LLT::scalar(AnyExtSize);
+
+ if (SrcTy.isPointer()) {
+ const LLT IntPtrTy = LLT::scalar(SrcTy.getSizeInBits());
+ SrcReg = MIRBuilder.buildPtrToInt(IntPtrTy, SrcReg).getReg(0);
+ }
+
auto ExtVal = MIRBuilder.buildAnyExtOrTrunc(NewSrcTy, SrcReg);
// Obtain the smaller value by shifting away the larger value.
- uint64_t LargeSplitSize = PowerOf2Floor(MemTy.getSizeInBits());
- uint64_t SmallSplitSize = MemTy.getSizeInBits() - LargeSplitSize;
auto ShiftAmt = MIRBuilder.buildConstant(NewSrcTy, LargeSplitSize);
auto SmallVal = MIRBuilder.buildLShr(NewSrcTy, ExtVal, ShiftAmt);
@@ -3075,9 +3091,8 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerStore(GStore &StoreMI) {
LLT PtrTy = MRI.getType(PtrReg);
auto OffsetCst = MIRBuilder.buildConstant(
LLT::scalar(PtrTy.getSizeInBits()), LargeSplitSize / 8);
- Register PtrAddReg = MRI.createGenericVirtualRegister(PtrTy);
auto SmallPtr =
- MIRBuilder.buildPtrAdd(PtrAddReg, PtrReg, OffsetCst);
+ MIRBuilder.buildPtrAdd(PtrTy, PtrReg, OffsetCst);
MachineMemOperand *LargeMMO =
MF.getMachineMemOperand(&MMO, 0, LargeSplitSize / 8);
More information about the llvm-commits
mailing list