Skip to content

Commit b163efa

Browse files
committed
[GlobalIsel][X86] Add handling for G_LOAD/G_SEXTLOAD/G_ZEXTLOAD/G_STORE
Replace the legacy legalizer versions and add initial scalar extload handling
1 parent 31c485c commit b163efa

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

llvm/lib/Target/X86/X86LegalizerInfo.cpp

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
4545
const LLT s16 = LLT::scalar(16);
4646
const LLT s32 = LLT::scalar(32);
4747
const LLT s64 = LLT::scalar(64);
48+
const LLT s80 = LLT::scalar(80);
4849
const LLT s128 = LLT::scalar(128);
4950
const LLT sMaxScalar = Subtarget.is64Bit() ? s64 : s32;
5051

@@ -292,6 +293,53 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
292293

293294
getActionDefinitionsBuilder({G_FRAME_INDEX, G_GLOBAL_VALUE}).legalFor({p0});
294295

296+
// load/store
297+
for (unsigned Op : {G_LOAD, G_STORE}) {
298+
auto &Action = getActionDefinitionsBuilder(Op);
299+
Action.legalForTypesWithMemDesc({{s8, p0, s1, 1},
300+
{s8, p0, s8, 1},
301+
{s16, p0, s8, 1},
302+
{s16, p0, s16, 1},
303+
{s32, p0, s8, 1},
304+
{s32, p0, s16, 1},
305+
{s32, p0, s32, 1},
306+
{s80, p0, s80, 1},
307+
{p0, p0, p0, 1}});
308+
if (Is64Bit)
309+
Action.legalForTypesWithMemDesc({{s64, p0, s8, 1},
310+
{s64, p0, s16, 1},
311+
{s64, p0, s32, 1},
312+
{s64, p0, s64, 1}});
313+
if (HasSSE1)
314+
Action.legalForTypesWithMemDesc({{v16s8, p0, v16s8, 1},
315+
{v8s16, p0, v8s16, 1},
316+
{v4s32, p0, v4s32, 1},
317+
{v2s64, p0, v2s64, 1}});
318+
if (HasAVX)
319+
Action.legalForTypesWithMemDesc({{v32s8, p0, v32s8, 1},
320+
{v16s16, p0, v16s16, 1},
321+
{v8s32, p0, v8s32, 1},
322+
{v4s64, p0, v4s64, 1}});
323+
if (HasAVX512)
324+
Action.legalForTypesWithMemDesc({{v64s8, p0, v64s8, 1},
325+
{v32s16, p0, v32s16, 1},
326+
{v16s32, p0, v16s32, 1},
327+
{v8s64, p0, v8s64, 1}});
328+
Action.widenScalarToNextPow2(0, /*Min=*/8).clampScalar(0, s8, sMaxScalar);
329+
}
330+
331+
for (unsigned Op : {G_SEXTLOAD, G_ZEXTLOAD}) {
332+
auto &Action = getActionDefinitionsBuilder(Op);
333+
Action.legalForTypesWithMemDesc({{s16, p0, s8, 1},
334+
{s32, p0, s8, 1},
335+
{s32, p0, s16, 1}});
336+
if (Is64Bit)
337+
Action.legalForTypesWithMemDesc({{s64, p0, s8, 1},
338+
{s64, p0, s16, 1},
339+
{s64, p0, s32, 1}});
340+
// TODO - SSE41/AVX2/AVX512F/AVX512BW vector extensions
341+
}
342+
295343
// sext, zext, and anyext
296344
getActionDefinitionsBuilder({G_SEXT, G_ZEXT, G_ANYEXT})
297345
.legalIf([=](const LegalityQuery &Query) {
@@ -442,13 +490,8 @@ X86LegalizerInfo::X86LegalizerInfo(const X86Subtarget &STI,
442490
setLegalizerInfoSSE2();
443491
setLegalizerInfoAVX();
444492
setLegalizerInfoAVX2();
445-
setLegalizerInfoAVX512();
446493

447494
auto &LegacyInfo = getLegacyLegalizerInfo();
448-
for (unsigned MemOp : {G_LOAD, G_STORE})
449-
LegacyInfo.setLegalizeScalarToDifferentSizeStrategy(
450-
MemOp, 0, LegacyLegalizerInfo::narrowToSmallerAndWidenToSmallest);
451-
452495
LegacyInfo.computeTables();
453496
verify(*STI.getInstrInfo());
454497
}
@@ -460,22 +503,13 @@ bool X86LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
460503

461504
void X86LegalizerInfo::setLegalizerInfo32bit() {
462505

463-
const LLT p0 = LLT::pointer(0, TM.getPointerSizeInBits(0));
464506
const LLT s8 = LLT::scalar(8);
465507
const LLT s16 = LLT::scalar(16);
466508
const LLT s32 = LLT::scalar(32);
467509
const LLT s64 = LLT::scalar(64);
468510

469511
auto &LegacyInfo = getLegacyLegalizerInfo();
470512

471-
for (unsigned MemOp : {G_LOAD, G_STORE}) {
472-
for (auto Ty : {s8, s16, s32, p0})
473-
LegacyInfo.setAction({MemOp, Ty}, LegacyLegalizeActions::Legal);
474-
475-
// And everything's fine in addrspace 0.
476-
LegacyInfo.setAction({MemOp, 1, p0}, LegacyLegalizeActions::Legal);
477-
}
478-
479513
// Merge/Unmerge
480514
for (const auto &Ty : {s16, s32, s64}) {
481515
LegacyInfo.setAction({G_MERGE_VALUES, Ty}, LegacyLegalizeActions::Legal);
@@ -493,14 +527,10 @@ void X86LegalizerInfo::setLegalizerInfo64bit() {
493527
if (!Subtarget.is64Bit())
494528
return;
495529

496-
const LLT s64 = LLT::scalar(64);
497530
const LLT s128 = LLT::scalar(128);
498531

499532
auto &LegacyInfo = getLegacyLegalizerInfo();
500533

501-
for (unsigned MemOp : {G_LOAD, G_STORE})
502-
LegacyInfo.setAction({MemOp, s64}, LegacyLegalizeActions::Legal);
503-
504534
// Merge/Unmerge
505535
LegacyInfo.setAction({G_MERGE_VALUES, s128}, LegacyLegalizeActions::Legal);
506536
LegacyInfo.setAction({G_UNMERGE_VALUES, 1, s128},
@@ -519,10 +549,6 @@ void X86LegalizerInfo::setLegalizerInfoSSE1() {
519549

520550
auto &LegacyInfo = getLegacyLegalizerInfo();
521551

522-
for (unsigned MemOp : {G_LOAD, G_STORE})
523-
for (auto Ty : {v4s32, v2s64})
524-
LegacyInfo.setAction({MemOp, Ty}, LegacyLegalizeActions::Legal);
525-
526552
// Merge/Unmerge
527553
for (const auto &Ty : {v4s32, v2s64}) {
528554
LegacyInfo.setAction({G_UNMERGE_VALUES, 1, Ty},
@@ -579,10 +605,6 @@ void X86LegalizerInfo::setLegalizerInfoAVX() {
579605

580606
auto &LegacyInfo = getLegacyLegalizerInfo();
581607

582-
for (unsigned MemOp : {G_LOAD, G_STORE})
583-
for (auto Ty : {v8s32, v4s64})
584-
LegacyInfo.setAction({MemOp, Ty}, LegacyLegalizeActions::Legal);
585-
586608
// Merge/Unmerge
587609
for (const auto &Ty :
588610
{v32s8, v64s8, v16s16, v32s16, v8s32, v16s32, v4s64, v8s64}) {
@@ -620,17 +642,3 @@ void X86LegalizerInfo::setLegalizerInfoAVX2() {
620642
LegacyInfo.setAction({G_UNMERGE_VALUES, Ty}, LegacyLegalizeActions::Legal);
621643
}
622644
}
623-
624-
void X86LegalizerInfo::setLegalizerInfoAVX512() {
625-
if (!Subtarget.hasAVX512())
626-
return;
627-
628-
const LLT v16s32 = LLT::fixed_vector(16, 32);
629-
const LLT v8s64 = LLT::fixed_vector(8, 64);
630-
631-
auto &LegacyInfo = getLegacyLegalizerInfo();
632-
633-
for (unsigned MemOp : {G_LOAD, G_STORE})
634-
for (auto Ty : {v16s32, v8s64})
635-
LegacyInfo.setAction({MemOp, Ty}, LegacyLegalizeActions::Legal);
636-
}

llvm/lib/Target/X86/X86LegalizerInfo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class X86LegalizerInfo : public LegalizerInfo {
4242
void setLegalizerInfoSSE2();
4343
void setLegalizerInfoAVX();
4444
void setLegalizerInfoAVX2();
45-
void setLegalizerInfoAVX512();
4645
};
4746
} // namespace llvm
4847
#endif

0 commit comments

Comments
 (0)