[llvm] [InstCombine] Added optimisation for trunc (Pow2 >> x) to i1 (PR #157030)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 7 14:23:21 PDT 2025
================
@@ -969,6 +971,25 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
Changed = true;
}
+ const APInt *C1;
+ Value *V1;
+ // trunc (lshr i8 C1, V1) to i1 -> icmp eq V1, log_2(C1) iff C1 is power of 2
+ if (DestWidth == 1 &&
+ match(Src, m_OneUse(m_Shr(m_Power2(C1), m_Value(V1))))) {
+ Value *Right = ConstantInt::get(V1->getType(), C1->nearestLogBase2());
----------------
andjo403 wrote:
seems like countr_zero is used instead of nearestLogBase2
https://github.com/llvm/llvm-project/pull/157030
More information about the llvm-commits
mailing list