Index: llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -3056,18 +3056,33 @@ 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. + const LLT NewSrcTy = LLT::scalar(NextPowerOf2(MemSizeInBits)); + + 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 +3090,8 @@ 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);