mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-13 08:56:04 +00:00
[IR] Add Type::isIntOrIntVectorTy(unsigned) similar to the existing isIntegerTy(unsigned), but also works for vectors.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307492 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1060082924
commit
eb41f6a345
@ -202,6 +202,12 @@ public:
|
||||
/// Return true if this is an integer type or a vector of integer types.
|
||||
bool isIntOrIntVectorTy() const { return getScalarType()->isIntegerTy(); }
|
||||
|
||||
/// Return true if this is an integer type or a vector of integer types of
|
||||
/// the given width.
|
||||
bool isIntOrIntVectorTy(unsigned BitWidth) const {
|
||||
return getScalarType()->isIntegerTy(BitWidth);
|
||||
}
|
||||
|
||||
/// True if this is an instance of FunctionType.
|
||||
bool isFunctionTy() const { return getTypeID() == FunctionTyID; }
|
||||
|
||||
|
@ -560,7 +560,7 @@ static Value *SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
|
||||
return Y;
|
||||
|
||||
/// i1 add -> xor.
|
||||
if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1))
|
||||
if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
|
||||
if (Value *V = SimplifyXorInst(Op0, Op1, Q, MaxRecurse-1))
|
||||
return V;
|
||||
|
||||
@ -770,7 +770,7 @@ static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
|
||||
return ConstantExpr::getIntegerCast(Result, Op0->getType(), true);
|
||||
|
||||
// i1 sub -> xor.
|
||||
if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1))
|
||||
if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
|
||||
if (Value *V = SimplifyXorInst(Op0, Op1, Q, MaxRecurse-1))
|
||||
return V;
|
||||
|
||||
@ -901,7 +901,7 @@ static Value *SimplifyMulInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
|
||||
return X;
|
||||
|
||||
// i1 mul -> and.
|
||||
if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1))
|
||||
if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
|
||||
if (Value *V = SimplifyAndInst(Op0, Op1, Q, MaxRecurse-1))
|
||||
return V;
|
||||
|
||||
@ -997,7 +997,7 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv) {
|
||||
// X % 1 -> 0
|
||||
// If this is a boolean op (single-bit element type), we can't have
|
||||
// division-by-zero or remainder-by-zero, so assume the divisor is 1.
|
||||
if (match(Op1, m_One()) || Ty->getScalarType()->isIntegerTy(1))
|
||||
if (match(Op1, m_One()) || Ty->isIntOrIntVectorTy(1))
|
||||
return IsDiv ? Op0 : Constant::getNullValue(Ty);
|
||||
|
||||
return nullptr;
|
||||
@ -2250,7 +2250,7 @@ static Value *simplifyICmpOfBools(CmpInst::Predicate Pred, Value *LHS,
|
||||
Value *RHS, const SimplifyQuery &Q) {
|
||||
Type *ITy = GetCompareTy(LHS); // The return type.
|
||||
Type *OpTy = LHS->getType(); // The operand type.
|
||||
if (!OpTy->getScalarType()->isIntegerTy(1))
|
||||
if (!OpTy->isIntOrIntVectorTy(1))
|
||||
return nullptr;
|
||||
|
||||
// A boolean compared to true/false can be simplified in 14 out of the 20
|
||||
|
@ -1500,12 +1500,10 @@ void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth,
|
||||
assert(Depth <= MaxDepth && "Limit Search Depth");
|
||||
unsigned BitWidth = Known.getBitWidth();
|
||||
|
||||
assert((V->getType()->isIntOrIntVectorTy() ||
|
||||
assert((V->getType()->isIntOrIntVectorTy(BitWidth) ||
|
||||
V->getType()->isPtrOrPtrVectorTy()) &&
|
||||
"Not integer or pointer type!");
|
||||
assert((Q.DL.getTypeSizeInBits(V->getType()->getScalarType()) == BitWidth) &&
|
||||
(!V->getType()->isIntOrIntVectorTy() ||
|
||||
V->getType()->getScalarSizeInBits() == BitWidth) &&
|
||||
assert(Q.DL.getTypeSizeInBits(V->getType()->getScalarType()) == BitWidth &&
|
||||
"V and Known should have same BitWidth");
|
||||
(void)BitWidth;
|
||||
|
||||
@ -4402,7 +4400,7 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
|
||||
return None;
|
||||
|
||||
Type *OpTy = LHS->getType();
|
||||
assert(OpTy->getScalarType()->isIntegerTy(1));
|
||||
assert(OpTy->isIntOrIntVectorTy(1));
|
||||
|
||||
// LHS ==> RHS by definition
|
||||
if (LHS == RHS)
|
||||
|
@ -512,7 +512,7 @@ ConstantInt *ConstantInt::getFalse(LLVMContext &Context) {
|
||||
}
|
||||
|
||||
Constant *ConstantInt::getTrue(Type *Ty) {
|
||||
assert(Ty->getScalarType()->isIntegerTy(1) && "Type not i1 or vector of i1.");
|
||||
assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
|
||||
ConstantInt *TrueC = ConstantInt::getTrue(Ty->getContext());
|
||||
if (auto *VTy = dyn_cast<VectorType>(Ty))
|
||||
return ConstantVector::getSplat(VTy->getNumElements(), TrueC);
|
||||
@ -520,7 +520,7 @@ Constant *ConstantInt::getTrue(Type *Ty) {
|
||||
}
|
||||
|
||||
Constant *ConstantInt::getFalse(Type *Ty) {
|
||||
assert(Ty->getScalarType()->isIntegerTy(1) && "Type not i1 or vector of i1.");
|
||||
assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
|
||||
ConstantInt *FalseC = ConstantInt::getFalse(Ty->getContext());
|
||||
if (auto *VTy = dyn_cast<VectorType>(Ty))
|
||||
return ConstantVector::getSplat(VTy->getNumElements(), FalseC);
|
||||
|
@ -538,7 +538,7 @@ bool CompositeType::indexValid(const Value *V) const {
|
||||
if (auto *STy = dyn_cast<StructType>(this)) {
|
||||
// Structure indexes require (vectors of) 32-bit integer constants. In the
|
||||
// vector case all of the indices must be equal.
|
||||
if (!V->getType()->getScalarType()->isIntegerTy(32))
|
||||
if (!V->getType()->isIntOrIntVectorTy(32))
|
||||
return false;
|
||||
const Constant *C = dyn_cast<Constant>(V);
|
||||
if (C && V->getType()->isVectorTy())
|
||||
|
@ -779,8 +779,7 @@ int SystemZTTIImpl::
|
||||
getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) {
|
||||
// vlvgp will insert two grs into a vector register, so only count half the
|
||||
// number of instructions.
|
||||
if (Opcode == Instruction::InsertElement &&
|
||||
Val->getScalarType()->isIntegerTy(64))
|
||||
if (Opcode == Instruction::InsertElement && Val->isIntOrIntVectorTy(64))
|
||||
return ((Index % 2 == 0) ? 1 : 0);
|
||||
|
||||
if (Opcode == Instruction::ExtractElement) {
|
||||
|
@ -1084,7 +1084,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
||||
if (Instruction *NV = foldOpWithConstantIntoOperand(I))
|
||||
return NV;
|
||||
|
||||
if (I.getType()->getScalarType()->isIntegerTy(1))
|
||||
if (I.getType()->isIntOrIntVectorTy(1))
|
||||
return BinaryOperator::CreateXor(LHS, RHS);
|
||||
|
||||
// X + X --> X << 1
|
||||
@ -1520,7 +1520,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
return Res;
|
||||
}
|
||||
|
||||
if (I.getType()->getScalarType()->isIntegerTy(1))
|
||||
if (I.getType()->isIntOrIntVectorTy(1))
|
||||
return BinaryOperator::CreateXor(Op0, Op1);
|
||||
|
||||
// Replace (-1 - A) with (~A).
|
||||
@ -1550,12 +1550,12 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
|
||||
// Fold (sub 0, (zext bool to B)) --> (sext bool to B)
|
||||
if (C->isNullValue() && match(Op1, m_ZExt(m_Value(X))))
|
||||
if (X->getType()->getScalarType()->isIntegerTy(1))
|
||||
if (X->getType()->isIntOrIntVectorTy(1))
|
||||
return CastInst::CreateSExtOrBitCast(X, Op1->getType());
|
||||
|
||||
// Fold (sub 0, (sext bool to B)) --> (zext bool to B)
|
||||
if (C->isNullValue() && match(Op1, m_SExt(m_Value(X))))
|
||||
if (X->getType()->getScalarType()->isIntegerTy(1))
|
||||
if (X->getType()->isIntOrIntVectorTy(1))
|
||||
return CastInst::CreateZExtOrBitCast(X, Op1->getType());
|
||||
}
|
||||
|
||||
|
@ -1188,15 +1188,14 @@ static Instruction *foldBoolSextMaskToSelect(BinaryOperator &I) {
|
||||
|
||||
// Fold (and (sext bool to A), B) --> (select bool, B, 0)
|
||||
Value *X = nullptr;
|
||||
if (match(Op0, m_SExt(m_Value(X))) &&
|
||||
X->getType()->getScalarType()->isIntegerTy(1)) {
|
||||
if (match(Op0, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
|
||||
Value *Zero = Constant::getNullValue(Op1->getType());
|
||||
return SelectInst::Create(X, Op1, Zero);
|
||||
}
|
||||
|
||||
// Fold (and ~(sext bool to A), B) --> (select bool, 0, B)
|
||||
if (match(Op0, m_Not(m_SExt(m_Value(X)))) &&
|
||||
X->getType()->getScalarType()->isIntegerTy(1)) {
|
||||
X->getType()->isIntOrIntVectorTy(1)) {
|
||||
Value *Zero = Constant::getNullValue(Op0->getType());
|
||||
return SelectInst::Create(X, Zero, Op1);
|
||||
}
|
||||
@ -1559,14 +1558,14 @@ static Value *getSelectCondition(Value *A, Value *B,
|
||||
InstCombiner::BuilderTy &Builder) {
|
||||
// If these are scalars or vectors of i1, A can be used directly.
|
||||
Type *Ty = A->getType();
|
||||
if (match(A, m_Not(m_Specific(B))) && Ty->getScalarType()->isIntegerTy(1))
|
||||
if (match(A, m_Not(m_Specific(B))) && Ty->isIntOrIntVectorTy(1))
|
||||
return A;
|
||||
|
||||
// If A and B are sign-extended, look through the sexts to find the booleans.
|
||||
Value *Cond;
|
||||
Value *NotB;
|
||||
if (match(A, m_SExt(m_Value(Cond))) &&
|
||||
Cond->getType()->getScalarType()->isIntegerTy(1) &&
|
||||
Cond->getType()->isIntOrIntVectorTy(1) &&
|
||||
match(B, m_OneUse(m_Not(m_Value(NotB))))) {
|
||||
NotB = peekThroughBitcast(NotB, true);
|
||||
if (match(NotB, m_SExt(m_Specific(Cond))))
|
||||
@ -1588,7 +1587,7 @@ static Value *getSelectCondition(Value *A, Value *B,
|
||||
// operand, see if the constants are inverse bitmasks.
|
||||
if (match(A, (m_Xor(m_SExt(m_Value(Cond)), m_Constant(AC)))) &&
|
||||
match(B, (m_Xor(m_SExt(m_Specific(Cond)), m_Constant(BC)))) &&
|
||||
Cond->getType()->getScalarType()->isIntegerTy(1) &&
|
||||
Cond->getType()->isIntOrIntVectorTy(1) &&
|
||||
areInverseVectorBitmasks(AC, BC)) {
|
||||
AC = ConstantExpr::getTrunc(AC, CmpInst::makeCmpResultType(Ty));
|
||||
return Builder.CreateXor(Cond, AC);
|
||||
@ -2230,10 +2229,10 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||
|
||||
// or(sext(A), B) / or(B, sext(A)) --> A ? -1 : B, where A is i1 or <N x i1>.
|
||||
if (match(Op0, m_OneUse(m_SExt(m_Value(A)))) &&
|
||||
A->getType()->getScalarType()->isIntegerTy(1))
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op1);
|
||||
if (match(Op1, m_OneUse(m_SExt(m_Value(A)))) &&
|
||||
A->getType()->getScalarType()->isIntegerTy(1))
|
||||
A->getType()->isIntOrIntVectorTy(1))
|
||||
return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op0);
|
||||
|
||||
// Note: If we've gotten to the point of visiting the outer OR, then the
|
||||
|
@ -4371,7 +4371,7 @@ static ICmpInst *canonicalizeCmpWithConstant(ICmpInst &I) {
|
||||
static Instruction *canonicalizeICmpBool(ICmpInst &I,
|
||||
InstCombiner::BuilderTy &Builder) {
|
||||
Value *A = I.getOperand(0), *B = I.getOperand(1);
|
||||
assert(A->getType()->getScalarType()->isIntegerTy(1) && "Bools only");
|
||||
assert(A->getType()->isIntOrIntVectorTy(1) && "Bools only");
|
||||
|
||||
// A boolean compared to true/false can be simplified to Op0/true/false in
|
||||
// 14 out of the 20 (10 predicates * 2 constants) possible combinations.
|
||||
@ -4478,7 +4478,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Op0->getType()->getScalarType()->isIntegerTy(1))
|
||||
if (Op0->getType()->isIntOrIntVectorTy(1))
|
||||
if (Instruction *Res = canonicalizeICmpBool(I, Builder))
|
||||
return Res;
|
||||
|
||||
|
@ -326,7 +326,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
}
|
||||
|
||||
/// i1 mul -> i1 and.
|
||||
if (I.getType()->getScalarType()->isIntegerTy(1))
|
||||
if (I.getType()->isIntOrIntVectorTy(1))
|
||||
return BinaryOperator::CreateAnd(Op0, Op1);
|
||||
|
||||
// X*(1 << Y) --> X << Y
|
||||
@ -938,8 +938,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
|
||||
}
|
||||
|
||||
if (match(Op0, m_One())) {
|
||||
assert(!I.getType()->getScalarType()->isIntegerTy(1) &&
|
||||
"i1 divide not removed?");
|
||||
assert(!I.getType()->isIntOrIntVectorTy(1) && "i1 divide not removed?");
|
||||
if (I.getOpcode() == Instruction::SDiv) {
|
||||
// If Op1 is 0 then it's undefined behaviour, if Op1 is 1 then the
|
||||
// result is one, if Op1 is -1 then the result is minus one, otherwise
|
||||
|
@ -1021,7 +1021,7 @@ Instruction *InstCombiner::foldSelectExtConst(SelectInst &Sel) {
|
||||
// TODO: Handle larger types? That requires adjusting FoldOpIntoSelect too.
|
||||
Value *X = ExtInst->getOperand(0);
|
||||
Type *SmallType = X->getType();
|
||||
if (!SmallType->getScalarType()->isIntegerTy(1))
|
||||
if (!SmallType->isIntOrIntVectorTy(1))
|
||||
return nullptr;
|
||||
|
||||
Constant *C;
|
||||
@ -1181,7 +1181,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
return &SI;
|
||||
}
|
||||
|
||||
if (SelType->getScalarType()->isIntegerTy(1) &&
|
||||
if (SelType->isIntOrIntVectorTy(1) &&
|
||||
TrueVal->getType() == CondVal->getType()) {
|
||||
if (match(TrueVal, m_One())) {
|
||||
// Change: A = select B, true, C --> A = or B, C
|
||||
|
@ -790,7 +790,7 @@ Instruction *InstCombiner::FoldOpIntoSelect(Instruction &Op, SelectInst *SI) {
|
||||
return nullptr;
|
||||
|
||||
// Bool selects with constant operands can be folded to logical ops.
|
||||
if (SI->getType()->getScalarType()->isIntegerTy(1))
|
||||
if (SI->getType()->isIntOrIntVectorTy(1))
|
||||
return nullptr;
|
||||
|
||||
// If it's a bitcast involving vectors, make sure it has the same number of
|
||||
|
Loading…
x
Reference in New Issue
Block a user