[llvm] [RISCV] Add `2^N + 2^M` expanding pattern for mul (PR #137195)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 24 23:54:24 PDT 2025


topperc wrote:

> > Should we be solving the general case? What if there are more than 2 bits set in the multiplicand?
> 
> I'm not sure whether it's profitable enough to break down a mul into more than two `shl`s, and we observe that other backends typically don't perform this general level of optimization either.
> 
> However, it may be beneficial if the mul could be broken down to a `shl + shladd + add` sequence. This could be a potential enhancement for a following patch.

The original bug report was for CPUs that don't implement M or Zmmul. For those CPUs, we can probably use more instructions to avoid a library call. Unless we're optimizing for size.

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


More information about the llvm-commits mailing list