Dilan Manatunga via llvm-dev
2016-May-31 22:34 UTC
[llvm-dev] Signed Division and InstCombine
I was looking through the InstCombine pass, and I was wondering why signed division is not considered a valid operation to combine in the canEvaluateTruncated function. This means, given the following code: %conv = sext i16 %0 to i32 %conv1 = sext i16 %1 to i32 %div = sdiv i32 %conv, %conv1 %conv2 = trunc i32 %div to i16 * Assume %0 and %1 are registers created from simple 16-bit loads. We cannot reduce the sequence to: %div = sdiv i16 %0 %1 What is the reason for the exclusion of sdiv from the operations considered valid for execution in a truncated format. Thanks, -Dilan Manatunga -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160531/2d3ea4b6/attachment.html>
Tim Northover via llvm-dev
2016-May-31 22:42 UTC
[llvm-dev] Signed Division and InstCombine
Hi Dilan, On 31 May 2016 at 15:34, Dilan Manatunga via llvm-dev <llvm-dev at lists.llvm.org> wrote:> What is the reason for the exclusion of sdiv from the operations considered > valid for execution in a truncated format.A 16-bit division of INT16_MIN by -1 is undefined behaviour but the original ext/trunc version is well-defined as 0. Cheers. Tim.
Tim Northover via llvm-dev
2016-May-31 22:50 UTC
[llvm-dev] Signed Division and InstCombine
On 31 May 2016 at 15:42, Tim Northover <t.p.northover at gmail.com> wrote:> A 16-bit division of INT16_MIN by -1 is undefined behaviour but the > original ext/trunc version is well-defined as 0.Sorry, INT16_MIN again actually. The main point still stands though, I think. Tim.
Just a reminder that Alive was created to answer exactly this kind of question. https://github.com/nunoplopes/alive John regehr at hawking:~$ ./alive/alive.py sdiv.opt ---------------------------------------- Optimization: 1 Precondition: true %conv = sext i16 %in1 to i32 %conv1 = sext i16 %in2 to i32 %div = sdiv i32 %conv, %conv1 %out = trunc i32 %div to i16 => %out = sdiv i16 %in1, %in2 ERROR: Domain of definedness of Target is smaller than Source's for i16 %out Example: %in1 i16 = 0x8000 (32768, -32768) %in2 i16 = 0xFFFF (65535, -1) %conv i32 = 0xFFFF8000 (4294934528, -32768) %conv1 i32 = 0xFFFFFFFF (4294967295, -1) %div i32 = 0x00008000 (32768) Source value: 0x8000 (32768, -32768) Target value: undef On 6/1/16 12:42 AM, Tim Northover via llvm-dev wrote:> Hi Dilan, > > On 31 May 2016 at 15:34, Dilan Manatunga via llvm-dev > <llvm-dev at lists.llvm.org> wrote: >> What is the reason for the exclusion of sdiv from the operations considered >> valid for execution in a truncated format. > > A 16-bit division of INT16_MIN by -1 is undefined behaviour but the > original ext/trunc version is well-defined as 0. > > Cheers. > > Tim. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >