[llvm] [AArch64] Fold vector select with power-of-2 bit-test to CMTST+BSP (PR #209100)
Mugundan S via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 2 20:53:29 PDT 2026
================
@@ -29067,6 +29089,43 @@ static SDValue performSETCCCombine(SDNode *N,
SplatLHSVal.isOne())
return DAG.getSetCC(DL, VT, DAG.getConstant(0, DL, CmpVT), RHS, ISD::SETGE);
+ // Fold setcc(and(X, Mask), Mask/0, eq/ne) --> [not] AArch64ISD::CMTST(X,
+ // Mask) for a power of 2 splat Mask, replacing AND+CMEQ with a single CMTST.
+ // Any NOT folds away when the result feeds a BSL/BIF/BIT select.
+ if (!DCI.isBeforeLegalize() && CmpVT.isFixedLengthVector() &&
+ (Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
+ LHS.getOpcode() == ISD::AND) {
+ APInt SplatVal;
+ SDValue X, MaskOp;
+ if (ISD::isConstantSplatVector(LHS.getOperand(1).getNode(), SplatVal) &&
----------------
MGN-GIT wrote:
Hi @davemgreen
Thanks for the beautiful suggestion, that's working fine as expected. I have updated patch and now the changes are minimal.
https://github.com/llvm/llvm-project/pull/209100
More information about the llvm-commits
mailing list