[llvm] dc6c3ba - [NFC][IR] Add CreateCountTrailingZeroElems helper (#106711)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 05:40:21 PDT 2024
Author: David Sherwood
Date: 2024-09-02T13:40:14+01:00
New Revision: dc6c3ba4c4372172f504fcbe440f62932edf1cc1
URL: https://github.com/llvm/llvm-project/commit/dc6c3ba4c4372172f504fcbe440f62932edf1cc1
DIFF: https://github.com/llvm/llvm-project/commit/dc6c3ba4c4372172f504fcbe440f62932edf1cc1.diff
LOG: [NFC][IR] Add CreateCountTrailingZeroElems helper (#106711)
The LoopIdiomVectorize pass already creates calls to the intrinsic
experimental_cttz_elts, but PR #88385 will start calling this more
too so I've created a helper for it.
Added:
Modified:
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 0dbcbc0b2cb76f..4193fcd1254018 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1079,6 +1079,15 @@ class IRBuilderBase {
nullptr, Name);
}
+ /// Create a call to llvm.experimental_cttz_elts
+ Value *CreateCountTrailingZeroElems(Type *ResTy, Value *Mask,
+ bool ZeroIsPoison = true,
+ const Twine &Name = "") {
+ return CreateIntrinsic(Intrinsic::experimental_cttz_elts,
+ {ResTy, Mask->getType()},
+ {Mask, getInt1(ZeroIsPoison)}, nullptr, Name);
+ }
+
private:
/// Create a call to a masked intrinsic with given Id.
CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
diff --git a/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
index cb31e2a2ecaec4..7af7408ed67a8c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
@@ -470,9 +470,7 @@ Value *LoopIdiomVectorize::createMaskedFindMismatch(
VectorFoundIndex->addIncoming(VectorIndexPhi, VectorLoopStartBlock);
Value *PredMatchCmp = Builder.CreateAnd(LastLoopPred, FoundPred);
- Value *Ctz = Builder.CreateIntrinsic(
- Intrinsic::experimental_cttz_elts, {ResType, PredMatchCmp->getType()},
- {PredMatchCmp, /*ZeroIsPoison=*/Builder.getInt1(true)});
+ Value *Ctz = Builder.CreateCountTrailingZeroElems(ResType, PredMatchCmp);
Ctz = Builder.CreateZExt(Ctz, I64Type);
Value *VectorLoopRes64 = Builder.CreateAdd(VectorFoundIndex, Ctz, "",
/*HasNUW=*/true, /*HasNSW=*/true);
More information about the llvm-commits
mailing list