[llvm] [DAGCombine] Fold `ctlz_zero_undef(X << C) -> ctlz_zero_undef(X) - C` (PR #100932)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 28 08:32:38 PDT 2024


================
@@ -11133,6 +11133,18 @@ SDValue DAGCombiner::visitCTLZ_ZERO_UNDEF(SDNode *N) {
   if (SDValue C =
           DAG.FoldConstantArithmetic(ISD::CTLZ_ZERO_UNDEF, DL, VT, {N0}))
     return C;
+
+  // Fold ctlz_zero_undef(X << C) --> ctlz_zero_undef(X) - C
+  SDValue A;
+  APInt C;
+  if (sd_match(N0, m_Shl(m_Value(A), m_ConstInt(C))) &&
----------------
dtcxzyw wrote:

It is checked by `DAG.computeKnownBits(A).countMinLeadingZeros() >= C.getLimitedValue()`.


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


More information about the llvm-commits mailing list