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

Dinesh Dwivedi dinesh.d at samsung.com
Fri May 16 07:34:20 PDT 2014


Hi bkramer, rafael, majnemer,

I tried to fix this but I am not sure about few things.
1) We always convert (X * C1) + (X * C2) to X *(C1 + C2) even if (C1 + C2)
overflows. e.g.

  %1 = mul nsw i32 %x, 2147483647
  %2 = mul nsw i32 %x, 3
  %3 = add nsw i32 %1, %2

becomes
  %1 = mul i32 %x, -2147483646

Is this what we want. In that case, we can blindly copy nsw from
add instruction to mul instruction. If so, I will update this patch.

2) In this patch, I have tried not to combine add to mul for above case
but that is not enough to stop this conversion (getting converted from
some other code). If above conversion is wrong, I can go through code
and fix this. For now, this patch should take care of not dropping nsw
flags.

3) I haven't added similar checks in visitSub. Actually, all c examples,
I can come up with, was not creating sub with nsw. If is it required to
add similar check, I can update this patch.

http://reviews.llvm.org/D3799

Files:
  lib/Transforms/InstCombine/InstCombineAddSub.cpp
  test/Transforms/InstCombine/add2.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3799.9481.patch
Type: text/x-patch
Size: 6751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140516/1dfb2d34/attachment.bin>


More information about the llvm-commits mailing list