[SVE] Eliminate calls to default-false VectorType::get() from InstCombine

Reviewers: efriedma, david-arm, fpetrogalli, spatel

Reviewed By: david-arm

Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80334
This commit is contained in:
Christopher Tetreault 2020-05-29 15:24:15 -07:00
parent fbac9ce226
commit 8f8029b458
5 changed files with 26 additions and 19 deletions

View File

@ -839,7 +839,7 @@ static Value *simplifyX86extrq(IntrinsicInst &II, Value *Op0,
Index /= 8; Index /= 8;
Type *IntTy8 = Type::getInt8Ty(II.getContext()); Type *IntTy8 = Type::getInt8Ty(II.getContext());
VectorType *ShufTy = VectorType::get(IntTy8, 16); auto *ShufTy = FixedVectorType::get(IntTy8, 16);
SmallVector<int, 16> ShuffleMask; SmallVector<int, 16> ShuffleMask;
for (int i = 0; i != (int)Length; ++i) for (int i = 0; i != (int)Length; ++i)
@ -916,7 +916,7 @@ static Value *simplifyX86insertq(IntrinsicInst &II, Value *Op0, Value *Op1,
Index /= 8; Index /= 8;
Type *IntTy8 = Type::getInt8Ty(II.getContext()); Type *IntTy8 = Type::getInt8Ty(II.getContext());
VectorType *ShufTy = VectorType::get(IntTy8, 16); auto *ShufTy = FixedVectorType::get(IntTy8, 16);
SmallVector<int, 16> ShuffleMask; SmallVector<int, 16> ShuffleMask;
for (int i = 0; i != (int)Index; ++i) for (int i = 0; i != (int)Index; ++i)
@ -2849,8 +2849,9 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
// We don't need a select if we know the mask bit is a 1. // We don't need a select if we know the mask bit is a 1.
if (!C || !C->getValue()[0]) { if (!C || !C->getValue()[0]) {
// Cast the mask to an i1 vector and then extract the lowest element. // Cast the mask to an i1 vector and then extract the lowest element.
auto *MaskTy = VectorType::get(Builder.getInt1Ty(), auto *MaskTy = FixedVectorType::get(
cast<IntegerType>(Mask->getType())->getBitWidth()); Builder.getInt1Ty(),
cast<IntegerType>(Mask->getType())->getBitWidth());
Mask = Builder.CreateBitCast(Mask, MaskTy); Mask = Builder.CreateBitCast(Mask, MaskTy);
Mask = Builder.CreateExtractElement(Mask, (uint64_t)0); Mask = Builder.CreateExtractElement(Mask, (uint64_t)0);
// Extract the lowest element from the passthru operand. // Extract the lowest element from the passthru operand.

View File

@ -483,7 +483,7 @@ static Instruction *foldVecTruncToExtElt(TruncInst &Trunc, InstCombiner &IC) {
// bitcast it to a vector type that we can extract from. // bitcast it to a vector type that we can extract from.
unsigned NumVecElts = VecWidth / DestWidth; unsigned NumVecElts = VecWidth / DestWidth;
if (VecType->getElementType() != DestType) { if (VecType->getElementType() != DestType) {
VecType = VectorType::get(DestType, NumVecElts); VecType = FixedVectorType::get(DestType, NumVecElts);
VecInput = IC.Builder.CreateBitCast(VecInput, VecType, "bc"); VecInput = IC.Builder.CreateBitCast(VecInput, VecType, "bc");
} }
@ -870,7 +870,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
assert(BitCastNumElts <= std::numeric_limits<uint32_t>::max() && assert(BitCastNumElts <= std::numeric_limits<uint32_t>::max() &&
"overflow 32-bits"); "overflow 32-bits");
Type *BitCastTo = VectorType::get(DestTy, BitCastNumElts); auto *BitCastTo = FixedVectorType::get(DestTy, BitCastNumElts);
Value *BitCast = Builder.CreateBitCast(VecOp, BitCastTo); Value *BitCast = Builder.CreateBitCast(VecOp, BitCastTo);
return ExtractElementInst::Create(BitCast, Builder.getInt32(NewIdx)); return ExtractElementInst::Create(BitCast, Builder.getInt32(NewIdx));
} }
@ -1536,7 +1536,7 @@ static Type *shrinkFPConstantVector(Value *V) {
} }
// Make a vector type from the minimal type. // Make a vector type from the minimal type.
return VectorType::get(MinType, NumElts); return FixedVectorType::get(MinType, NumElts);
} }
/// Find the minimum FP type we can safely truncate to. /// Find the minimum FP type we can safely truncate to.
@ -1921,8 +1921,11 @@ Instruction *InstCombiner::visitPtrToInt(PtrToIntInst &CI) {
return commonPointerCastTransforms(CI); return commonPointerCastTransforms(CI);
Type *PtrTy = DL.getIntPtrType(CI.getContext(), AS); Type *PtrTy = DL.getIntPtrType(CI.getContext(), AS);
if (auto *VTy = dyn_cast<VectorType>(Ty)) // Handle vectors of pointers. if (auto *VTy = dyn_cast<VectorType>(Ty)) {
PtrTy = VectorType::get(PtrTy, VTy->getNumElements()); // Handle vectors of pointers.
// FIXME: what should happen for scalable vectors?
PtrTy = FixedVectorType::get(PtrTy, VTy->getNumElements());
}
Value *P = Builder.CreatePtrToInt(CI.getOperand(0), PtrTy); Value *P = Builder.CreatePtrToInt(CI.getOperand(0), PtrTy);
return CastInst::CreateIntegerCast(P, Ty, /*isSigned=*/false); return CastInst::CreateIntegerCast(P, Ty, /*isSigned=*/false);
@ -1961,7 +1964,8 @@ static Instruction *optimizeVectorResizeWithIntegerBitCasts(Value *InVal,
DestTy->getElementType()->getPrimitiveSizeInBits()) DestTy->getElementType()->getPrimitiveSizeInBits())
return nullptr; return nullptr;
SrcTy = VectorType::get(DestTy->getElementType(), SrcTy->getNumElements()); SrcTy =
FixedVectorType::get(DestTy->getElementType(), SrcTy->getNumElements());
InVal = IC.Builder.CreateBitCast(InVal, SrcTy); InVal = IC.Builder.CreateBitCast(InVal, SrcTy);
} }
@ -2187,7 +2191,7 @@ static Instruction *canonicalizeBitCastExtElt(BitCastInst &BitCast,
return nullptr; return nullptr;
unsigned NumElts = ExtElt->getVectorOperandType()->getNumElements(); unsigned NumElts = ExtElt->getVectorOperandType()->getNumElements();
auto *NewVecType = VectorType::get(DestType, NumElts); auto *NewVecType = FixedVectorType::get(DestType, NumElts);
auto *NewBC = IC.Builder.CreateBitCast(ExtElt->getVectorOperand(), auto *NewBC = IC.Builder.CreateBitCast(ExtElt->getVectorOperand(),
NewVecType, "bc"); NewVecType, "bc");
return ExtractElementInst::Create(NewBC, ExtElt->getIndexOperand()); return ExtractElementInst::Create(NewBC, ExtElt->getIndexOperand());
@ -2658,7 +2662,8 @@ Instruction *InstCombiner::visitAddrSpaceCast(AddrSpaceCastInst &CI) {
Type *MidTy = PointerType::get(DestElemTy, SrcTy->getAddressSpace()); Type *MidTy = PointerType::get(DestElemTy, SrcTy->getAddressSpace());
if (VectorType *VT = dyn_cast<VectorType>(CI.getType())) { if (VectorType *VT = dyn_cast<VectorType>(CI.getType())) {
// Handle vectors of pointers. // Handle vectors of pointers.
MidTy = VectorType::get(MidTy, VT->getNumElements()); // FIXME: what should happen for scalable vectors?
MidTy = FixedVectorType::get(MidTy, VT->getNumElements());
} }
Value *NewBitCast = Builder.CreateBitCast(Src, MidTy); Value *NewBitCast = Builder.CreateBitCast(Src, MidTy);

View File

@ -1862,7 +1862,7 @@ Instruction *InstCombiner::foldICmpAndConstant(ICmpInst &Cmp,
if (ExactLogBase2 != -1 && DL.isLegalInteger(ExactLogBase2 + 1)) { if (ExactLogBase2 != -1 && DL.isLegalInteger(ExactLogBase2 + 1)) {
Type *NTy = IntegerType::get(Cmp.getContext(), ExactLogBase2 + 1); Type *NTy = IntegerType::get(Cmp.getContext(), ExactLogBase2 + 1);
if (auto *AndVTy = dyn_cast<VectorType>(And->getType())) if (auto *AndVTy = dyn_cast<VectorType>(And->getType()))
NTy = VectorType::get(NTy, AndVTy->getNumElements()); NTy = FixedVectorType::get(NTy, AndVTy->getNumElements());
Value *Trunc = Builder.CreateTrunc(X, NTy); Value *Trunc = Builder.CreateTrunc(X, NTy);
auto NewPred = Cmp.getPredicate() == CmpInst::ICMP_EQ ? CmpInst::ICMP_SGE auto NewPred = Cmp.getPredicate() == CmpInst::ICMP_EQ ? CmpInst::ICMP_SGE
: CmpInst::ICMP_SLT; : CmpInst::ICMP_SLT;
@ -2152,7 +2152,7 @@ Instruction *InstCombiner::foldICmpShlConstant(ICmpInst &Cmp,
DL.isLegalInteger(TypeBits - Amt)) { DL.isLegalInteger(TypeBits - Amt)) {
Type *TruncTy = IntegerType::get(Cmp.getContext(), TypeBits - Amt); Type *TruncTy = IntegerType::get(Cmp.getContext(), TypeBits - Amt);
if (auto *ShVTy = dyn_cast<VectorType>(ShType)) if (auto *ShVTy = dyn_cast<VectorType>(ShType))
TruncTy = VectorType::get(TruncTy, ShVTy->getNumElements()); TruncTy = FixedVectorType::get(TruncTy, ShVTy->getNumElements());
Constant *NewC = Constant *NewC =
ConstantInt::get(TruncTy, C.ashr(*ShiftAmt).trunc(TypeBits - Amt)); ConstantInt::get(TruncTy, C.ashr(*ShiftAmt).trunc(TypeBits - Amt));
return new ICmpInst(Pred, Builder.CreateTrunc(X, TruncTy), NewC); return new ICmpInst(Pred, Builder.CreateTrunc(X, TruncTy), NewC);
@ -2785,7 +2785,7 @@ static Instruction *foldICmpBitCast(ICmpInst &Cmp,
Type *NewType = Builder.getIntNTy(XType->getScalarSizeInBits()); Type *NewType = Builder.getIntNTy(XType->getScalarSizeInBits());
if (auto *XVTy = dyn_cast<VectorType>(XType)) if (auto *XVTy = dyn_cast<VectorType>(XType))
NewType = VectorType::get(NewType, XVTy->getNumElements()); NewType = FixedVectorType::get(NewType, XVTy->getNumElements());
Value *NewBitcast = Builder.CreateBitCast(X, NewType); Value *NewBitcast = Builder.CreateBitCast(X, NewType);
if (TrueIfSigned) if (TrueIfSigned)
return new ICmpInst(ICmpInst::ICMP_SLT, NewBitcast, return new ICmpInst(ICmpInst::ICMP_SLT, NewBitcast,

View File

@ -1144,7 +1144,8 @@ Value *InstCombiner::simplifyAMDGCNMemoryIntrinsicDemanded(IntrinsicInst *II,
Module *M = II->getParent()->getParent()->getParent(); Module *M = II->getParent()->getParent()->getParent();
Type *EltTy = IIVTy->getElementType(); Type *EltTy = IIVTy->getElementType();
Type *NewTy = (NewNumElts == 1) ? EltTy : VectorType::get(EltTy, NewNumElts); Type *NewTy =
(NewNumElts == 1) ? EltTy : FixedVectorType::get(EltTy, NewNumElts);
OverloadTys[0] = NewTy; OverloadTys[0] = NewTy;
Function *NewIntrin = Intrinsic::getDeclaration(M, IID, OverloadTys); Function *NewIntrin = Intrinsic::getDeclaration(M, IID, OverloadTys);

View File

@ -1336,10 +1336,10 @@ static Value *evaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask) {
Type *EltTy = V->getType()->getScalarType(); Type *EltTy = V->getType()->getScalarType();
Type *I32Ty = IntegerType::getInt32Ty(V->getContext()); Type *I32Ty = IntegerType::getInt32Ty(V->getContext());
if (isa<UndefValue>(V)) if (isa<UndefValue>(V))
return UndefValue::get(VectorType::get(EltTy, Mask.size())); return UndefValue::get(FixedVectorType::get(EltTy, Mask.size()));
if (isa<ConstantAggregateZero>(V)) if (isa<ConstantAggregateZero>(V))
return ConstantAggregateZero::get(VectorType::get(EltTy, Mask.size())); return ConstantAggregateZero::get(FixedVectorType::get(EltTy, Mask.size()));
if (Constant *C = dyn_cast<Constant>(V)) if (Constant *C = dyn_cast<Constant>(V))
return ConstantExpr::getShuffleVector(C, UndefValue::get(C->getType()), return ConstantExpr::getShuffleVector(C, UndefValue::get(C->getType()),
@ -2131,7 +2131,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
continue; continue;
if (!VectorType::isValidElementType(TgtTy)) if (!VectorType::isValidElementType(TgtTy))
continue; continue;
VectorType *CastSrcTy = VectorType::get(TgtTy, TgtNumElems); auto *CastSrcTy = FixedVectorType::get(TgtTy, TgtNumElems);
if (!BegIsAligned) { if (!BegIsAligned) {
// Shuffle the input so [0,NumElements) contains the output, and // Shuffle the input so [0,NumElements) contains the output, and
// [NumElems,SrcNumElems) is undef. // [NumElems,SrcNumElems) is undef.