From 5f07dcd23c2dac5b34115df07d3ae629c35c6eb3 Mon Sep 17 00:00:00 2001 From: Christopher Tetreault Date: Tue, 14 Apr 2020 13:30:18 -0700 Subject: [PATCH] [SVE] Remove calls to getBitWidth from IR Reviewers: efriedma, sdesmalen, RKSimon, majnemer Reviewed By: majnemer Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77897 --- llvm/lib/IR/AutoUpgrade.cpp | 27 +++++++++++++++------------ llvm/lib/IR/ConstantFold.cpp | 3 ++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index a1e93c9..e2997df 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -1247,8 +1247,9 @@ static Value *UpgradeMaskedStore(IRBuilder<> &Builder, Ptr = Builder.CreateBitCast(Ptr, llvm::PointerType::getUnqual(Data->getType())); const Align Alignment = - Aligned ? Align(cast(Data->getType())->getBitWidth() / 8) - : Align(1); + Aligned + ? Align(Data->getType()->getPrimitiveSizeInBits().getFixedSize() / 8) + : Align(1); // If the mask is all ones just emit a regular store. if (const auto *C = dyn_cast(Mask)) @@ -1268,8 +1269,10 @@ static Value *UpgradeMaskedLoad(IRBuilder<> &Builder, // Cast the pointer to the right type. Ptr = Builder.CreateBitCast(Ptr, llvm::PointerType::getUnqual(ValTy)); const Align Alignment = - Aligned ? Align(cast(Passthru->getType())->getBitWidth() / 8) - : Align(1); + Aligned + ? Align(Passthru->getType()->getPrimitiveSizeInBits().getFixedSize() / + 8) + : Align(1); // If the mask is all ones just emit a regular store. if (const auto *C = dyn_cast(Mask)) @@ -1739,9 +1742,9 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { Value *BC = Builder.CreateBitCast(Arg0, PointerType::getUnqual(Arg1->getType()), "cast"); - VectorType *VTy = cast(Arg1->getType()); - StoreInst *SI = - Builder.CreateAlignedStore(Arg1, BC, Align(VTy->getBitWidth() / 8)); + StoreInst *SI = Builder.CreateAlignedStore( + Arg1, BC, + Align(Arg1->getType()->getPrimitiveSizeInBits().getFixedSize() / 8)); SI->setMetadata(M->getMDKindID("nontemporal"), Node); // Remove intrinsic. @@ -3079,13 +3082,13 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { C, ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(C), 1))); Value *Ptr = CI->getArgOperand(0); - VectorType *VTy = cast(CI->getType()); // Convert the type of the pointer to a pointer to the stored type. - Value *BC = - Builder.CreateBitCast(Ptr, PointerType::getUnqual(VTy), "cast"); - LoadInst *LI = - Builder.CreateAlignedLoad(VTy, BC, Align(VTy->getBitWidth() / 8)); + Value *BC = Builder.CreateBitCast( + Ptr, PointerType::getUnqual(CI->getType()), "cast"); + LoadInst *LI = Builder.CreateAlignedLoad( + CI->getType(), BC, + Align(CI->getType()->getPrimitiveSizeInBits().getFixedSize() / 8)); LI->setMetadata(M->getMDKindID("nontemporal"), Node); Rep = LI; } else if (IsX86 && (Name.startswith("fma.vfmadd.") || diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index de20cc3..d286379 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -139,7 +139,8 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) { // and dest type have the same size (otherwise its an illegal cast). if (VectorType *DestPTy = dyn_cast(DestTy)) { if (VectorType *SrcTy = dyn_cast(V->getType())) { - assert(DestPTy->getBitWidth() == SrcTy->getBitWidth() && + assert(DestPTy->getPrimitiveSizeInBits() == + SrcTy->getPrimitiveSizeInBits() && "Not cast between same sized vectors!"); SrcTy = nullptr; // First, check for null. Undef is already handled. -- 2.7.4