-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][IR] Add CreateCountTrailingZeroElems helper #106711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The LoopIdiomVectorize pass already creates calls to the intrinsic experimental_cttz_elts, but PR llvm#88385 will start calling this more too so I've created a helper for it.
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-llvm-transforms Author: David Sherwood (david-arm) ChangesThe LoopIdiomVectorize pass already creates calls to the intrinsic Full diff: https://github.com/llvm/llvm-project/pull/106711.diff 2 Files Affected:
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 0dbcbc0b2cb76f..d85f51a0a01210 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1079,6 +1079,14 @@ class IRBuilderBase {
nullptr, Name);
}
+ /// Create a call to llvm.experimental_cttz_elts
+ Value *CreateCountTrailingZeroElems(Type *ResTy, Value *Mask,
+ const Twine &Name = "") {
+ return CreateIntrinsic(
+ Intrinsic::experimental_cttz_elts, {ResTy, Mask->getType()},
+ {Mask, getInt1(/*ZeroIsPoison=*/true)}, 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..45c0eae29c9e9a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
@@ -470,9 +470,8 @@ 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);
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
llvm/include/llvm/IR/IRBuilder.h
Outdated
const Twine &Name = "") { | ||
return CreateIntrinsic( | ||
Intrinsic::experimental_cttz_elts, {ResTy, Mask->getType()}, | ||
{Mask, getInt1(/*ZeroIsPoison=*/true)}, nullptr, Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the helper will currently only ever be called when ZeroIsPoison is true, I think the helper should be able to set a different value. Maybe ZeroIsPoison could be passed in with a default value of true instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion! Uploaded a new patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.