[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 13:36:20 PDT 2014


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