From 9959cdb66a02b50e29f4635b65c59a422f7b11c7 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Mon, 5 Jun 2023 10:46:49 -0700 Subject: [PATCH] [IRBUilder] Introduce getAllOnesMask [nfc] Simplify D99750 by factoring out a utility which we already have multiple instances of in tree. --- llvm/include/llvm/IR/IRBuilder.h | 6 ++++++ llvm/lib/IR/IRBuilder.cpp | 6 ++---- llvm/lib/IR/VectorBuilder.cpp | 4 +--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index 7cc659721132..1e32908dd537 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -800,6 +800,12 @@ public: CallInst *CreateMaskedCompressStore(Value *Val, Value *Ptr, Value *Mask = nullptr); + /// Return an all true boolean vector (mask) with \p NumElts lanes. + Value *getAllOnesMask(ElementCount NumElts) { + VectorType *VTy = VectorType::get(Type::getInt1Ty(Context), NumElts); + return Constant::getAllOnesValue(VTy); + } + /// Create an assume intrinsic call that allows the optimizer to /// assume that the provided condition will be true. /// diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp index f3d5a6099cd6..fd5a00f7d478 100644 --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -661,8 +661,7 @@ CallInst *IRBuilderBase::CreateMaskedGather(Type *Ty, Value *Ptrs, assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch"); if (!Mask) - Mask = Constant::getAllOnesValue( - VectorType::get(Type::getInt1Ty(Context), NumElts)); + Mask = getAllOnesMask(NumElts); if (!PassThru) PassThru = PoisonValue::get(Ty); @@ -697,8 +696,7 @@ CallInst *IRBuilderBase::CreateMaskedScatter(Value *Data, Value *Ptrs, #endif if (!Mask) - Mask = Constant::getAllOnesValue( - VectorType::get(Type::getInt1Ty(Context), NumElts)); + Mask = getAllOnesMask(NumElts); Type *OverloadedTypes[] = {DataTy, PtrsTy}; Value *Ops[] = {Data, Ptrs, getInt32(Alignment.value()), Mask}; diff --git a/llvm/lib/IR/VectorBuilder.cpp b/llvm/lib/IR/VectorBuilder.cpp index e7be7a98a593..c07bc0561fba 100644 --- a/llvm/lib/IR/VectorBuilder.cpp +++ b/llvm/lib/IR/VectorBuilder.cpp @@ -32,9 +32,7 @@ Module &VectorBuilder::getModule() const { } Value *VectorBuilder::getAllTrueMask() { - auto *BoolTy = Builder.getInt1Ty(); - auto *MaskTy = VectorType::get(BoolTy, StaticVectorLength); - return ConstantInt::getAllOnesValue(MaskTy); + return Builder.getAllOnesMask(StaticVectorLength); } Value &VectorBuilder::requestMask() {