Commit 3bebf028 authored by Christopher Tetreault's avatar Christopher Tetreault
Browse files

Clean up usages of asserting vector getters in Type

Summary:
Remove usages of asserting vector getters in Type in preparation for the
VectorType refactor. The existence of these functions complicates the
refactor while adding little value.

Reviewers: sdesmalen, rriddle, efriedma

Reviewed By: sdesmalen

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77262
parent 49e20c4c
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1513,9 +1513,10 @@ static void instrumentMaskedLoadOrStore(AddressSanitizer *Pass,
                                        unsigned Granularity, uint32_t TypeSize,
                                        bool IsWrite, Value *SizeArgument,
                                        bool UseCalls, uint32_t Exp) {
  auto *VTy = cast<PointerType>(Addr->getType())->getElementType();
  auto *VTy =
      cast<VectorType>(cast<PointerType>(Addr->getType())->getElementType());
  uint64_t ElemTypeSize = DL.getTypeStoreSizeInBits(VTy->getScalarType());
  unsigned Num = VTy->getVectorNumElements();
  unsigned Num = VTy->getNumElements();
  auto Zero = ConstantInt::get(IntptrTy, 0);
  for (unsigned Idx = 0; Idx < Num; ++Idx) {
    Value *InstrumentedAddress = nullptr;
+14 −11
Original line number Diff line number Diff line
@@ -2068,9 +2068,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
  size_t VectorOrPrimitiveTypeSizeInBits(Type *Ty) {
    assert(!(Ty->isVectorTy() && Ty->getScalarType()->isPointerTy()) &&
           "Vector of pointers is not a valid shadow type");
    return Ty->isVectorTy() ?
      Ty->getVectorNumElements() * Ty->getScalarSizeInBits() :
      Ty->getPrimitiveSizeInBits();
    return Ty->isVectorTy() ? cast<VectorType>(Ty)->getNumElements() *
                                  Ty->getScalarSizeInBits()
                            : Ty->getPrimitiveSizeInBits();
  }

  /// Cast between two shadow types, extending or truncating as
@@ -2086,7 +2086,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
    if (dstTy->isIntegerTy() && srcTy->isIntegerTy())
      return IRB.CreateIntCast(V, dstTy, Signed);
    if (dstTy->isVectorTy() && srcTy->isVectorTy() &&
        dstTy->getVectorNumElements() == srcTy->getVectorNumElements())
        cast<VectorType>(dstTy)->getNumElements() ==
            cast<VectorType>(srcTy)->getNumElements())
      return IRB.CreateIntCast(V, dstTy, Signed);
    Value *V1 = IRB.CreateBitCast(V, Type::getIntNTy(*MS.C, srcSizeInBits));
    Value *V2 =
@@ -2130,9 +2131,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
                           Value *OtherArg) {
    Constant *ShadowMul;
    Type *Ty = ConstArg->getType();
    if (Ty->isVectorTy()) {
      unsigned NumElements = Ty->getVectorNumElements();
      Type *EltTy = Ty->getVectorElementType();
    if (auto *VTy = dyn_cast<VectorType>(Ty)) {
      unsigned NumElements = VTy->getNumElements();
      Type *EltTy = VTy->getElementType();
      SmallVector<Constant *, 16> Elements;
      for (unsigned Idx = 0; Idx < NumElements; ++Idx) {
        if (ConstantInt *Elt =
@@ -2657,7 +2658,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
      assert(CopyOp->getType() == I.getType());
      assert(CopyOp->getType()->isVectorTy());
      Value *ResultShadow = getShadow(CopyOp);
      Type *EltTy = ResultShadow->getType()->getVectorElementType();
      Type *EltTy = cast<VectorType>(ResultShadow->getType())->getElementType();
      for (int i = 0; i < NumUsedElements; ++i) {
        ResultShadow = IRB.CreateInsertElement(
            ResultShadow, ConstantInt::getNullValue(EltTy),
@@ -2959,8 +2960,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {

        Value *Acc = IRB.CreateExtractElement(
            MaskedPassThruShadow, ConstantInt::get(IRB.getInt32Ty(), 0));
        for (int i = 1, N = PassThru->getType()->getVectorNumElements(); i < N;
             ++i) {
        for (int i = 1,
                 N = cast<VectorType>(PassThru->getType())->getNumElements();
             i < N; ++i) {
          Value *More = IRB.CreateExtractElement(
              MaskedPassThruShadow, ConstantInt::get(IRB.getInt32Ty(), i));
          Acc = IRB.CreateOr(Acc, More);
@@ -3020,7 +3022,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
  void handlePclmulIntrinsic(IntrinsicInst &I) {
    IRBuilder<> IRB(&I);
    Type *ShadowTy = getShadowTy(&I);
    unsigned Width = I.getArgOperand(0)->getType()->getVectorNumElements();
    unsigned Width =
        cast<VectorType>(I.getArgOperand(0)->getType())->getNumElements();
    assert(isa<ConstantInt>(I.getArgOperand(2)) &&
           "pclmul 3rd operand must be a constant");
    unsigned Imm = cast<ConstantInt>(I.getArgOperand(2))->getZExtValue();
+6 −4
Original line number Diff line number Diff line
@@ -195,10 +195,11 @@ static Value* generatePoisonChecks(Instruction &I) {
    break;
  case Instruction::ExtractElement: {
    Value *Vec = I.getOperand(0);
    if (Vec->getType()->getVectorIsScalable())
    auto *VecVTy = cast<VectorType>(Vec->getType());
    if (VecVTy->isScalable())
      break;
    Value *Idx = I.getOperand(1);
    unsigned NumElts = Vec->getType()->getVectorNumElements();
    unsigned NumElts = VecVTy->getNumElements();
    Value *Check =
      B.CreateICmp(ICmpInst::ICMP_UGE, Idx,
                   ConstantInt::get(Idx->getType(), NumElts));
@@ -207,10 +208,11 @@ static Value* generatePoisonChecks(Instruction &I) {
  }
  case Instruction::InsertElement: {
    Value *Vec = I.getOperand(0);
    if (Vec->getType()->getVectorIsScalable())
    auto *VecVTy = cast<VectorType>(Vec->getType());
    if (VecVTy->isScalable())
      break;
    Value *Idx = I.getOperand(2);
    unsigned NumElts = Vec->getType()->getVectorNumElements();
    unsigned NumElts = VecVTy->getNumElements();
    Value *Check =
      B.CreateICmp(ICmpInst::ICMP_UGE, Idx,
                   ConstantInt::get(Idx->getType(), NumElts));