[llvm] [InstCombine] Fold `X udiv Y` to `X lshr cttz(Y)` if Y is a power of 2 (PR #121386)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 09:05:32 PST 2025


goldsteinn wrote:

> > > > It would probably make sense to add a takeLog2 based fold for cttz as a follow up. I think that would recover the regression from [dtcxzyw/llvm-opt-benchmark#1908 (comment)](https://github.com/dtcxzyw/llvm-opt-benchmark/pull/1908#discussion_r1900188252).
> > > 
> > > 
> > > I think we would probably need a flash for that, or maybe a wrapping function. It makes sense to create `cttz` to avoid a `div`, but probably not a `mul`.
> > 
> > 
> > What I meant is to optimize cttz using takeLog2, not make takeLog2 emit cttz.
> 
> Ahh, yeah that makes sense.

Ill post a patch for that shortly.

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


More information about the llvm-commits mailing list