Skip to content

[GlobalSel][NFC] Remove LLT initializers taking scalar sizes #119725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions llvm/include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,12 @@ class LLVM_ABI MachineFunction {
int64_t Offset, LLT Ty);
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
int64_t Offset, LocationSize Size) {
return getMachineMemOperand(
MMO, Offset,
!Size.hasValue() ? LLT()
: Size.isScalable()
? LLT::scalable_vector(1, 8 * Size.getValue().getKnownMinValue())
: LLT::scalar(8 * Size.getValue().getKnownMinValue()));
if (!Size.hasValue())
return getMachineMemOperand(MMO, Offset, LLT());

ElementCount EC = ElementCount::get(1, Size.isScalable());
LLT Ty = LLT::scalar(8 * Size.getValue().getKnownMinValue());
return getMachineMemOperand(MMO, Offset, LLT::scalarOrVector(EC, Ty));
}
MachineMemOperand *getMachineMemOperand(const MachineMemOperand *MMO,
int64_t Offset, uint64_t Size) {
Expand Down
37 changes: 0 additions & 37 deletions llvm/include/llvm/CodeGenTypes/LowLevelType.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ class LLT {
ElementCount::getFixed(0), SizeInBits, AddressSpace};
}

/// Get a low-level vector of some number of elements and element width.
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits) {
assert(!EC.isScalar() && "invalid number of vector elements");
return LLT{/*isPointer=*/false, /*isVector=*/true, /*isScalar=*/false,
EC, ScalarSizeInBits, /*AddressSpace=*/0};
}

