Skip to content

Commit d6bbb10

Browse files
committed
[AArch64][GlobalISel] Don't crash when legalising vector G_SHL
1 parent 53dfdf7 commit d6bbb10

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
216216
.widenScalarToNextPow2(0)
217217
.clampScalar(1, s32, s64)
218218
.clampScalar(0, s32, s64)
219+
.minScalarSameAs(1, 0)
220+
.minScalarEltSameAsIf(isVector(0), 1, 0)
221+
.maxScalarEltSameAsIf(isVector(0), 1, 0)
219222
.clampNumElements(0, v8s8, v16s8)
220223
.clampNumElements(0, v4s16, v8s16)
221224
.clampNumElements(0, v2s32, v4s32)
222225
.clampNumElements(0, v2s64, v2s64)
223226
.moreElementsToNextPow2(0)
224-
.minScalarSameAs(1, 0)
225-
.scalarizeIf(scalarOrEltWiderThan(0, 64), 0)
226-
.minScalarEltSameAsIf(isVector(0), 1, 0)
227-
.maxScalarEltSameAsIf(isVector(0), 1, 0);
227+
.scalarizeIf(scalarOrEltWiderThan(0, 64), 0);
228228

229229
getActionDefinitionsBuilder(G_PTR_ADD)
230230
.legalFor({{p0, s64}, {v2p0, v2s64}})
@@ -470,29 +470,31 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
470470
getActionDefinitionsBuilder(G_FMAD).lower();
471471

472472
for (unsigned Op : {G_SEXTLOAD, G_ZEXTLOAD}) {
473-
auto &Actions = getActionDefinitionsBuilder(Op);
473+
auto &Actions = getActionDefinitionsBuilder(Op);
474474

475475
if (Op == G_SEXTLOAD)
476-
Actions.lowerIf(atomicOrderingAtLeastOrStrongerThan(0, AtomicOrdering::Unordered));
476+
Actions.lowerIf(
477+
atomicOrderingAtLeastOrStrongerThan(0, AtomicOrdering::Unordered));
477478

478479
// Atomics have zero extending behavior.
479480
Actions
480-
.legalForTypesWithMemDesc({{s32, p0, s8, 8},
481-
{s32, p0, s16, 8},
482-
{s32, p0, s32, 8},
483-
{s64, p0, s8, 2},
484-
{s64, p0, s16, 2},
485-
{s64, p0, s32, 4},
486-
{s64, p0, s64, 8},
487-
{p0, p0, s64, 8},
488-
{v2s32, p0, s64, 8}})
489-
.widenScalarToNextPow2(0)
490-
.clampScalar(0, s32, s64)
491-
// TODO: We could support sum-of-pow2's but the lowering code doesn't know
492-
// how to do that yet.
493-
.unsupportedIfMemSizeNotPow2()
494-
// Lower anything left over into G_*EXT and G_LOAD
495-
.lower();
481+
.legalForTypesWithMemDesc({{s32, p0, s8, 8},
482+
{s32, p0, s16, 8},
483+
{s32, p0, s32, 8},
484+
{s64, p0, s8, 2},
485+
{s64, p0, s16, 2},
486+
{s64, p0, s32, 4},
487+
{s64, p0, s64, 8},
488+
{p0, p0, s64, 8},
489+
{v2s32, p0, s64, 8}})
490+
.widenScalarToNextPow2(0)
491+
.clampScalar(0, s32, s64)
492+
// TODO: We could support sum-of-pow2's but the lowering code doesn't
493+
// know
494+
// how to do that yet.
495+
.unsupportedIfMemSizeNotPow2()
496+
// Lower anything left over into G_*EXT and G_LOAD
497+
.lower();
496498
}
497499

498500
auto IsPtrVecPred = [=](const LegalityQuery &Query) {
@@ -985,9 +987,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
985987

986988
// Control-flow
987989
getActionDefinitionsBuilder(G_BR).alwaysLegal();
988-
getActionDefinitionsBuilder(G_BRCOND)
989-
.legalFor({s32})
990-
.clampScalar(0, s32, s32);
990+
getActionDefinitionsBuilder(G_BRCOND).legalFor({s32}).clampScalar(0, s32,
991+
s32);
991992
getActionDefinitionsBuilder(G_BRINDIRECT).legalFor({p0});
992993

993994
getActionDefinitionsBuilder(G_SELECT)
@@ -1056,8 +1057,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
10561057
.widenScalarToNextPow2(0, /*Min*/ 8);
10571058

10581059
getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG_WITH_SUCCESS)
1059-
.lowerIf(
1060-
all(typeInSet(0, {s8, s16, s32, s64, s128}), typeIs(2, p0)));
1060+
.lowerIf(all(typeInSet(0, {s8, s16, s32, s64, s128}), typeIs(2, p0)));
10611061

10621062
bool UseOutlineAtomics = ST.outlineAtomics() && !ST.hasLSE();
10631063

@@ -1611,7 +1611,7 @@ bool AArch64LegalizerInfo::legalizeSmallCMGlobalValue(
16111611
// Don't modify an intrinsic call.
16121612
if (GlobalOp.isSymbol())
16131613
return true;
1614-
const auto* GV = GlobalOp.getGlobal();
1614+
const auto *GV = GlobalOp.getGlobal();
16151615
if (GV->isThreadLocal())
16161616
return true; // Don't want to modify TLS vars.
16171617

@@ -1685,10 +1685,10 @@ bool AArch64LegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
16851685
switch (IntrinsicID) {
16861686
case Intrinsic::vacopy: {
16871687
unsigned PtrSize = ST->isTargetILP32() ? 4 : 8;
1688-
unsigned VaListSize =
1689-
(ST->isTargetDarwin() || ST->isTargetWindows())
1690-
? PtrSize
1691-
: ST->isTargetILP32() ? 20 : 32;
1688+
unsigned VaListSize = (ST->isTargetDarwin() || ST->isTargetWindows())
1689+
? PtrSize
1690+
: ST->isTargetILP32() ? 20
1691+
: 32;
16921692

16931693
MachineFunction &MF = *MI.getMF();
16941694
auto Val = MF.getRegInfo().createGenericVirtualRegister(
@@ -2135,7 +2135,8 @@ bool AArch64LegalizerInfo::legalizeCTPOP(MachineInstr &MI,
21352135
// v8s16,v4s32,v2s64 -> v16i8
21362136
LLT VTy = Size == 128 ? LLT::fixed_vector(16, 8) : LLT::fixed_vector(8, 8);
21372137
if (Ty.isScalar()) {
2138-
assert((Size == 32 || Size == 64 || Size == 128) && "Expected only 32, 64, or 128 bit scalars!");
2138+
assert((Size == 32 || Size == 64 || Size == 128) &&
2139+
"Expected only 32, 64, or 128 bit scalars!");
21392140
if (Size == 32) {
21402141
Val = MIRBuilder.buildZExt(LLT::scalar(64), Val).getReg(0);
21412142
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llc -global-isel -o - %s | FileCheck %s
2+
3+
target triple = "aarch64-unknown-unknown"
4+
5+
; Check we don't crash here.
6+
7+
define <2 x i8> @test() {
8+
entry:
9+
%zeroes = zext <2 x i1> zeroinitializer to <2 x i32>
10+
%ones = shl <2 x i32> splat (i32 1), %zeroes
11+
%ones.trunc = trunc <2 x i32> %ones to <2 x i8>
12+
ret <2 x i8> %ones.trunc
13+
}

0 commit comments

Comments
 (0)