[llvm-dev] The undef story
Joerg Sonnenberger via llvm-dev
llvm-dev at lists.llvm.org
Thu Jun 29 08:58:02 PDT 2017
On Thu, Jun 29, 2017 at 08:41:59AM -0700, Peter Lawrence via llvm-dev wrote:
> This doesn’t make sense to me, a shift amount of 48 is “undefined” for unsigned char,
> How do we know this isn’t a source code bug,
> What makes us think the the user intended the result to be “0”.
It is a source bug, if the code is ever executed. This is in fact a
class of real world bugs as CPUs *do* implement overly large shifts
differently. There are two different views here:
(1) It obviously means the result should be zero, since all bits are
shifted out.
(2) It is faster to just mask the operand and avoid any compares in the
ALU. It has the nice side effect of simplifying rotation in software.
ARM and X86 are examples for those views.
Joerg
More information about the llvm-dev
mailing list