[llvm] [AArch64][SVE2] Generate SVE2 BSL instruction in LLVM for bit-twiddling. (PR #83514)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 11:42:19 PDT 2024
================
@@ -17660,23 +17656,32 @@ static SDValue tryCombineToBSL(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
for (int j = 1; j >= 0; --j) {
BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(i));
BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(j));
- if (!BVN0 || !BVN1)
+ APInt Val1, Val2;
+ if ((!BVN0 || !BVN1) &&
+ (!ISD::isConstantSplatVector(N0->getOperand(i).getNode(), Val1) ||
+ !ISD::isConstantSplatVector(N1->getOperand(j).getNode(), Val2)))
continue;
bool FoundMatch = true;
- for (unsigned k = 0; k < VT.getVectorNumElements(); ++k) {
- ConstantSDNode *CN0 = dyn_cast<ConstantSDNode>(BVN0->getOperand(k));
- ConstantSDNode *CN1 = dyn_cast<ConstantSDNode>(BVN1->getOperand(k));
- if (!CN0 || !CN1 ||
- CN0->getZExtValue() != (BitMask & ~CN1->getZExtValue())) {
- FoundMatch = false;
- break;
+ if (BVN0) {
+ for (unsigned k = 0; k < VT.getVectorNumElements(); ++k) {
+ ConstantSDNode *CN0 = dyn_cast<ConstantSDNode>(BVN0->getOperand(k));
+ ConstantSDNode *CN1 = dyn_cast<ConstantSDNode>(BVN1->getOperand(k));
+ if (!CN0 || !CN1 ||
+ CN0->getZExtValue() != (BitMask & ~CN1->getZExtValue())) {
+ FoundMatch = false;
+ break;
+ }
}
+ } else {
+ FoundMatch = ((BitMask & ~Val1.getZExtValue()) == Val2.getZExtValue());
}
- if (FoundMatch)
- return DAG.getNode(AArch64ISD::BSP, DL, VT, SDValue(BVN0, 0),
+ if (FoundMatch) {
+ SDNode *Arg = (BVN0) ? BVN0 : N0->getOperand(i).getNode();
+ return DAG.getNode(AArch64ISD::BSP, DL, VT, SDValue(Arg, 0),
----------------
paulwalker-arm wrote:
Can `SDValue(Arg, 0)` just be `N0->getOperand(i)`?
https://github.com/llvm/llvm-project/pull/83514
More information about the llvm-commits
mailing list