[llvm] [InstCombine] Fold `(ct{t, l}z Pow2)` -> `Log2(Pow2)` (PR #122620)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 12 01:55:01 PST 2025


================
@@ -588,6 +588,22 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
     }
   }
 
+  // cttz(Pow2) -> Log2(Pow2)
+  // ctlz(Pow2) -> BitWidth - 1 - Log2(Pow2)
+  if (IsTZ || II.hasOneUse()) {
----------------
dtcxzyw wrote:

Oops. I guess @goldsteinn means `Op0->hasOneUse()`.


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


More information about the llvm-commits mailing list