[llvm] Optimize count leading ones if promoted type (PR #99591)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 23 05:04:31 PDT 2024
================
@@ -5049,6 +5049,40 @@ static MVT getPromotedVectorElementType(const TargetLowering &TLI,
return MidVT;
}
+// (CTLZ (XOR Op -1)) --> (TRUNCATE (CTLZ_ZERO_UNDEF
+// (XOR (SHIFT (ANYEXTEND Op1)
+// ShiftAmount)
+// -1)))
+static bool ExtendCtlzNot(SDNode *Node, SDValue &Result, SDLoc &dl, MVT OVT,
+ MVT NVT, SelectionDAG &DAG) {
+ SDValue NotOp = Node->getOperand(0);
+ if (NotOp.getOpcode() != ISD::XOR)
+ return false;
+
+ SDValue SrcOp = NotOp->getOperand(0);
+ SDValue CstOp = NotOp->getOperand(1);
+
+ ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(CstOp);
+
+ if (!Cst || !Cst->isAllOnes())
+ return false;
----------------
RKSimon wrote:
We can now use SDPatternMatch to do this for us -
```
sd_match(Node->getOperand(0), m_Not(SrcOp))
```
https://github.com/llvm/llvm-project/pull/99591
More information about the llvm-commits
mailing list