/// Get a low-level vector of some number of elements and element type.
static constexpr LLT vector(ElementCount EC, LLT ScalarTy) {
assert(!EC.isScalar() && "invalid number of vector elements");
Expand Down Expand Up @@ -95,26 +88,12 @@ class LLT {
return scalar(64);
}

/// Get a low-level fixed-width vector of some number of elements and element
/// width.
static constexpr LLT fixed_vector(unsigned NumElements,
unsigned ScalarSizeInBits) {
return vector(ElementCount::getFixed(NumElements), ScalarSizeInBits);
}

/// Get a low-level fixed-width vector of some number of elements and element
/// type.
static constexpr LLT fixed_vector(unsigned NumElements, LLT ScalarTy) {
return vector(ElementCount::getFixed(NumElements), ScalarTy);
}

/// Get a low-level scalable vector of some number of elements and element
/// width.
static constexpr LLT scalable_vector(unsigned MinNumElements,
unsigned ScalarSizeInBits) {
return vector(ElementCount::getScalable(MinNumElements), ScalarSizeInBits);
}

/// Get a low-level scalable vector of some number of elements and element
/// type.
static constexpr LLT scalable_vector(unsigned MinNumElements, LLT ScalarTy) {
Expand All @@ -125,12 +104,6 @@ class LLT {
return EC.isScalar() ? ScalarTy : LLT::vector(EC, ScalarTy);
}

static constexpr LLT scalarOrVector(ElementCount EC, uint64_t ScalarSize) {
assert(ScalarSize <= std::numeric_limits<unsigned>::max() &&
"Not enough bits in LLT to represent size");
return scalarOrVector(EC, LLT::scalar(static_cast<unsigned>(ScalarSize)));
}

explicit constexpr LLT(bool isPointer, bool isVector, bool isScalar,
ElementCount EC, uint64_t SizeInBits,
unsigned AddressSpace)
Expand Down Expand Up @@ -215,16 +188,6 @@ class LLT {
return isVector() ? LLT::vector(getElementCount(), NewEltTy) : NewEltTy;
}

/// If this type is a vector, return a vector with the same number of elements
/// but the new element size. Otherwise, return the new element type. Invalid
/// for pointer types. For pointer types, use changeElementType.
constexpr LLT changeElementSize(unsigned NewEltSize) const {
assert(!isPointerOrPointerVector() &&
"invalid to directly change element size for pointers");
return isVector() ? LLT::vector(getElementCount(), NewEltSize)
: LLT::scalar(NewEltSize);
}

/// Return a vector or scalar with the same element type and the new element
/// count.
constexpr LLT changeElementCount(ElementCount EC) const {
Expand Down
13 changes: 5 additions & 8 deletions llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,7 @@ static LLT getMidVTForTruncRightShiftCombine(LLT ShiftTy, LLT TruncTy) {

// ShiftTy > 32 > TruncTy -> 32
if (ShiftSize > 32 && TruncSize < 32)
return ShiftTy.changeElementSize(32);
return ShiftTy.changeElementType(LLT::scalar(32));

// TODO: We could also reduce to 16 bits, but that's more target-dependent.
// Some targets like it, some don't, some only like it under certain
Expand Down Expand Up @@ -5361,9 +5361,8 @@ MachineInstr *CombinerHelper::buildUDivUsingMul(MachineInstr &MI) {

Q = MIB.buildLShr(Ty, Q, PostShift).getReg(0);
auto One = MIB.buildConstant(Ty, 1);
auto IsOne = MIB.buildICmp(
CmpInst::Predicate::ICMP_EQ,
Ty.isScalar() ? LLT::scalar(1) : Ty.changeElementSize(1), RHS, One);
auto IsOne = MIB.buildICmp(CmpInst::Predicate::ICMP_EQ,
Ty.changeElementType(LLT::scalar(1)), RHS, One);
return MIB.buildSelect(Ty, IsOne, LHS, Q);
}

Expand Down Expand Up @@ -5402,8 +5401,7 @@ bool CombinerHelper::matchUDivByConst(MachineInstr &MI) {
return false;
if (!isLegalOrBeforeLegalizer(
{TargetOpcode::G_ICMP,
{DstTy.isVector() ? DstTy.changeElementSize(1) : LLT::scalar(1),
DstTy}}))
{DstTy.changeElementType(LLT::scalar(1)), DstTy}}))
return false;
}

Expand Down Expand Up @@ -5535,8 +5533,7 @@ void CombinerHelper::applySDivByPow2(MachineInstr &MI) {
Register RHS = SDiv.getReg(2);
LLT Ty = MRI.getType(Dst);
LLT ShiftAmtTy = getTargetLowering().getPreferredShiftAmountTy(Ty);
LLT CCVT =
Ty.isVector() ? LLT::vector(Ty.getElementCount(), 1) : LLT::scalar(1);
LLT CCVT = Ty.changeElementType(LLT::scalar(1));

// Effectively we want to lower G_SDIV %lhs, %rhs, where %rhs is a power of 2,
// to the following version:
Expand Down
16 changes: 7 additions & 9 deletions llvm/lib/CodeGen/GlobalISel/LegacyLegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,22 @@ LegacyLegalizerInfo::findVectorLegalAction(const InstrAspect &Aspect) const {
ScalarInVectorActions[OpcodeIdx][TypeIdx];

LLT IntermediateType;
auto ElementSizeAndAction =
auto &&[ElementSize, Action1] =
findAction(ElemSizeVec, Aspect.Type.getScalarSizeInBits());
IntermediateType = LLT::fixed_vector(Aspect.Type.getNumElements(),
ElementSizeAndAction.first);
if (ElementSizeAndAction.second != Legal)
return {ElementSizeAndAction.second, IntermediateType};
IntermediateType = Aspect.Type.changeElementType(LLT::scalar(ElementSize));
if (Action1 != Legal)
return {Action1, IntermediateType};

auto i = NumElements2Actions[OpcodeIdx].find(
IntermediateType.getScalarSizeInBits());
if (i == NumElements2Actions[OpcodeIdx].end()) {
return {NotFound, IntermediateType};
}
const SizeAndActionsVec &NumElementsVec = (*i).second[TypeIdx];
auto NumElementsAndAction =
auto &&[NumElements, Action2] =
findAction(NumElementsVec, IntermediateType.getNumElements());
return {NumElementsAndAction.second,
LLT::fixed_vector(NumElementsAndAction.first,
IntermediateType.getScalarSizeInBits())};
return {Action2,
LLT::fixed_vector(NumElements, IntermediateType.getScalarType())};
}

unsigned LegacyLegalizerInfo::getOpcodeIdxForOpcode(unsigned Opcode) const {
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/LegalizeMutations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ LegalizeMutation LegalizeMutations::widenScalarOrEltToNextPow2(unsigned TypeIdx,
const LLT Ty = Query.Types[TypeIdx];
unsigned NewEltSizeInBits =
std::max(1u << Log2_32_Ceil(Ty.getScalarSizeInBits()), Min);
return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
return std::make_pair(TypeIdx,
Ty.changeElementType(LLT::scalar(NewEltSizeInBits)));
};
}

Expand All @@ -90,7 +91,8 @@ LegalizeMutations::widenScalarOrEltToNextMultipleOf(unsigned TypeIdx,
return [=](const LegalityQuery &Query) {
const LLT Ty = Query.Types[TypeIdx];
unsigned NewEltSizeInBits = alignTo(Ty.getScalarSizeInBits(), Size);
return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
return std::make_pair(TypeIdx,
Ty.changeElementType(LLT::scalar(NewEltSizeInBits)));
};
}

Expand Down
Loading
Loading