[llvm] [CodeGenPrepare] Unfold slow ctpop when used in power-of-two test (PR #102731)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 12 00:20:36 PDT 2024
================
@@ -1757,6 +1758,40 @@ bool CodeGenPrepare::combineToUSubWithOverflow(CmpInst *Cmp,
return true;
}
+// Decanonicalizes icmp+ctpop power-of-two test if ctpop is slow.
+bool CodeGenPrepare::unfoldPow2Test(CmpInst *Cmp) {
+ ICmpInst::Predicate Pred;
+ Value *X;
+ uint64_t C;
+
+ if (!match(Cmp, m_ICmp(Pred, m_Intrinsic<Intrinsic::ctpop>(m_Value(X)),
+ m_ConstantInt(C))))
+ return false;
+
+ Type *Ty = X->getType();
+ if (Ty->isVectorTy() || TTI->getPopcntSupport(Ty->getIntegerBitWidth()) ==
+ TargetTransformInfo::PSK_FastHardware)
----------------
nikic wrote:
Comparing this with simplifySetCCWithCTPOP, it seems to always expand the scalar case, and the vector case only if it's fast.
https://github.com/llvm/llvm-project/pull/102731
More information about the llvm-commits
mailing list