llvm.org GIT mirror llvm / eb41f6a
[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 Craig Topper 3 years ago
12 changed file(s) with 36 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
200200
201201 /// Return true if this is an integer type or a vector of integer types.
202202 bool isIntOrIntVectorTy() const { return getScalarType()->isIntegerTy(); }
203
204 /// Return true if this is an integer type or a vector of integer types of
205 /// the given width.
206 bool isIntOrIntVectorTy(unsigned BitWidth) const {
207 return getScalarType()->isIntegerTy(BitWidth);
208 }
203209
204210 /// True if this is an instance of FunctionType.
205211 bool isFunctionTy() const { return getTypeID() == FunctionTyID; }
559559 return Y;
560560
561561 /// i1 add -> xor.
562 if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1))
562 if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
563563 if (Value *V = SimplifyXorInst(Op0, Op1, Q, MaxRecurse-1))
564564 return V;
565565
769769 return ConstantExpr::getIntegerCast(Result, Op0->getType(), true);
770770
771771 // i1 sub -> xor.
772 if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1))
772 if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
773773 if (Value *V = SimplifyXorInst(Op0, Op1, Q, MaxRecurse-1))
774774 return V;
775775
900900 return X;
901901
902902 // i1 mul -> and.
903 if (MaxRecurse && Op0->getType()->getScalarType()->isIntegerTy(1))
903 if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
904904 if (Value *V = SimplifyAndInst(Op0, Op1, Q, MaxRecurse-1))
905905 return V;
906906
996996 // X % 1 -> 0
997997 // If this is a boolean op (single-bit element type), we can't have
998998 // division-by-zero or remainder-by-zero, so assume the divisor is 1.
999 if (match(Op1, m_One()) || Ty->getScalarType()->isIntegerTy(1))
999 if (match(Op1, m_One()) || Ty->isIntOrIntVectorTy(1))
10001000 return IsDiv ? Op0 : Constant::getNullValue(Ty);
10011001
10021002 return nullptr;
22492249 Value *RHS, const SimplifyQuery &Q) {
22502250 Type *ITy = GetCompareTy(LHS); // The return type.
22512251 Type *OpTy = LHS->getType(); // The operand type.
2252 if (!OpTy->getScalarType()->isIntegerTy(1))
2252 if (!OpTy->isIntOrIntVectorTy(1))
22532253 return nullptr;
22542254
22552255 // A boolean compared to true/false can be simplified in 14 out of the 20
14991499 assert(Depth <= MaxDepth && "Limit Search Depth");
15001500 unsigned BitWidth = Known.getBitWidth();
15011501
1502 assert((V->getType()->isIntOrIntVectorTy() ||
1502 assert((V->getType()->isIntOrIntVectorTy(BitWidth) ||
15031503 V->getType()->isPtrOrPtrVectorTy()) &&
15041504 "Not integer or pointer type!");
1505 assert((Q.DL.getTypeSizeInBits(V->getType()->getScalarType()) == BitWidth) &&
1506 (!V->getType()->isIntOrIntVectorTy() ||
1507 V->getType()->getScalarSizeInBits() == BitWidth) &&
1505 assert(Q.DL.getTypeSizeInBits(V->getType()->getScalarType()) == BitWidth &&
15081506 "V and Known should have same BitWidth");
15091507 (void)BitWidth;
15101508
44014399 return None;
44024400
44034401 Type *OpTy = LHS->getType();
4404 assert(OpTy->getScalarType()->isIntegerTy(1));
4402 assert(OpTy->isIntOrIntVectorTy(1));
44054403
44064404 // LHS ==> RHS by definition
44074405 if (LHS == RHS)
511511 }
512512
513513 Constant *ConstantInt::getTrue(Type *Ty) {
514 assert(Ty->getScalarType()->isIntegerTy(1) && "Type not i1 or vector of i1.");
514 assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
515515 ConstantInt *TrueC = ConstantInt::getTrue(Ty->getContext());
516516 if (auto *VTy = dyn_cast(Ty))
517517 return ConstantVector::getSplat(VTy->getNumElements(), TrueC);
519519 }
520520
521521 Constant *ConstantInt::getFalse(Type *Ty) {
522 assert(Ty->getScalarType()->isIntegerTy(1) && "Type not i1 or vector of i1.");
522 assert(Ty->isIntOrIntVectorTy(1) && "Type not i1 or vector of i1.");
523523 ConstantInt *FalseC = ConstantInt::getFalse(Ty->getContext());
524524 if (auto *VTy = dyn_cast(Ty))
525525 return ConstantVector::getSplat(VTy->getNumElements(), FalseC);
537537 if (auto *STy = dyn_cast(this)) {
538538 // Structure indexes require (vectors of) 32-bit integer constants. In the
539539 // vector case all of the indices must be equal.
540 if (!V->getType()->getScalarType()->isIntegerTy(32))
540 if (!V->getType()->isIntOrIntVectorTy(32))
541541 return false;
542542 const Constant *C = dyn_cast(V);
543543 if (C && V->getType()->isVectorTy())
778778 getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) {
779779 // vlvgp will insert two grs into a vector register, so only count half the
780780 // number of instructions.
781 if (Opcode == Instruction::InsertElement &&
782 Val->getScalarType()->isIntegerTy(64))
781 if (Opcode == Instruction::InsertElement && Val->isIntOrIntVectorTy(64))
783782 return ((Index % 2 == 0) ? 1 : 0);
784783
785784 if (Opcode == Instruction::ExtractElement) {
10831083 if (Instruction *NV = foldOpWithConstantIntoOperand(I))
10841084 return NV;
10851085
1086 if (I.getType()->getScalarType()->isIntegerTy(1))
1086 if (I.getType()->isIntOrIntVectorTy(1))
10871087 return BinaryOperator::CreateXor(LHS, RHS);
10881088
10891089 // X + X --> X << 1
15191519 return Res;
15201520 }
15211521
1522 if (I.getType()->getScalarType()->isIntegerTy(1))
1522 if (I.getType()->isIntOrIntVectorTy(1))
15231523 return BinaryOperator::CreateXor(Op0, Op1);
15241524
15251525 // Replace (-1 - A) with (~A).
15491549
15501550 // Fold (sub 0, (zext bool to B)) --> (sext bool to B)
15511551 if (C->isNullValue() && match(Op1, m_ZExt(m_Value(X))))
1552 if (X->getType()->getScalarType()->isIntegerTy(1))
1552 if (X->getType()->isIntOrIntVectorTy(1))
15531553 return CastInst::CreateSExtOrBitCast(X, Op1->getType());
15541554
15551555 // Fold (sub 0, (sext bool to B)) --> (zext bool to B)
15561556 if (C->isNullValue() && match(Op1, m_SExt(m_Value(X))))
1557 if (X->getType()->getScalarType()->isIntegerTy(1))
1557 if (X->getType()->isIntOrIntVectorTy(1))
15581558 return CastInst::CreateZExtOrBitCast(X, Op1->getType());
15591559 }
15601560
11871187
11881188 // Fold (and (sext bool to A), B) --> (select bool, B, 0)
11891189 Value *X = nullptr;
1190 if (match(Op0, m_SExt(m_Value(X))) &&
1191 X->getType()->getScalarType()->isIntegerTy(1)) {
1190 if (match(Op0, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
11921191 Value *Zero = Constant::getNullValue(Op1->getType());
11931192 return SelectInst::Create(X, Op1, Zero);
11941193 }
11951194
11961195 // Fold (and ~(sext bool to A), B) --> (select bool, 0, B)
11971196 if (match(Op0, m_Not(m_SExt(m_Value(X)))) &&
1198 X->getType()->getScalarType()->isIntegerTy(1)) {
1197 X->getType()->isIntOrIntVectorTy(1)) {
11991198 Value *Zero = Constant::getNullValue(Op0->getType());
12001199 return SelectInst::Create(X, Zero, Op1);
12011200 }
15581557 InstCombiner::BuilderTy &Builder) {
15591558 // If these are scalars or vectors of i1, A can be used directly.
15601559 Type *Ty = A->getType();
1561 if (match(A, m_Not(m_Specific(B))) && Ty->getScalarType()->isIntegerTy(1))
1560 if (match(A, m_Not(m_Specific(B))) && Ty->isIntOrIntVectorTy(1))
15621561 return A;
15631562
15641563 // If A and B are sign-extended, look through the sexts to find the booleans.
15651564 Value *Cond;
15661565 Value *NotB;
15671566 if (match(A, m_SExt(m_Value(Cond))) &&
1568 Cond->getType()->getScalarType()->isIntegerTy(1) &&
1567 Cond->getType()->isIntOrIntVectorTy(1) &&
15691568 match(B, m_OneUse(m_Not(m_Value(NotB))))) {
15701569 NotB = peekThroughBitcast(NotB, true);
15711570 if (match(NotB, m_SExt(m_Specific(Cond))))
15871586 // operand, see if the constants are inverse bitmasks.
15881587 if (match(A, (m_Xor(m_SExt(m_Value(Cond)), m_Constant(AC)))) &&
15891588 match(B, (m_Xor(m_SExt(m_Specific(Cond)), m_Constant(BC)))) &&
1590 Cond->getType()->getScalarType()->isIntegerTy(1) &&
1589 Cond->getType()->isIntOrIntVectorTy(1) &&
15911590 areInverseVectorBitmasks(AC, BC)) {
15921591 AC = ConstantExpr::getTrunc(AC, CmpInst::makeCmpResultType(Ty));
15931592 return Builder.CreateXor(Cond, AC);
22292228
22302229 // or(sext(A), B) / or(B, sext(A)) --> A ? -1 : B, where A is i1 or .
22312230 if (match(Op0, m_OneUse(m_SExt(m_Value(A)))) &&
2232 A->getType()->getScalarType()->isIntegerTy(1))
2231 A->getType()->isIntOrIntVectorTy(1))
22332232 return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op1);
22342233 if (match(Op1, m_OneUse(m_SExt(m_Value(A)))) &&
2235 A->getType()->getScalarType()->isIntegerTy(1))
2234 A->getType()->isIntOrIntVectorTy(1))
22362235 return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op0);
22372236
22382237 // Note: If we've gotten to the point of visiting the outer OR, then the
43704370 static Instruction *canonicalizeICmpBool(ICmpInst &I,
43714371 InstCombiner::BuilderTy &Builder) {
43724372 Value *A = I.getOperand(0), *B = I.getOperand(1);
4373 assert(A->getType()->getScalarType()->isIntegerTy(1) && "Bools only");
4373 assert(A->getType()->isIntOrIntVectorTy(1) && "Bools only");
43744374
43754375 // A boolean compared to true/false can be simplified to Op0/true/false in
43764376 // 14 out of the 20 (10 predicates * 2 constants) possible combinations.
44774477 }
44784478 }
44794479
4480 if (Op0->getType()->getScalarType()->isIntegerTy(1))
4480 if (Op0->getType()->isIntOrIntVectorTy(1))
44814481 if (Instruction *Res = canonicalizeICmpBool(I, Builder))
44824482 return Res;
44834483
325325 }
326326
327327 /// i1 mul -> i1 and.
328 if (I.getType()->getScalarType()->isIntegerTy(1))
328 if (I.getType()->isIntOrIntVectorTy(1))
329329 return BinaryOperator::CreateAnd(Op0, Op1);
330330
331331 // X*(1 << Y) --> X << Y
937937 }
938938
939939 if (match(Op0, m_One())) {
940 assert(!I.getType()->getScalarType()->isIntegerTy(1) &&
941 "i1 divide not removed?");
940 assert(!I.getType()->isIntOrIntVectorTy(1) && "i1 divide not removed?");
942941 if (I.getOpcode() == Instruction::SDiv) {
943942 // If Op1 is 0 then it's undefined behaviour, if Op1 is 1 then the
944943 // result is one, if Op1 is -1 then the result is minus one, otherwise
10201020 // TODO: Handle larger types? That requires adjusting FoldOpIntoSelect too.
10211021 Value *X = ExtInst->getOperand(0);
10221022 Type *SmallType = X->getType();
1023 if (!SmallType->getScalarType()->isIntegerTy(1))
1023 if (!SmallType->isIntOrIntVectorTy(1))
10241024 return nullptr;
10251025
10261026 Constant *C;
11801180 return &SI;
11811181 }
11821182
1183 if (SelType->getScalarType()->isIntegerTy(1) &&
1183 if (SelType->isIntOrIntVectorTy(1) &&
11841184 TrueVal->getType() == CondVal->getType()) {
11851185 if (match(TrueVal, m_One())) {
11861186 // Change: A = select B, true, C --> A = or B, C
789789 return nullptr;
790790
791791 // Bool selects with constant operands can be folded to logical ops.
792 if (SI->getType()->getScalarType()->isIntegerTy(1))
792 if (SI->getType()->isIntOrIntVectorTy(1))
793793 return nullptr;
794794
795795 // If it's a bitcast involving vectors, make sure it has the same number of