[PATCH] D107711: [DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)

Ben Shi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 10 03:17:15 PDT 2021


benshi001 added a comment.

In D107711#2934794 <https://reviews.llvm.org/D107711#2934794>, @craig.topper wrote:

> In D107711#2934246 <https://reviews.llvm.org/D107711#2934246>, @benshi001 wrote:
>
>> Is there any better way to implement this optimization other than ISelDagToDag?
>>
>> 1. It seems hard to calculate c1/c0 by writing TD mapping rules.
>>
>> 2. I also tried DAG transform in `RISCVTargetLowering::ReplaceNodeResults`, it is also not easy, since it involves more code about legalization.
>
> It should probably be a DAG combine and the transform that's turning (mul (add X, C1), C2) into (add (mul X, C2), C1 * C2) should ask the target if it is profitable, or at least call isLegalAddImmediate for C1*C2. @spatel or @lebedev.ri, what do you think?

Thanks for your help! I have added a new target hook function isMulAddWithConstNotProfitable to let the DAGCombiner consult the target before combining (mul (add X, C1), C2).

This solution seems more clear. And it really improve most riscv's assembly code, except two of them, which I have made inline comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107711/new/

https://reviews.llvm.org/D107711



More information about the llvm-commits mailing list