Skip to content

Commit ebcf9ba

Browse files
Finish making address-space sensitive, and fix AMDGPU backend
1 parent 99e87a3 commit ebcf9ba

File tree

12 files changed

+219
-131
lines changed

12 files changed

+219
-131
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/Analysis/TargetTransformInfoImpl.h"
2929
#include "llvm/Analysis/ValueTracking.h"
3030
#include "llvm/CodeGen/ISDOpcodes.h"
31+
#include "llvm/CodeGen/SelectionDAGNodes.h"
3132
#include "llvm/CodeGen/TargetLowering.h"
3233
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3334
#include "llvm/CodeGen/ValueTypes.h"
@@ -1244,9 +1245,14 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
12441245
EVT LoadVT = EVT::getEVT(Src);
12451246
unsigned LType =
12461247
((Opcode == Instruction::ZExt) ? ISD::ZEXTLOAD : ISD::SEXTLOAD);
1247-
if (DstLT.first == SrcLT.first &&
1248-
TLI->isLoadExtLegal(LType, ExtVT, LoadVT))
1249-
return 0;
1248+
1249+
if (I && isa<LoadInst>(I->getOperand(0))) {
1250+
auto *LI = cast<LoadInst>(I->getOperand(0));
1251+
1252+
if (DstLT.first == SrcLT.first &&
1253+
TLI->isLoadExtLegal(LType, ExtVT, LoadVT, LI->getPointerAddressSpace()))
1254+
return 0;
1255+
}
12501256
}
12511257
break;
12521258
case Instruction::AddrSpaceCast:
@@ -1531,7 +1537,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
15311537
if (Opcode == Instruction::Store)
15321538
LA = getTLI()->getTruncStoreAction(LT.second, MemVT);
15331539
else
1534-
LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT);
1540+
LA = getTLI()->getLoadExtAction(ISD::EXTLOAD, LT.second, MemVT, AddressSpace);
15351541

15361542
if (LA != TargetLowering::Legal && LA != TargetLowering::Custom) {
15371543
// This is a vector load/store for some illegal type that is scalarized.

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,11 @@ class LLVM_ABI TargetLoweringBase {
14831483
unsigned Shift = 4 * ExtType;
14841484

14851485
if (!LoadExtActions.count(AddrSpace)) {
1486-
return Legal; // default
1486+
if (MemVT == MVT::i2 || MemVT == MVT::i4 || MemVT == MVT::v128i2 ||
1487+
MemVT == MVT::v64i4)
1488+
return Expand;
1489+
1490+
return Legal;
14871491
}
14881492
return (
14891493
LegalizeAction)((LoadExtActions.at(AddrSpace)[ValI][MemI] >> Shift) &
@@ -2641,25 +2645,38 @@ class LLVM_ABI TargetLoweringBase {
26412645
/// Indicate that the specified load with extension does not work with the
26422646
/// specified type and indicate what to do about it.
26432647
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT,
2644-
LegalizeAction Action, unsigned AddrSpace) {
2648+
LegalizeAction Action, unsigned AddrSpace = 0) {
26452649
assert(ExtType < ISD::LAST_LOADEXT_TYPE && ValVT.isValid() &&
26462650
MemVT.isValid() && "Table isn't big enough!");
26472651
assert((unsigned)Action < 0x10 && "too many bits for bitfield array");
2652+
2653+
if (!LoadExtActions.count(AddrSpace)) {
2654+
LoadExtActions[AddrSpace]; // Initialize the map for the addrspace
2655+
2656+
for (MVT AVT : MVT::all_valuetypes()) {
2657+
for (MVT VT : {MVT::i2, MVT::i4, MVT::v128i2, MVT::v64i4}) {
2658+
setLoadExtAction(ISD::EXTLOAD, AVT, VT, Expand, AddrSpace);
2659+
setLoadExtAction(ISD::ZEXTLOAD, AVT, VT, Expand, AddrSpace);
2660+
}
2661+
}
2662+
}
2663+
26482664
unsigned Shift = 4 * ExtType;
26492665
LoadExtActions[AddrSpace][ValVT.SimpleTy][MemVT.SimpleTy] &=
26502666
~((uint16_t)0xF << Shift);
26512667
LoadExtActions[AddrSpace][ValVT.SimpleTy][MemVT.SimpleTy] |=
26522668
(uint16_t)Action << Shift;
26532669
}
26542670
void setLoadExtAction(ArrayRef<unsigned> ExtTypes, MVT ValVT, MVT MemVT,
2655-
LegalizeAction Action) {
2671+
LegalizeAction Action, unsigned AddrSpace = 0) {
26562672
for (auto ExtType : ExtTypes)
2657-
setLoadExtAction(ExtType, ValVT, MemVT, Action);
2673+
setLoadExtAction(ExtType, ValVT, MemVT, Action, AddrSpace);
26582674
}
26592675
void setLoadExtAction(ArrayRef<unsigned> ExtTypes, MVT ValVT,
2660-
ArrayRef<MVT> MemVTs, LegalizeAction Action) {
2676+
ArrayRef<MVT> MemVTs, LegalizeAction Action,
2677+
unsigned AddrSpace = 0) {
26612678
for (auto MemVT : MemVTs)
2662-
setLoadExtAction(ExtTypes, ValVT, MemVT, Action);
2679+
setLoadExtAction(ExtTypes, ValVT, MemVT, Action, AddrSpace);
26632680
}
26642681

26652682
/// Let target indicate that an extending atomic load of the specified type
@@ -3135,7 +3152,7 @@ class LLVM_ABI TargetLoweringBase {
31353152
LType = ISD::SEXTLOAD;
31363153
}
31373154

3138-
return isLoadExtLegal(LType, VT, LoadVT);
3155+
return isLoadExtLegal(LType, VT, LoadVT, Load->getPointerAddressSpace());
31393156
}
31403157

31413158
/// Return true if any actual instruction that defines a value of type FromTy

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7347,7 +7347,7 @@ bool CodeGenPrepare::optimizeLoadExt(LoadInst *Load) {
73477347

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

73537353
IRBuilder<> Builder(Load->getNextNode());

0 commit comments

Comments
 (0)