[PATCH] Fixing inst-combine not to drops nsw when combining adds into mul (PR19263)

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Jun 5 14:39:07 PDT 2014


Yet another thing to be careful about. The proposed patch would have
disable the combining in

define i16 @f(i16 %a) {
       %b = mul i16 %a, 2
       %c = mul i16 %a, 32767
       %d = add i16 %b, %c
       ret i16 %d
}

I added the testcase in r210287.

On 5 June 2014 16:36, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
> There is an interesting organizational problem:
>
> Given
>
> define i16 @f(i16 %a) {
>        %b = mul nsw i16 %a, 3
>        %c = mul nsw i16 %a, 7
>        %d = add nsw i16 %b, %c
>        ret i16 %d
> }
>
> With your patch we produce
>
> define i16 @f(i16 %a) {
>   %d = mul i16 %a, 10
>   ret i16 %d
> }
>
> but given
>
> define i16 @f(i16 %a) {
>        %b = mul nsw i16 %a, 2
>        %c = mul nsw i16 %a, 7
>        %d = add nsw i16 %b, %c
>        ret i16 %d
> }
>
> it produces
>
> define i16 @f(i16 %a) {
>   %d = mul nsw i16 %a, 9
>   ret i16 %d
> }
>
> The problem comes from some cases being transformed in
> SimplifyUsingDistributiveLaws before getting to your code.
>
> Maybe what should happen is that as an early cleanup patch
> dyn_castFoldableMul should be moved and used by
> SimplifyUsingDistributiveLaws which would now handle all relevant
> cases.
>
> What do you think?




More information about the llvm-commits mailing list