Skip to content

Commit 794dc7a

Browse files
committed
[CodeGen] Split MVT::changeTypeToInteger() functionality from EVT::changeTypeToInteger().
Add the MVT equivalent handling for EVT changeTypeToInteger/changeVectorElementType/changeVectorElementTypeToInteger. All the SimpleVT code already exists inside the EVT equivalents, but by splitting this out we can use these directly inside MVT types without converting to/from EVT.
1 parent 088f3c8 commit 794dc7a

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

llvm/include/llvm/CodeGen/ValueTypes.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,17 @@ namespace llvm {
9292
/// with the element type converted to an integer type with the same
9393
/// bitwidth.
9494
EVT changeVectorElementTypeToInteger() const {
95-
if (!isSimple())
96-
return changeExtendedVectorElementTypeToInteger();
97-
MVT EltTy = getSimpleVT().getVectorElementType();
98-
unsigned BitWidth = EltTy.getSizeInBits();
99-
MVT IntTy = MVT::getIntegerVT(BitWidth);
100-
MVT VecTy = MVT::getVectorVT(IntTy, getVectorElementCount());
101-
assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
102-
"Simple vector VT not representable by simple integer vector VT!");
103-
return VecTy;
95+
if (isSimple())
96+
return getSimpleVT().changeVectorElementTypeToInteger();
97+
return changeExtendedVectorElementTypeToInteger();
10498
}
10599

106100
/// Return a VT for a vector type whose attributes match ourselves
107101
/// with the exception of the element type that is chosen by the caller.
108102
EVT changeVectorElementType(EVT EltVT) const {
109-
if (!isSimple())
110-
return changeExtendedVectorElementType(EltVT);
111-
MVT VecTy = MVT::getVectorVT(EltVT.V, getVectorElementCount());
112-
assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
113-
"Simple vector VT not representable by simple integer vector VT!");
114-
return VecTy;
103+
if (isSimple() && EltVT.isSimple())
104+
return getSimpleVT().changeVectorElementType(EltVT.getSimpleVT());
105+
return changeExtendedVectorElementType(EltVT);
115106
}
116107

117108
/// Return the type converted to an equivalently sized integer or vector
@@ -122,8 +113,7 @@ namespace llvm {
122113
return changeVectorElementTypeToInteger();
123114

124115
if (isSimple())
125-
return MVT::getIntegerVT(getSizeInBits());
126-
116+
return getSimpleVT().changeTypeToInteger();
127117
return changeExtendedTypeToInteger();
128118
}
129119

llvm/include/llvm/Support/MachineValueType.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,36 @@ namespace llvm {
425425
SimpleTy == MVT::iPTRAny);
426426
}
427427

428+
/// Return a vector with the same number of elements as this vector, but
429+
/// with the element type converted to an integer type with the same
430+
/// bitwidth.
431+
MVT changeVectorElementTypeToInteger() const {
432+
MVT EltTy = getVectorElementType();
433+
MVT IntTy = MVT::getIntegerVT(EltTy.getSizeInBits());
434+
MVT VecTy = MVT::getVectorVT(IntTy, getVectorElementCount());
435+
assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
436+
"Simple vector VT not representable by simple integer vector VT!");
437+
return VecTy;
438+
}
439+
440+
/// Return a VT for a vector type whose attributes match ourselves
441+
/// with the exception of the element type that is chosen by the caller.
442+
MVT changeVectorElementType(MVT EltVT) const {
443+
MVT VecTy = MVT::getVectorVT(EltVT, getVectorElementCount());
444+
assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
445+
"Simple vector VT not representable by simple integer vector VT!");
446+
return VecTy;
447+
}
448+
449+
/// Return the type converted to an equivalently sized integer or vector
450+
/// with integer element type. Similar to changeVectorElementTypeToInteger,
451+
/// but also handles scalars.
452+
MVT changeTypeToInteger() {
453+
if (isVector())
454+
return changeVectorElementTypeToInteger();
455+
return MVT::getIntegerVT(getSizeInBits());
456+
}
457+
428458
/// Return a VT for a vector type with the same element type but
429459
/// half the number of elements.
430460
MVT getHalfNumVectorElementsVT() const {

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34862,7 +34862,7 @@ static bool matchBinaryShuffle(MVT MaskVT, ArrayRef<int> Mask,
3486234862
DAG.computeKnownBits(V1, DemandedZeroV1).isZero() &&
3486334863
DAG.computeKnownBits(V2, DemandedZeroV2).isZero()) {
3486434864
Shuffle = ISD::OR;
34865-
SrcVT = DstVT = EVT(MaskVT).changeTypeToInteger().getSimpleVT();
34865+
SrcVT = DstVT = MaskVT.changeTypeToInteger();
3486634866
return true;
3486734867
}
3486834868
}

0 commit comments

Comments
 (0)