[PATCH] Fixing inst-combine not to drops nsw when combining adds into mul (PR19263)
Dinesh Dwivedi
dinesh.d at samsung.com
Fri Jun 6 03:42:58 PDT 2014
I agree with the idea that these cases should get handled in SimplifyUsingDistributiveLaws and
I am working on generalized approach for that.
I have updated patch to just put following changes in record.
I have removed check for overflow because after analyzing few cases, I think we should not
disable transformation to pattern like this even if (2 + 32767)
%b = mul i16 %a, 2
%c = mul i16 %a, 32767
%d = add i16 %b, %c
ret i16 %d
as original case and transformed case will result in same output. When I pointed out case similar to
this, I thought that for some value of 'a', '(b+c)' might be positive but if we add constant which will become
negative due to overflow, result will mismatch.
I realized that as 'a' in integer, if a == 0, we will get 0 in any case and any value of a > 0, b and c will never
be less than 2 and 32767 respectively. so add result will always overflow.
What do you think? Should be disable above transform.
I have added a TODO to fix transform happening in SimplifyUsingDistributiveLaws and dropping nsw.
I will update it soon so that all these pattern gets handle in SimplifyUsingDistributiveLaws.
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.10173.patch
Type: text/x-patch
Size: 5664 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140606/0fa732a1/attachment.bin>
More information about the llvm-commits
mailing list