[llvm] [DAGCombine] Transform `shl X, cttz(Y)` to `mul (Y & -Y), X` if cttz is unsupported (PR #85066)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 01:21:37 PDT 2024


================
@@ -9962,6 +9962,18 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
     if (SDValue NewSHL = visitShiftByConstant(N))
       return NewSHL;
 
+  // fold (shl X, cttz(Y)) -> (mul (Y & -Y), X) if cttz is unsupported on the
+  // target.
+  if ((N1.getOpcode() == ISD::CTTZ || N1.getOpcode() == ISD::CTTZ_ZERO_UNDEF) &&
+      N1.hasOneUse() && !TLI.isOperationLegalOrCustom(ISD::CTTZ, VT) &&
----------------
dtcxzyw wrote:

I hardcode the opcode to avoid introducing regressions on rv64+zbb :(
Do you have better solution?


https://github.com/llvm/llvm-project/pull/85066


More information about the llvm-commits mailing list