Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -652,17 +652,17 @@ bool GIMatchTableExecutor::executeMatchTable(
MachineMemOperand *MMO =
*(State.MIs[InsnID]->memoperands_begin() + MMOIdx);

unsigned Size = MRI.getType(MO.getReg()).getSizeInBits();
const auto Size = MRI.getType(MO.getReg()).getSizeInBits();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use TypeSize.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (MatcherOpcode == GIM_CheckMemorySizeEqualToLLT &&
MMO->getSizeInBits().getValue() != Size) {
MMO->getSizeInBits() != Size) {
if (handleReject() == RejectAndGiveUp)
return false;
} else if (MatcherOpcode == GIM_CheckMemorySizeLessThanLLT &&
MMO->getSizeInBits().getValue() >= Size) {
MMO->getSizeInBits().getValue() >= Size.getKnownMinValue()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these should either use TypeSize::isKnownGE or test that the types are equally scalable.

The Size in GIM_CheckMemorySizeEqualTo should maybe be scalable too, although as far as I understand none of that is used at the moment.

if (handleReject() == RejectAndGiveUp)
return false;
} else if (MatcherOpcode == GIM_CheckMemorySizeGreaterThanLLT &&
MMO->getSizeInBits().getValue() <= Size)
MMO->getSizeInBits().getValue() <= Size.getKnownMinValue())
if (handleReject() == RejectAndGiveUp)
return false;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ bool CombinerHelper::isIndexedLoadStoreLegal(GLoadStore &LdSt) const {
LLT Ty = MRI.getType(LdSt.getReg(0));
LLT MemTy = LdSt.getMMO().getMemoryType();
SmallVector<LegalityQuery::MemDesc, 2> MemDescrs(
{{MemTy, MemTy.getSizeInBits(), AtomicOrdering::NotAtomic}});
{{MemTy, MemTy.getSizeInBits().getKnownMinValue(), AtomicOrdering::NotAtomic}});
unsigned IndexedOpc = getIndexedOpc(LdSt.getOpcode());
SmallVector<LLT> OpTys;
if (IndexedOpc == TargetOpcode::G_INDEXED_STORE)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ bool IRTranslator::translateLoad(const User &U, MachineIRBuilder &MIRBuilder) {

bool IRTranslator::translateStore(const User &U, MachineIRBuilder &MIRBuilder) {
const StoreInst &SI = cast<StoreInst>(U);
if (DL->getTypeStoreSize(SI.getValueOperand()->getType()) == 0)
if (DL->getTypeStoreSize(SI.getValueOperand()->getType()).isZero())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated change. Isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed, otherwise we implicitly cast a ScalableVectorTy into ScalarTy and will fail.

TypeSize::operator TypeSize::ScalarTy() const {
  if (isScalable()) {
    reportInvalidSizeRequest(
        "Cannot implicitly convert a scalable size to a fixed-width size in "
        "`TypeSize::operator ScalarTy()`");
    return getKnownMinValue();
  }
  return getFixedValue();
}

return true;

ArrayRef<Register> Vals = getOrCreateVRegs(*SI.getValueOperand());
Expand Down
14 changes: 11 additions & 3 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26375,12 +26375,20 @@ bool AArch64TargetLowering::shouldLocalize(
return TargetLoweringBase::shouldLocalize(MI, TTI);
}

static bool isScalableTySupported(const unsigned Op) {
return Op == Instruction::Load || Op == Instruction::Store;
}

bool AArch64TargetLowering::fallBackToDAGISel(const Instruction &Inst) const {
if (Inst.getType()->isScalableTy())
return true;
const auto ScalableTySupported = isScalableTySupported(Inst.getOpcode());

// Fallback for scalable vectors
if (Inst.getType()->isScalableTy() && !ScalableTySupported) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to distinguish between GlobalISel and FastISel here. FastISel also calls this function, and it doesn't support scalable vectors. The patch you linked uses a command line flag to do this, but there is probably a better way than that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi - Please keep the command line option from #72976 at the moment. It will help having a debug option we can use for testing, but not be limited to implement every single SVE optimization before global-isel becomes production ready.

This doesn't need to be dependant on the operations we currently "support", the normal fallback mechanism for unsupported operations should handle that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added option aarch64-enable-sve-gisel which is disabled by default, instead of aarch64-disable-sve-gisel, because I found other options are also "enable" like aarch64-enable-logical-imm

return true;
}

for (unsigned i = 0; i < Inst.getNumOperands(); ++i)
if (Inst.getOperand(i)->getType()->isScalableTy())
if (Inst.getOperand(i)->getType()->isScalableTy() && !ScalableTySupported)
return true;

if (const AllocaInst *AI = dyn_cast<AllocaInst>(&Inst)) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64RegisterBanks.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def GPRRegBank : RegisterBank<"GPR", [XSeqPairsClass]>;

/// Floating Point/Vector Registers: B, H, S, D, Q.
def FPRRegBank : RegisterBank<"FPR", [QQQQ]>;
def FPRRegBank : RegisterBank<"FPR", [QQQQ, ZPR]>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment needs update to include ZPR too.


/// Conditional register: NZCV.
def CCRegBank : RegisterBank<"CC", [CCR]>;
59 changes: 53 additions & 6 deletions llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,27 @@ static unsigned selectLoadStoreUIOp(unsigned GenericOpc, unsigned RegBankID,
return GenericOpc;
}

/// Select the AArch64 opcode for the G_LOAD or G_STORE operation for scalable
/// vectors.
/// \p ElementSize size of the element of the scalable vector
static unsigned selectLoadStoreSVEOp(const unsigned GenericOpc,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this manually selected in the DAG path? Can you do this in tablegen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Select the AArch64 opcode for the G_LOAD or G_STORE operation \p GenericOpc,
/// appropriate for the (value) register bank \p RegBankID and of memory access
/// size \p OpSize. This returns the variant with the base+unsigned-immediate
/// addressing mode (e.g., LDRXui).
/// \returns \p GenericOpc if the combination is unsupported.
static unsigned selectLoadStoreUIOp(unsigned GenericOpc, unsigned RegBankID,
unsigned OpSize) {
const bool isStore = GenericOpc == TargetOpcode::G_STORE;
switch (RegBankID) {
case AArch64::GPRRegBankID:
switch (OpSize) {
case 8:
return isStore ? AArch64::STRBBui : AArch64::LDRBBui;
case 16:
return isStore ? AArch64::STRHHui : AArch64::LDRHHui;
case 32:
return isStore ? AArch64::STRWui : AArch64::LDRWui;
case 64:
return isStore ? AArch64::STRXui : AArch64::LDRXui;
}
break;
case AArch64::FPRRegBankID:
switch (OpSize) {
case 8:
return isStore ? AArch64::STRBui : AArch64::LDRBui;
case 16:
return isStore ? AArch64::STRHui : AArch64::LDRHui;
case 32:
return isStore ? AArch64::STRSui : AArch64::LDRSui;
case 64:
return isStore ? AArch64::STRDui : AArch64::LDRDui;
case 128:
return isStore ? AArch64::STRQui : AArch64::LDRQui;
}
break;
}
return GenericOpc;
}

Currently we are already doing selectLoadStoreUIOp manually. I'm following the same idea.
Making them select through TableGen would require more work and can be a separate patch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some investigation and found that the patch is actually using the existing tablegen-ed patterns in selectImpl. The added instruction selector code is just skipped.

const unsigned ElementSize) {
const bool isStore = GenericOpc == TargetOpcode::G_STORE;

switch (ElementSize) {
case 8:
return isStore ? AArch64::ST1B : AArch64::LD1B;
case 16:
return isStore ? AArch64::ST1H : AArch64::LD1H;
case 32:
return isStore ? AArch64::ST1W : AArch64::LD1W;
case 64:
return isStore ? AArch64::ST1D : AArch64::LD1D;
}

return GenericOpc;
}

/// Helper function for selectCopy. Inserts a subregister copy from \p SrcReg
/// to \p *To.
///
Expand Down Expand Up @@ -2853,8 +2874,8 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code actually used? Or is the tablegen pattern already used? I'm not sure how the predicates work otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the entire file AArch64InstructionSelector.cpp because we can reuse tablegen patterns. So I think we don't need to change here.

}

uint64_t MemSizeInBytes = LdSt.getMemSize().getValue();
unsigned MemSizeInBits = LdSt.getMemSizeInBits().getValue();
uint64_t MemSizeInBytes = LdSt.getMemSize().getValue().getKnownMinValue();
unsigned MemSizeInBits = LdSt.getMemSizeInBits().getValue().getKnownMinValue();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting.

AtomicOrdering Order = LdSt.getMMO().getSuccessOrdering();

// Need special instructions for atomics that affect ordering.
Expand Down Expand Up @@ -2906,9 +2927,23 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
const LLT ValTy = MRI.getType(ValReg);
const RegisterBank &RB = *RBI.getRegBank(ValReg, MRI, TRI);

#ifndef NDEBUG
if (ValTy.isScalableVector()) {
assert(STI.hasSVE()
&& "Load/Store register operand is scalable vector "
"while SVE is not supported by the target");
// assert(RB.getID() == AArch64::SVRRegBankID
// && "Load/Store register operand is scalable vector "
// "while its register bank is not SVR");
}
#endif

// The code below doesn't support truncating stores, so we need to split it
// again.
if (isa<GStore>(LdSt) && ValTy.getSizeInBits() > MemSizeInBits) {
// Truncate only if type is not scalable vector
const bool NeedTrunc = !ValTy.isScalableVector()
&& ValTy.getSizeInBits().getFixedValue() > MemSizeInBits;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need truncate / zext / sext support eventually. Please format the entire patch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add truncate / zext / sext in this patch?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can be separate - one step at a time, and it would be good to get the basics in first :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format the entire patch.

All formatting done

if (isa<GStore>(LdSt) && NeedTrunc) {
unsigned SubReg;
LLT MemTy = LdSt.getMMO().getMemoryType();
auto *RC = getRegClassForTypeOnBank(MemTy, RB);
Expand All @@ -2921,7 +2956,7 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
.getReg(0);
RBI.constrainGenericRegister(Copy, *RC, MRI);
LdSt.getOperand(0).setReg(Copy);
} else if (isa<GLoad>(LdSt) && ValTy.getSizeInBits() > MemSizeInBits) {
} else if (isa<GLoad>(LdSt) && NeedTrunc) {
// If this is an any-extending load from the FPR bank, split it into a regular
// load + extend.
if (RB.getID() == AArch64::FPRRegBankID) {
Expand Down Expand Up @@ -2951,10 +2986,19 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
// instruction with an updated opcode, or a new instruction.
auto SelectLoadStoreAddressingMode = [&]() -> MachineInstr * {
bool IsStore = isa<GStore>(I);
const unsigned NewOpc =
selectLoadStoreUIOp(I.getOpcode(), RB.getID(), MemSizeInBits);
unsigned NewOpc;
if (ValTy.isScalableVector()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM prefers removing brackets from single statements.

NewOpc = selectLoadStoreSVEOp(I.getOpcode(), ValTy.getElementType().getSizeInBits());
} else {
NewOpc = selectLoadStoreUIOp(I.getOpcode(), RB.getID(), MemSizeInBits);
}
if (NewOpc == I.getOpcode())
return nullptr;

if (ValTy.isScalableVector()) {
// Add the predicate register operand
I.addOperand(MachineOperand::CreatePredicate(true));
}
// Check if we can fold anything into the addressing mode.
auto AddrModeFns =
selectAddrModeIndexed(I.getOperand(1), MemSizeInBytes);
Expand All @@ -2970,6 +3014,9 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
Register CurValReg = I.getOperand(0).getReg();
IsStore ? NewInst.addUse(CurValReg) : NewInst.addDef(CurValReg);
NewInst.cloneMemRefs(I);
if (ValTy.isScalableVector()) {
NewInst.add(I.getOperand(1)); // Copy predicate register
}
for (auto &Fn : *AddrModeFns)
Fn(NewInst);
I.eraseFromParent();
Expand Down
93 changes: 90 additions & 3 deletions llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,79 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
const LLT v2s64 = LLT::fixed_vector(2, 64);
const LLT v2p0 = LLT::fixed_vector(2, p0);

// Scalable vector sizes range from 128 to 2048
// Note that subtargets may not support the full range.
// See [ScalableVecTypes] below.
const LLT nxv16s8 = LLT::scalable_vector(16, s8);
const LLT nxv32s8 = LLT::scalable_vector(32, s8);
const LLT nxv64s8 = LLT::scalable_vector(64, s8);
const LLT nxv128s8 = LLT::scalable_vector(128, s8);
const LLT nxv256s8 = LLT::scalable_vector(256, s8);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a scalable vector, which size is an unknown multiple of 256 * 8. Legalizing loads of scalable vectors is unintuitive.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, there is no target that supports nxv256s8. The original patch only listed:

 const LLT nxv8s16 = LLT::scalable_vector(8, 16);
 const LLT nxv4s32 = LLT::scalable_vector(4, 32);
 const LLT nxv2s64 = LLT::scalable_vector(2, 64);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it simpler for now, I would remove all these except for base sizes of 128-bit:

  • nxv8s16, nxv4s32, and nxv2s64 as listed in the original patch
  • nxv16s8 since SelectionDAG supports it
  • nxv2p0 since it has the same effective size as nxv2s64.


const LLT nxv8s16 = LLT::scalable_vector(8, s16);
const LLT nxv16s16 = LLT::scalable_vector(16, s16);
const LLT nxv32s16 = LLT::scalable_vector(32, s16);
const LLT nxv64s16 = LLT::scalable_vector(64, s16);
const LLT nxv128s16 = LLT::scalable_vector(128, s16);

const LLT nxv4s32 = LLT::scalable_vector(4, s32);
const LLT nxv8s32 = LLT::scalable_vector(8, s32);
const LLT nxv16s32 = LLT::scalable_vector(16, s32);
const LLT nxv32s32 = LLT::scalable_vector(32, s32);
const LLT nxv64s32 = LLT::scalable_vector(64, s32);

const LLT nxv2s64 = LLT::scalable_vector(2, s64);
const LLT nxv4s64 = LLT::scalable_vector(4, s64);
const LLT nxv8s64 = LLT::scalable_vector(8, s64);
const LLT nxv16s64 = LLT::scalable_vector(16, s64);
const LLT nxv32s64 = LLT::scalable_vector(32, s64);

const LLT nxv2p0 = LLT::scalable_vector(2, p0);
const LLT nxv4p0 = LLT::scalable_vector(4, p0);
const LLT nxv8p0 = LLT::scalable_vector(8, p0);
const LLT nxv16p0 = LLT::scalable_vector(16, p0);
const LLT nxv32p0 = LLT::scalable_vector(32, p0);

const auto ScalableVec128 = {
nxv16s8, nxv8s16, nxv4s32, nxv2s64, nxv2p0,
};
const auto ScalableVec256 = {
nxv32s8, nxv16s16, nxv8s32, nxv4s64, nxv4p0,
};
const auto ScalableVec512 = {
nxv64s8, nxv32s16, nxv16s32, nxv8s64, nxv8p0,
};
const auto ScalableVec1024 = {
nxv128s8, nxv64s16, nxv32s32, nxv16s64, nxv16p0,
};
const auto ScalableVec2048 = {
nxv256s8, nxv128s16, nxv64s32, nxv32s64, nxv32p0,
};

/// Scalable vector types supported by the sub target.
/// Empty if SVE is not supported.
SmallVector<LLT> ScalableVecTypes;

if (ST.hasSVE()) {
// Add scalable vector types that are supported by the subtarget
const auto MinSize = ST.getMinSVEVectorSizeInBits();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the point of SVE is that you can compile on one machine and run on another with a different vector widths.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, checking ST.hasSVE() is enough, at least for sizes of multiple of 128-bit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a const bool HasRCPC3 = ST.hasRCPC3(); in the file. You could add a similar:

const bool HasSVE = ST.hasSVE();

auto MaxSize = ST.getMaxSVEVectorSizeInBits();
if (MaxSize == 0) {
// Unknown max size, assume the target supports all sizes.
MaxSize = 2048;
}
if (MinSize <= 128 && 128 <= MaxSize)
ScalableVecTypes.append(ScalableVec128);
if (MinSize <= 256 && 256 <= MaxSize)
ScalableVecTypes.append(ScalableVec256);
if (MinSize <= 512 && 512 <= MaxSize)
ScalableVecTypes.append(ScalableVec512);
if (MinSize <= 1024 && 1024 <= MaxSize)
ScalableVecTypes.append(ScalableVec1024);
if (MinSize <= 2048 && 2048 <= MaxSize)
ScalableVecTypes.append(ScalableVec2048);
}

std::initializer_list<LLT> PackedVectorAllTypeList = {/* Begin 128bit types */
v16s8, v8s16, v4s32,
v2s64, v2p0,
Expand Down Expand Up @@ -329,6 +402,18 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
return ValTy.isPointerVector() && ValTy.getAddressSpace() == 0;
};

const auto IsSameScalableVecTy = [=](const LegalityQuery &Query) {
// Legal if loading a scalable vector type
// into a scalable vector register of the exactly same type
if (!Query.Types[0].isScalableVector() || Query.Types[1] != p0)
return false;
if (Query.MMODescrs[0].MemoryTy != Query.Types[0])
return false;
if (Query.MMODescrs[0].AlignInBits < 128)
return false;
return is_contained(ScalableVecTypes, Query.Types[0]);
};

getActionDefinitionsBuilder(G_LOAD)
.customIf([=](const LegalityQuery &Query) {
return HasRCPC3 && Query.Types[0] == s128 &&
Expand All @@ -354,6 +439,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
// These extends are also legal
.legalForTypesWithMemDesc(
{{s32, p0, s8, 8}, {s32, p0, s16, 8}, {s64, p0, s32, 8}})
.legalIf(IsSameScalableVecTy)
.widenScalarToNextPow2(0, /* MinSize = */ 8)
.clampMaxNumElements(0, s8, 16)
.clampMaxNumElements(0, s16, 8)
Expand Down Expand Up @@ -398,7 +484,9 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
{s64, p0, s64, 8}, {s64, p0, s32, 8}, // truncstorei32 from s64
{p0, p0, s64, 8}, {s128, p0, s128, 8}, {v16s8, p0, s128, 8},
{v8s8, p0, s64, 8}, {v4s16, p0, s64, 8}, {v8s16, p0, s128, 8},
{v2s32, p0, s64, 8}, {v4s32, p0, s128, 8}, {v2s64, p0, s128, 8}})
{v2s32, p0, s64, 8}, {v4s32, p0, s128, 8}, {v2s64, p0, s128, 8},
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo this, unless it is clang-formatted on purpose.

.legalIf(IsSameScalableVecTy)
.clampScalar(0, s8, s64)
.lowerIf([=](const LegalityQuery &Query) {
return Query.Types[0].isScalar() &&
Expand Down Expand Up @@ -440,8 +528,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
{p0, v4s32, v4s32, 8},
{p0, v2s64, v2s64, 8},
{p0, v2p0, v2p0, 8},
{p0, s128, s128, 8},
})
{p0, s128, s128, 8}})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, formatted the entire patch.

.unsupported();

auto IndexedLoadBasicPred = [=](const LegalityQuery &Query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool matchSplitStoreZero128(MachineInstr &MI, MachineRegisterInfo &MRI) {
if (!Store.isSimple())
return false;
LLT ValTy = MRI.getType(Store.getValueReg());
if (!ValTy.isVector() || ValTy.getSizeInBits() != 128)
if (!ValTy.isVector() || ValTy.getSizeInBits().getKnownMinValue() != 128)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a check for !Scalable, I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, reverted this line and added this above instead.

if (ValTy.isScalableVector())
    return false;

return false;
if (Store.getMemSizeInBits() != ValTy.getSizeInBits())
return false; // Don't split truncating stores.
Expand Down Expand Up @@ -657,8 +657,8 @@ bool AArch64PostLegalizerCombiner::optimizeConsecutiveMemOpAddressing(
Register PtrBaseReg;
APInt Offset;
LLT StoredValTy = MRI.getType(St->getValueReg());
unsigned ValSize = StoredValTy.getSizeInBits();
if (ValSize < 32 || St->getMMO().getSizeInBits() != ValSize)
const auto ValSize = StoredValTy.getSizeInBits();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think somewhere up above in this function we should bail out if the vector is scalable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, replaced with a bail-out check for operand 0 being scalable vector.

if (ValSize.getKnownMinValue() < 32 || St->getMMO().getSizeInBits() != ValSize)
continue;

Register PtrReg = St->getPointerReg();
Expand Down
10 changes: 7 additions & 3 deletions llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ AArch64RegisterBankInfo::getRegBankFromRegClass(const TargetRegisterClass &RC,
case AArch64::QQRegClassID:
case AArch64::QQQRegClassID:
case AArch64::QQQQRegClassID:
case AArch64::ZPRRegClassID:
return getRegBank(AArch64::FPRRegBankID);
case AArch64::GPR32commonRegClassID:
case AArch64::GPR32RegClassID:
Expand Down Expand Up @@ -740,11 +741,14 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
LLT Ty = MRI.getType(MO.getReg());
if (!Ty.isValid())
continue;
OpSize[Idx] = Ty.getSizeInBits();
OpSize[Idx] = Ty.getSizeInBits().getKnownMinValue();

// As a top-level guess, vectors go in FPRs, scalars and pointers in GPRs.
// As a top-level guess, scalable vectors go in SVRs, non-scalable
// vectors go in FPRs, scalars and pointers in GPRs.
// For floating-point instructions, scalars go in FPRs.
if (Ty.isVector() || isPreISelGenericFloatingPointOpcode(Opc) ||
if (Ty.isScalableVector())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't isScalableVector() already covered by isVector()?

OpRegBankIdx[Idx] = PMI_FirstFPR;
else if (Ty.isVector() || isPreISelGenericFloatingPointOpcode(Opc) ||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to distinguish between scalable and fixed sized vectors explicitly.

 Ty.getSizeInBits() 

asserts for scalable vectors.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or put all vectors into the first if. The second is for > 64 bits.

Ty.getSizeInBits() > 64)
OpRegBankIdx[Idx] = PMI_FirstFPR;
else
Expand Down
Loading