Skip to content

Commit 4e0648a

Browse files
committed
[TargetLowering] Add MachineMemOperand::Flags to allowsMemoryAccess tests (PR42123)
As discussed on D62910, we need to check whether particular types of memory access are allowed, not just their alignment/address-space. This NFC patch adds a MachineMemOperand::Flags argument to allowsMemoryAccess and allowsMisalignedMemoryAccesses, and wires up calls to pass the relevant flags to them. If people are happy with this approach I can then update X86TargetLowering::allowsMisalignedMemoryAccesses to handle misaligned NT load/stores. Differential Revision: https://reviews.llvm.org/D63075 llvm-svn: 363179
1 parent 5b0e0dd commit 4e0648a

28 files changed

+91
-76
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
196196
public:
197197
/// \name Scalar TTI Implementations
198198
/// @{
199-
bool allowsMisalignedMemoryAccesses(LLVMContext &Context,
200-
unsigned BitWidth, unsigned AddressSpace,
201-
unsigned Alignment, bool *Fast) const {
199+
bool allowsMisalignedMemoryAccesses(LLVMContext &Context, unsigned BitWidth,
200+
unsigned AddressSpace, unsigned Alignment,
201+
bool *Fast) const {
202202
EVT E = EVT::getIntegerVT(Context, BitWidth);
203-
return getTLI()->allowsMisalignedMemoryAccesses(E, AddressSpace, Alignment, Fast);
203+
return getTLI()->allowsMisalignedMemoryAccesses(
204+
E, AddressSpace, Alignment, MachineMemOperand::MONone, Fast);
204205
}
205206

206207
bool hasBranchDivergence() { return false; }

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,20 +1415,22 @@ class TargetLoweringBase {
14151415
/// copy/move/set is converted to a sequence of store operations. Its use
14161416
/// helps to ensure that such replacements don't generate code that causes an
14171417
/// alignment error (trap) on the target machine.
1418-
virtual bool allowsMisalignedMemoryAccesses(EVT,
1419-
unsigned AddrSpace = 0,
1420-
unsigned Align = 1,
1421-
bool * /*Fast*/ = nullptr) const {
1418+
virtual bool allowsMisalignedMemoryAccesses(
1419+
EVT, unsigned AddrSpace = 0, unsigned Align = 1,
1420+
MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
1421+
bool * /*Fast*/ = nullptr) const {
14221422
return false;
14231423
}
14241424

14251425
/// Return true if the target supports a memory access of this type for the
14261426
/// given address space and alignment. If the access is allowed, the optional
14271427
/// final parameter returns if the access is also fast (as defined by the
14281428
/// target).
1429-
bool allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT,
1430-
unsigned AddrSpace = 0, unsigned Alignment = 1,
1431-
bool *Fast = nullptr) const;
1429+
bool
1430+
allowsMemoryAccess(LLVMContext &Context, const DataLayout &DL, EVT VT,
1431+
unsigned AddrSpace = 0, unsigned Alignment = 1,
1432+
MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
1433+
bool *Fast = nullptr) const;
14321434

14331435
/// Return true if the target supports a memory access of this type for the
14341436
/// given MachineMemOperand. If the access is allowed, the optional

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4638,7 +4638,8 @@ bool DAGCombiner::isLegalNarrowLdSt(LSBaseSDNode *LDST,
46384638
// Ensure that this isn't going to produce an unsupported unaligned access.
46394639
if (ShAmt &&
46404640
!TLI.allowsMemoryAccess(*DAG.getContext(), DAG.getDataLayout(), MemVT,
4641-
LDST->getAddressSpace(), ShAmt / 8))
4641+
LDST->getAddressSpace(), ShAmt / 8,
4642+
LDST->getMemOperand()->getFlags()))
46424643
return false;
46434644

46444645
// It's not possible to generate a constant of extended or untyped type.

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ TargetLowering::findOptimalMemOpLowering(std::vector<EVT> &MemOps,
238238
// issuing a (or a pair of) unaligned and overlapping load / store.
239239
bool Fast;
240240
if (NumMemOps && AllowOverlap && NewVTSize < Size &&
241-
allowsMisalignedMemoryAccesses(VT, DstAS, DstAlign, &Fast) &&
241+
allowsMisalignedMemoryAccesses(VT, DstAS, DstAlign,
242+
MachineMemOperand::MONone, &Fast) &&
242243
Fast)
243244
VTSize = Size;
244245
else {

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ bool TargetLoweringBase::allowsMemoryAccess(LLVMContext &Context,
14641464
const DataLayout &DL, EVT VT,
14651465
unsigned AddrSpace,
14661466
unsigned Alignment,
1467+
MachineMemOperand::Flags Flags,
14671468
bool *Fast) const {
14681469
// Check if the specified alignment is sufficient based on the data layout.
14691470
// TODO: While using the data layout works in practice, a better solution
@@ -1479,15 +1480,15 @@ bool TargetLoweringBase::allowsMemoryAccess(LLVMContext &Context,
14791480
}
14801481

14811482
// This is a misaligned access.
1482-
return allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Fast);
1483+
return allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment, Flags, Fast);
14831484
}
14841485

14851486
bool TargetLoweringBase::allowsMemoryAccess(LLVMContext &Context,
14861487
const DataLayout &DL, EVT VT,
14871488
const MachineMemOperand &MMO,
14881489
bool *Fast) const {
14891490
return allowsMemoryAccess(Context, DL, VT, MMO.getAddrSpace(),
1490-
MMO.getAlignment(), Fast);
1491+
MMO.getAlignment(), MMO.getFlags(), Fast);
14911492
}
14921493

