Skip to content

Commit d57515b

Browse files
authored
[LLT] Add and use isPointerVector and isPointerOrPointerVector. NFC. (llvm#81283)
1 parent 346e7c7 commit d57515b

File tree

9 files changed

+28
-30
lines changed

9 files changed

+28
-30
lines changed

llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ class LegalizeRuleSet {
10841084
},
10851085
[=](const LegalityQuery &Query) {
10861086
LLT T = Query.Types[LargeTypeIdx];
1087-
if (T.isVector() && T.getElementType().isPointer())
1087+
if (T.isPointerVector())
10881088
T = T.changeElementType(LLT::scalar(T.getScalarSizeInBits()));
10891089
return std::make_pair(TypeIdx, T);
10901090
});

llvm/include/llvm/CodeGenTypes/LowLevelType.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,17 @@ class LLT {
134134

135135
explicit LLT(MVT VT);
136136

137-
constexpr bool isValid() const { return IsScalar || RawData != 0; }
137+
constexpr bool isValid() const { return IsScalar || IsPointer || IsVector; }
138138

139139
constexpr bool isScalar() const { return IsScalar; }
140140

141-
constexpr bool isPointer() const {
142-
return isValid() && IsPointer && !IsVector;
143-
}
141+
constexpr bool isPointer() const { return IsPointer && !IsVector; }
142+
143+
constexpr bool isPointerVector() const { return IsPointer && IsVector; }
144+
145+
constexpr bool isPointerOrPointerVector() const { return IsPointer; }
144146

145-
constexpr bool isVector() const { return isValid() && IsVector; }
147+
constexpr bool isVector() const { return IsVector; }
146148

147149
/// Returns the number of elements in a vector LLT. Must only be called on
148150
/// vector types.
@@ -209,7 +211,7 @@ class LLT {
209211
/// but the new element size. Otherwise, return the new element type. Invalid
210212
/// for pointer types. For pointer types, use changeElementType.
211213
constexpr LLT changeElementSize(unsigned NewEltSize) const {
212-
assert(!getScalarType().isPointer() &&
214+
assert(!isPointerOrPointerVector() &&
213215
"invalid to directly change element size for pointers");
214216
return isVector() ? LLT::vector(getElementCount(), NewEltSize)
215217
: LLT::scalar(NewEltSize);

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,8 +1716,7 @@ Register LegalizerHelper::coerceToScalar(Register Val) {
17161716
Register NewVal = Val;
17171717

17181718
assert(Ty.isVector());
1719-
LLT EltTy = Ty.getElementType();
1720-
if (EltTy.isPointer())
1719+
if (Ty.isPointerVector())
17211720
NewVal = MIRBuilder.buildPtrToInt(NewTy, NewVal).getReg(0);
17221721
return MIRBuilder.buildBitcast(NewTy, NewVal).getReg(0);
17231722
}
@@ -7964,7 +7963,7 @@ LegalizerHelper::LegalizeResult LegalizerHelper::lowerSelect(MachineInstr &MI) {
79647963
auto [DstReg, DstTy, MaskReg, MaskTy, Op1Reg, Op1Ty, Op2Reg, Op2Ty] =
79657964
MI.getFirst4RegLLTs();
79667965

7967-
bool IsEltPtr = DstTy.getScalarType().isPointer();
7966+
bool IsEltPtr = DstTy.isPointerOrPointerVector();
79687967
if (IsEltPtr) {
79697968
LLT ScalarPtrTy = LLT::scalar(DstTy.getScalarSizeInBits());
79707969
LLT NewTy = DstTy.changeElementType(ScalarPtrTy);

llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void MachineIRBuilder::validateShiftOp(const LLT Res, const LLT Op0,
199199
MachineInstrBuilder
200200
MachineIRBuilder::buildPtrAdd(const DstOp &Res, const SrcOp &Op0,
201201
const SrcOp &Op1, std::optional<unsigned> Flags) {
202-
assert(Res.getLLTTy(*getMRI()).getScalarType().isPointer() &&
202+
assert(Res.getLLTTy(*getMRI()).isPointerOrPointerVector() &&
203203
Res.getLLTTy(*getMRI()) == Op0.getLLTTy(*getMRI()) && "type mismatch");
204204
assert(Op1.getLLTTy(*getMRI()).getScalarType().isScalar() && "invalid offset type");
205205

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,10 +1288,10 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
12881288
if (!DstTy.isValid() || !PtrTy.isValid() || !OffsetTy.isValid())
12891289
break;
12901290

1291-
if (!PtrTy.getScalarType().isPointer())
1291+
if (!PtrTy.isPointerOrPointerVector())
12921292
report("gep first operand must be a pointer", MI);
12931293

1294-
if (OffsetTy.getScalarType().isPointer())
1294+
if (OffsetTy.isPointerOrPointerVector())
12951295
report("gep offset operand must not be a pointer", MI);
12961296

12971297
// TODO: Is the offset allowed to be a scalar with a vector?
@@ -1304,7 +1304,7 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
13041304
if (!DstTy.isValid() || !SrcTy.isValid() || !MaskTy.isValid())
13051305
break;
13061306

1307-
if (!DstTy.getScalarType().isPointer())
1307+
if (!DstTy.isPointerOrPointerVector())
13081308
report("ptrmask result type must be a pointer", MI);
13091309

13101310
if (!MaskTy.getScalarType().isScalar())
@@ -1330,15 +1330,13 @@ void MachineVerifier::verifyPreISelGenericInstruction(const MachineInstr *MI) {
13301330
if (!DstTy.isValid() || !SrcTy.isValid())
13311331
break;
13321332

1333-
LLT DstElTy = DstTy.getScalarType();
1334-
LLT SrcElTy = SrcTy.getScalarType();
1335-
if (DstElTy.isPointer() || SrcElTy.isPointer())
1333+
if (DstTy.isPointerOrPointerVector() || SrcTy.isPointerOrPointerVector())
13361334
report("Generic extend/truncate can not operate on pointers", MI);
13371335

13381336
verifyVectorElementMatch(DstTy, SrcTy, MI);
13391337

1340-
unsigned DstSize = DstElTy.getSizeInBits();
1341-
unsigned SrcSize = SrcElTy.getSizeInBits();
1338+
unsigned DstSize = DstTy.getScalarSizeInBits();
1339+
unsigned SrcSize = SrcTy.getScalarSizeInBits();
13421340
switch (MI->getOpcode()) {
13431341
default:
13441342
if (DstSize <= SrcSize)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ bool AArch64InstructionSelector::preISelLower(MachineInstr &I) {
20912091
case AArch64::G_DUP: {
20922092
// Convert the type from p0 to s64 to help selection.
20932093
LLT DstTy = MRI.getType(I.getOperand(0).getReg());
2094-
if (!DstTy.getElementType().isPointer())
2094+
if (!DstTy.isPointerVector())
20952095
return false;
20962096
auto NewSrc = MIB.buildCopy(LLT::scalar(64), I.getOperand(1).getReg());
20972097
MRI.setType(I.getOperand(0).getReg(),

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
343343

344344
auto IsPtrVecPred = [=](const LegalityQuery &Query) {
345345
const LLT &ValTy = Query.Types[0];
346-
if (!ValTy.isVector())
347-
return false;
348-
const LLT EltTy = ValTy.getElementType();
349-
return EltTy.isPointer() && EltTy.getAddressSpace() == 0;
346+
return ValTy.isPointerVector() && ValTy.getAddressSpace() == 0;
350347
};
351348

352349
getActionDefinitionsBuilder(G_LOAD)
@@ -521,7 +518,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
521518
[=](const LegalityQuery &Query) {
522519
const LLT &Ty = Query.Types[0];
523520
const LLT &SrcTy = Query.Types[1];
524-
return Ty.isVector() && !SrcTy.getElementType().isPointer() &&
521+
return Ty.isVector() && !SrcTy.isPointerVector() &&
525522
Ty.getElementType() != SrcTy.getElementType();
526523
},
527524
0, 1)
@@ -555,7 +552,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
555552
[=](const LegalityQuery &Query) {
556553
const LLT &Ty = Query.Types[0];
557554
const LLT &SrcTy = Query.Types[1];
558-
return Ty.isVector() && !SrcTy.getElementType().isPointer() &&
555+
return Ty.isVector() && !SrcTy.isPointerVector() &&
559556
Ty.getElementType() != SrcTy.getElementType();
560557
},
561558
0, 1)
@@ -1649,7 +1646,7 @@ bool AArch64LegalizerInfo::legalizeLoadStore(
16491646
return true;
16501647
}
16511648

1652-
if (!ValTy.isVector() || !ValTy.getElementType().isPointer() ||
1649+
if (!ValTy.isPointerVector() ||
16531650
ValTy.getElementType().getAddressSpace() != 0) {
16541651
LLVM_DEBUG(dbgs() << "Tried to do custom legalization on wrong load/store");
16551652
return false;

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,10 @@ static bool loadStoreBitcastWorkaround(const LLT Ty) {
498498
if (!Ty.isVector())
499499
return true;
500500

501-
LLT EltTy = Ty.getElementType();
502-
if (EltTy.isPointer())
501+
if (Ty.isPointerVector())
503502
return true;
504503

505-
unsigned EltSize = EltTy.getSizeInBits();
504+
unsigned EltSize = Ty.getScalarSizeInBits();
506505
return EltSize != 32 && EltSize != 64;
507506
}
508507

llvm/unittests/CodeGen/LowLevelTypeTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,16 @@ TEST(LowLevelTypeTest, Pointer) {
259259
// Test kind.
260260
ASSERT_TRUE(Ty.isValid());
261261
ASSERT_TRUE(Ty.isPointer());
262+
ASSERT_TRUE(Ty.isPointerOrPointerVector());
262263

263264
ASSERT_FALSE(Ty.isScalar());
264265
ASSERT_FALSE(Ty.isVector());
265266

266267
ASSERT_TRUE(VTy.isValid());
267268
ASSERT_TRUE(VTy.isVector());
268269
ASSERT_TRUE(VTy.getElementType().isPointer());
270+
ASSERT_TRUE(VTy.isPointerVector());
271+
ASSERT_TRUE(VTy.isPointerOrPointerVector());
269272

270273
EXPECT_EQ(Ty, VTy.getElementType());
271274
EXPECT_EQ(Ty.getSizeInBits(), VTy.getScalarSizeInBits());

0 commit comments

Comments
 (0)