[llvm] [NFC][IR] Add CreateCountTrailingZeroElems helper (PR #106711)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 04:06:08 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-llvm-transforms
Author: David Sherwood (david-arm)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/106711.diff
2 Files Affected:
- (modified) llvm/include/llvm/IR/IRBuilder.h (+8)
- (modified) llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp (+2-3)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/106711
More information about the llvm-commits
mailing list