[llvm] [InstCombine] Fold Minimum over Trailing/Leading Bits Counts (PR #90402)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 09:06:16 PDT 2024
================
@@ -1633,6 +1667,21 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
Value *Cmp = Builder.CreateICmpNE(I0, Zero);
return CastInst::Create(Instruction::ZExt, Cmp, II->getType());
}
+ // umin(cttz(x), const) --> cttz(x | (1 << const))
+ Value *X;
+ Constant *Y;
+ Value *Z;
+ if (match(I0, m_OneUse(m_Cttz(m_Value(X), m_Value(Z)))) &&
+ match(I1, m_Constant(Y))) {
+ return foldMinimumOverTrailingOrLeadingZeroCount<Intrinsic::cttz>(
+ II, X, Z, Y, DL, Builder);
+ }
+ // umin(ctlz(x), const) --> ctlz(x | ((1 << (bitwidth - 1) >> const)))
+ if (match(I0, m_OneUse(m_Ctlz(m_Value(X), m_Value(Z)))) &&
+ match(I1, m_Constant(Y))) {
+ return foldMinimumOverTrailingOrLeadingZeroCount<Intrinsic::ctlz>(
+ II, X, Z, Y, DL, Builder);
+ }
----------------
goldsteinn wrote:
The matching code could also be in `foldMinimumOverTrailing...`. Just pass the intrinsic ID in question and use `m_Intrinsic`
https://github.com/llvm/llvm-project/pull/90402
More information about the llvm-commits
mailing list