[llvm-dev] Signed Division and InstCombine

Dilan Manatunga via llvm-dev llvm-dev at lists.llvm.org
Tue May 31 16:19:29 PDT 2016


Ohh, duh. Just did the math in my head. All makes sense now. Probably had
the same thought process you were having when I initially thought it should
be zero.

Thanks for the quick responses.
-Dilan
On Tue, May 31, 2016 at 4:12 PM Tim Northover <t.p.northover at gmail.com>
wrote:

> On 31 May 2016 at 16:02, Dilan Manatunga <manatunga at gmail.com> wrote:
> > Just to verify, a 16-bit divion of INT16_MIN  by -1 results in INT16_MIN
> > again?
>
> No, "sdiv i16 -32768, -1" is undefined behaviour. The version with an
> "sext" and "trunc" avoids the undefined behaviour and does return
> -32768.
>
> > If the issue only occurs in this case, why aren't there checks to see if
> we
> > can simplify sdiv in cases where we know that numerator is not INT16_MIN
> or
> > the denominator is not -1. For example, we could simplify divides
> involving
> > one operand constants. Is it because this case is most likely rare?
>
> It's probably just that no-one has bothered to implement it, I'd
> actually expect the code to be reasonably common from C compilation.
> Another factor is that RISC CPUs mostly won't care (they tend to only
> have natural width division anyway), so that removes a large swathe of
> people who might be interested.
>
> Cheers.
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160531/b21c25c0/attachment.html>


More information about the llvm-dev mailing list