Skip to content

Commit e5948b4

Browse files
authored
[NVPTX] Support i256 load/store with 256-bit vector load (#155198)
1 parent c94b5f0 commit e5948b4

File tree

8 files changed

+283
-154
lines changed

8 files changed

+283
-154
lines changed

clang/lib/Basic/Targets/NVPTX.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
6969
HasFloat16 = true;
7070

7171
if (TargetPointerWidth == 32)
72-
resetDataLayout(
73-
"e-p:32:32-p6:32:32-p7:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
72+
resetDataLayout("e-p:32:32-p6:32:32-p7:32:32-i64:64-i128:128-i256:256-v16:"
73+
"16-v32:32-n16:32:64");
7474
else if (Opts.NVPTXUseShortPointers)
75-
resetDataLayout(
76-
"e-p3:32:32-p4:32:32-p5:32:32-p6:32:32-p7:32:32-i64:64-i128:128-v16:"
77-
"16-v32:32-n16:32:64");
75+
resetDataLayout("e-p3:32:32-p4:32:32-p5:32:32-p6:32:32-p7:32:32-i64:64-"
76+
"i128:128-i256:256-v16:"
77+
"16-v32:32-n16:32:64");
7878
else
79-
resetDataLayout("e-p6:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
79+
resetDataLayout(
80+
"e-p6:32:32-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64");
8081

8182
// If possible, get a TargetInfo for our host triple, so we can match its
8283
// types.

clang/test/CodeGen/target-data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@
144144

145145
// RUN: %clang_cc1 -triple nvptx-unknown -o - -emit-llvm %s | \
146146
// RUN: FileCheck %s -check-prefix=NVPTX
147-
// NVPTX: target datalayout = "e-p:32:32-p6:32:32-p7:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
147+
// NVPTX: target datalayout = "e-p:32:32-p6:32:32-p7:32:32-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64"
148148

149149
// RUN: %clang_cc1 -triple nvptx64-unknown -o - -emit-llvm %s | \
150150
// RUN: FileCheck %s -check-prefix=NVPTX64
151-
// NVPTX64: target datalayout = "e-p6:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
151+
// NVPTX64: target datalayout = "e-p6:32:32-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64"
152152

153153
// RUN: %clang_cc1 -triple r600-unknown -o - -emit-llvm %s | \
154154
// RUN: FileCheck %s -check-prefix=R600

llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,6 @@ bool NVPTXDAGToDAGISel::tryLoad(SDNode *N) {
11011101
if (PlainLoad && PlainLoad->isIndexed())
11021102
return false;
11031103

1104-
const EVT LoadedEVT = LD->getMemoryVT();
1105-
if (!LoadedEVT.isSimple())
1106-
return false;
1107-
const MVT LoadedVT = LoadedEVT.getSimpleVT();
1108-
11091104
// Address Space Setting
11101105
const auto CodeAddrSpace = getAddrSpace(LD);
11111106
if (canLowerToLDG(*LD, *Subtarget, CodeAddrSpace))
@@ -1115,7 +1110,7 @@ bool NVPTXDAGToDAGISel::tryLoad(SDNode *N) {
11151110
SDValue Chain = N->getOperand(0);
11161111
const auto [Ordering, Scope] = insertMemoryInstructionFence(DL, Chain, LD);
11171112

1118-
const unsigned FromTypeWidth = LoadedVT.getSizeInBits();
1113+
const unsigned FromTypeWidth = LD->getMemoryVT().getSizeInBits();
11191114

11201115
// Vector Setting
11211116
const unsigned FromType =
@@ -1169,9 +1164,6 @@ static unsigned getStoreVectorNumElts(SDNode *N) {
11691164

11701165
bool NVPTXDAGToDAGISel::tryLoadVector(SDNode *N) {
11711166
MemSDNode *LD = cast<MemSDNode>(N);
1172-
const EVT MemEVT = LD->getMemoryVT();
1173-
if (!MemEVT.isSimple())
1174-
return false;
11751167

11761168
// Address Space Setting
11771169
const auto CodeAddrSpace = getAddrSpace(LD);
@@ -1241,10 +1233,6 @@ bool NVPTXDAGToDAGISel::tryLoadVector(SDNode *N) {
12411233
}
12421234

12431235
bool NVPTXDAGToDAGISel::tryLDG(MemSDNode *LD) {
1244-
const EVT LoadedEVT = LD->getMemoryVT();
1245-
if (!LoadedEVT.isSimple())
1246-
return false;
1247-
12481236
SDLoc DL(LD);
12491237

12501238
unsigned ExtensionType;
@@ -1361,10 +1349,6 @@ bool NVPTXDAGToDAGISel::tryStore(SDNode *N) {
13611349
if (PlainStore && PlainStore->isIndexed())
13621350
return false;
13631351

1364-
const EVT StoreVT = ST->getMemoryVT();
1365-
if (!StoreVT.isSimple())
1366-
return false;
1367-
13681352
// Address Space Setting
13691353
const auto CodeAddrSpace = getAddrSpace(ST);
13701354

@@ -1373,7 +1357,7 @@ bool NVPTXDAGToDAGISel::tryStore(SDNode *N) {
13731357
const auto [Ordering, Scope] = insertMemoryInstructionFence(DL, Chain, ST);
13741358

13751359
// Vector Setting
1376-
const unsigned ToTypeWidth = StoreVT.getSimpleVT().getSizeInBits();
1360+
const unsigned ToTypeWidth = ST->getMemoryVT().getSizeInBits();
13771361

13781362
// Create the machine instruction DAG
13791363
SDValue Value = PlainStore ? PlainStore->getValue() : AtomicStore->getVal();
@@ -1410,8 +1394,7 @@ bool NVPTXDAGToDAGISel::tryStore(SDNode *N) {
14101394

14111395
bool NVPTXDAGToDAGISel::tryStoreVector(SDNode *N) {
14121396
MemSDNode *ST = cast<MemSDNode>(N);
1413-
const EVT StoreVT = ST->getMemoryVT();
1414-
assert(StoreVT.isSimple() && "Store value is not simple");
1397+
const unsigned TotalWidth = ST->getMemoryVT().getSizeInBits();
14151398

14161399
// Address Space Setting
14171400
const auto CodeAddrSpace = getAddrSpace(ST);
@@ -1424,10 +1407,6 @@ bool NVPTXDAGToDAGISel::tryStoreVector(SDNode *N) {
14241407
SDValue Chain = ST->getChain();
14251408
const auto [Ordering, Scope] = insertMemoryInstructionFence(DL, Chain, ST);
14261409

1427-
// Type Setting: toType + toTypeWidth
1428-
// - for integer type, always use 'u'
1429-
const unsigned TotalWidth = StoreVT.getSimpleVT().getSizeInBits();
1430-
14311410
const unsigned NumElts = getStoreVectorNumElts(ST);
14321411

14331412
SmallVector<SDValue, 16> Ops;

0 commit comments

Comments
 (0)