Skip to content

Commit dc6c3ba

Browse files
authored
[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.
1 parent dc3f66a commit dc6c3ba

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,15 @@ class IRBuilderBase {
10791079
nullptr, Name);
10801080
}
10811081

1082+
/// Create a call to llvm.experimental_cttz_elts
1083+
Value *CreateCountTrailingZeroElems(Type *ResTy, Value *Mask,
1084+
bool ZeroIsPoison = true,
1085+
const Twine &Name = "") {
1086+
return CreateIntrinsic(Intrinsic::experimental_cttz_elts,
1087+
{ResTy, Mask->getType()},
1088+
{Mask, getInt1(ZeroIsPoison)}, nullptr, Name);
1089+
}
1090+
10821091
private:
10831092
/// Create a call to a masked intrinsic with given Id.
10841093
CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,

llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,7 @@ Value *LoopIdiomVectorize::createMaskedFindMismatch(
470470
VectorFoundIndex->addIncoming(VectorIndexPhi, VectorLoopStartBlock);
471471

472472
Value *PredMatchCmp = Builder.CreateAnd(LastLoopPred, FoundPred);
473-
Value *Ctz = Builder.CreateIntrinsic(
474-
Intrinsic::experimental_cttz_elts, {ResType, PredMatchCmp->getType()},
475-
{PredMatchCmp, /*ZeroIsPoison=*/Builder.getInt1(true)});
473+
Value *Ctz = Builder.CreateCountTrailingZeroElems(ResType, PredMatchCmp);
476474
Ctz = Builder.CreateZExt(Ctz, I64Type);
477475
Value *VectorLoopRes64 = Builder.CreateAdd(VectorFoundIndex, Ctz, "",
478476
/*HasNUW=*/true, /*HasNSW=*/true);

0 commit comments

Comments
 (0)