14931494
BranchProbability TargetLoweringBase::getPredictableBranchThreshold() const {

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,10 +1074,9 @@ MVT AArch64TargetLowering::getScalarShiftAmountTy(const DataLayout &DL,
10741074
return MVT::i64;
10751075
}
10761076

1077-
bool AArch64TargetLowering::allowsMisalignedMemoryAccesses(EVT VT,
1078-
unsigned AddrSpace,
1079-
unsigned Align,
1080-
bool *Fast) const {
1077+
bool AArch64TargetLowering::allowsMisalignedMemoryAccesses(
1078+
EVT VT, unsigned AddrSpace, unsigned Align, MachineMemOperand::Flags Flags,
1079+
bool *Fast) const {
10811080
if (Subtarget->requiresStrictAlign())
10821081
return false;
10831082

@@ -2843,7 +2842,8 @@ SDValue AArch64TargetLowering::LowerSTORE(SDValue Op,
28432842
unsigned AS = StoreNode->getAddressSpace();
28442843
unsigned Align = StoreNode->getAlignment();
28452844
if (Align < MemVT.getStoreSize() &&
2846-
!allowsMisalignedMemoryAccesses(MemVT, AS, Align, nullptr)) {
2845+
!allowsMisalignedMemoryAccesses(
2846+
MemVT, AS, Align, StoreNode->getMemOperand()->getFlags(), nullptr)) {
28472847
return scalarizeVectorStore(StoreNode, DAG);
28482848
}
28492849

@@ -8716,7 +8716,9 @@ EVT AArch64TargetLowering::getOptimalMemOpType(
87168716
if (memOpAlign(SrcAlign, DstAlign, AlignCheck))
87178717
return true;
87188718
bool Fast;
8719-
return allowsMisalignedMemoryAccesses(VT, 0, 1, &Fast) && Fast;
8719+
return allowsMisalignedMemoryAccesses(VT, 0, 1, MachineMemOperand::MONone,
8720+
&Fast) &&
8721+
Fast;
87208722
};
87218723

87228724
if (CanUseNEON && IsMemset && !IsSmallMemset &&

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ class AArch64TargetLowering : public TargetLowering {
262262

263263
/// Returns true if the target allows unaligned memory accesses of the
264264
/// specified type.
265-
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace = 0,
266-
unsigned Align = 1,
267-
bool *Fast = nullptr) const override;
265+
bool allowsMisalignedMemoryAccesses(
266+
EVT VT, unsigned AddrSpace = 0, unsigned Align = 1,
267+
MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
268+
bool *Fast = nullptr) const override;
268269

269270
/// Provide custom lowering hooks for some operations.
270271
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,7 +2968,8 @@ SDValue AMDGPUTargetLowering::performLoadCombine(SDNode *N,
29682968
// Expand unaligned loads earlier than legalization. Due to visitation order
29692969
// problems during legalization, the emitted instructions to pack and unpack
29702970
// the bytes again are not eliminated in the case of an unaligned copy.
2971-
if (!allowsMisalignedMemoryAccesses(VT, AS, Align, &IsFast)) {
2971+
if (!allowsMisalignedMemoryAccesses(
2972+
VT, AS, Align, LN->getMemOperand()->getFlags(), &IsFast)) {
29722973
if (VT.isVector())
29732974
return scalarizeVectorLoad(LN, DAG);
29742975

@@ -3020,7 +3021,8 @@ SDValue AMDGPUTargetLowering::performStoreCombine(SDNode *N,
30203021
// order problems during legalization, the emitted instructions to pack and
30213022
// unpack the bytes again are not eliminated in the case of an unaligned
30223023
// copy.
3023-
if (!allowsMisalignedMemoryAccesses(VT, AS, Align, &IsFast)) {
3024+
if (!allowsMisalignedMemoryAccesses(
3025+
VT, AS, Align, SN->getMemOperand()->getFlags(), &IsFast)) {
30243026
if (VT.isVector())
30253027
return scalarizeVectorStore(SN, DAG);
30263028

llvm/lib/Target/AMDGPU/R600ISelLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,8 @@ SDValue R600TargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const {
12611261

12621262
unsigned Align = StoreNode->getAlignment();
12631263
if (Align < MemVT.getStoreSize() &&
1264-
!allowsMisalignedMemoryAccesses(MemVT, AS, Align, nullptr)) {
1264+
!allowsMisalignedMemoryAccesses(
1265+
MemVT, AS, Align, StoreNode->getMemOperand()->getFlags(), nullptr)) {
12651266
return expandUnalignedStore(StoreNode, DAG);
12661267
}
12671268

@@ -1663,10 +1664,9 @@ bool R600TargetLowering::canMergeStoresTo(unsigned AS, EVT MemVT,
16631664
return true;
16641665
}
16651666

1666-
bool R600TargetLowering::allowsMisalignedMemoryAccesses(EVT VT,
1667-
unsigned AddrSpace,
1668-
unsigned Align,
1669-
bool *IsFast) const {
1667+
bool R600TargetLowering::allowsMisalignedMemoryAccesses(
1668+
EVT VT, unsigned AddrSpace, unsigned Align, MachineMemOperand::Flags Flags,
1669+
bool *IsFast) const {
16701670
if (IsFast)
16711671
*IsFast = false;
16721672

llvm/lib/Target/AMDGPU/R600ISelLowering.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class R600TargetLowering final : public AMDGPUTargetLowering {
4949
bool canMergeStoresTo(unsigned AS, EVT MemVT,
5050
const SelectionDAG &DAG) const override;
5151

52-
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS,
53-
unsigned Align,
54-
bool *IsFast) const override;
52+
bool allowsMisalignedMemoryAccesses(
53+
EVT VT, unsigned AS, unsigned Align,
54+
MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
55+
bool *IsFast = nullptr) const override;
5556

5657
private:
5758
unsigned Gen;

0 commit comments

Comments
 (0)