Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/CodeGen/BasicTTIImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,8 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
if (Opcode == Instruction::Store)
LA = getTLI()->getTruncStoreAction(LT.second, MemVT);
else
LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT);
LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT,
AddressSpace);

if (LA != TargetLowering::Legal && LA != TargetLowering::Custom) {
// This is a vector load/store for some illegal type that is scalarized.
Expand Down
55 changes: 37 additions & 18 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -1479,27 +1479,38 @@ class LLVM_ABI TargetLoweringBase {
/// Return how this load with extension should be treated: either it is legal,
/// needs to be promoted to a larger size, needs to be expanded to some other
/// code sequence, or the target has a custom expander for it.
LegalizeAction getLoadExtAction(unsigned ExtType, EVT ValVT,
EVT MemVT) const {
LegalizeAction getLoadExtAction(unsigned ExtType, EVT ValVT, EVT MemVT,
unsigned AddrSpace = 0) const {
if (ValVT.isExtended() || MemVT.isExtended()) return Expand;
unsigned ValI = (unsigned) ValVT.getSimpleVT().SimpleTy;
unsigned MemI = (unsigned) MemVT.getSimpleVT().SimpleTy;
assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValI < MVT::VALUETYPE_SIZE &&
MemI < MVT::VALUETYPE_SIZE && "Table isn't big enough!");
unsigned Shift = 4 * ExtType;
return (LegalizeAction)((LoadExtActions[ValI][MemI] >> Shift) & 0xf);
if (LoadExtActions.count(AddrSpace)) {
return (
LegalizeAction)((LoadExtActions.at(AddrSpace)[ValI][MemI] >> Shift) &
0xf);
} else {
assert(AddrSpace != 0 && "addrspace zero should be initialized");
return (
LegalizeAction)((LoadExtActions.at(0)[ValI][MemI] >> Shift) &
0xf);
}
}

/// Return true if the specified load with extension is legal on this target.
bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT) const {
return getLoadExtAction(ExtType, ValVT, MemVT) == Legal;
bool isLoadExtLegal(unsigned ExtType, EVT ValVT, EVT MemVT,
unsigned AddrSpace = 0) const {
return getLoadExtAction(ExtType, ValVT, MemVT, AddrSpace) == Legal;
}

/// Return true if the specified load with extension is legal or custom
/// on this target.
bool isLoadExtLegalOrCustom(unsigned ExtType, EVT ValVT, EVT MemVT) const {
return getLoadExtAction(ExtType, ValVT, MemVT) == Legal ||
getLoadExtAction(ExtType, ValVT, MemVT) == Custom;
bool isLoadExtLegalOrCustom(unsigned ExtType, EVT ValVT, EVT MemVT,
unsigned AddrSpace = 0) const {
return getLoadExtAction(ExtType, ValVT, MemVT, AddrSpace) == Legal ||
getLoadExtAction(ExtType, ValVT, MemVT, AddrSpace) == Custom;
}

/// Same as getLoadExtAction, but for atomic loads.
Expand Down Expand Up @@ -2641,23 +2652,27 @@ class LLVM_ABI TargetLoweringBase {
/// Indicate that the specified load with extension does not work with the
/// specified type and indicate what to do about it.
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT,
LegalizeAction Action) {
LegalizeAction Action, unsigned AddrSpace = 0) {
assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() &&
MemVT.isValid() && "Table isn't big enough!");
assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
assert(AddrSpace == 0 && "expected addrspace 0");
unsigned Shift = 4 * ExtType;
LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] &= ~((uint16_t)0xF << Shift);
LoadExtActions[ValVT.SimpleTy][MemVT.SimpleTy] |= (uint16_t)Action << Shift;
LoadExtActions[AddrSpace][ValVT.SimpleTy][MemVT.SimpleTy] &=
~((uint16_t)0xF << Shift);
LoadExtActions[AddrSpace][ValVT.SimpleTy][MemVT.SimpleTy] |=
(uint16_t)Action << Shift;
}
void setLoadExtAction(ArrayRef<unsigned> ExtTypes, MVT ValVT, MVT MemVT,
LegalizeAction Action) {
LegalizeAction Action, unsigned AddrSpace = 0) {
for (auto ExtType : ExtTypes)
setLoadExtAction(ExtType, ValVT, MemVT, Action);
setLoadExtAction(ExtType, ValVT, MemVT, Action, AddrSpace);
}
void setLoadExtAction(ArrayRef<unsigned> ExtTypes, MVT ValVT,
ArrayRef<MVT> MemVTs, LegalizeAction Action) {
ArrayRef<MVT> MemVTs, LegalizeAction Action,
unsigned AddrSpace = 0) {
for (auto MemVT : MemVTs)
setLoadExtAction(ExtTypes, ValVT, MemVT, Action);
setLoadExtAction(ExtTypes, ValVT, MemVT, Action, AddrSpace);
}

/// Let target indicate that an extending atomic load of the specified type
Expand Down Expand Up @@ -3133,7 +3148,7 @@ class LLVM_ABI TargetLoweringBase {
LType = ISD::SEXTLOAD;
}

return isLoadExtLegal(LType, VT, LoadVT);
return isLoadExtLegal(LType, VT, LoadVT, Load->getPointerAddressSpace());
}

/// Return true if any actual instruction that defines a value of type FromTy
Expand Down Expand Up @@ -3748,8 +3763,12 @@ class LLVM_ABI TargetLoweringBase {
/// For each load extension type and each value type, keep a LegalizeAction
/// that indicates how instruction selection should deal with a load of a
/// specific value type and extension type. Uses 4-bits to store the action
/// for each of the 4 load ext types.
uint16_t LoadExtActions[MVT::VALUETYPE_SIZE][MVT::VALUETYPE_SIZE];
/// for each of the 4 load ext types. These actions can be specified for each
/// address space.
using LoadExtActionMapTy =
std::array<std::array<uint16_t, MVT::VALUETYPE_SIZE>, MVT::VALUETYPE_SIZE>;
using LoadExtActionMap = std::map<unsigned, LoadExtActionMapTy>;
LoadExtActionMap LoadExtActions;

/// Similar to LoadExtActions, but for atomic loads. Only Legal or Expand
/// (default) values are supported.
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7328,7 +7328,8 @@ bool CodeGenPrepare::optimizeLoadExt(LoadInst *Load) {

// Reject cases that won't be matched as extloads.
if (!LoadResultVT.bitsGT(TruncVT) || !TruncVT.isRound() ||
!TLI->isLoadExtLegal(ISD::ZEXTLOAD, LoadResultVT, TruncVT))
!TLI->isLoadExtLegal(ISD::ZEXTLOAD, LoadResultVT, TruncVT,
Load->getPointerAddressSpace()))
return false;

IRBuilder<> Builder(Load->getNextNode());
Expand Down
Loading
Loading