Fix Logical Right Shift Simplify Bug:

林作健 via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 7 18:53:08 PDT 2016


Hi,
    Michael and I have discussed this problem, and he thinks
"Bit shift by the type's bitsize or more is undefined behavior in C/C++
(C11, 6.5.7p3; C++11, [expr.shift] 2.). If this happens the compiler
can do anything it likes to ("make fly demons out of your nose"). LLVM
chooses to use Undef. You should fix your original code, eg. introduce
a separate case for rot==16 and rot==0.

With this 'fix' the output program might behave differently on
different CPUs, depending on how they implement shift operations.
Common implementations are to shift on the shift amount modulo type
size (ie. a nop when the shift amount is equal to the size) or to set
the result to all-zeros or all-ones (ashr on negative values)."

Then I find out the code snippet that I cut from V8 ECMAScript engine,
has fixed this problem according to what Mr Kruse says.

Thank you again for your answer, Mr Kurse.


2016-08-06 8:42 GMT+08:00 林作健 <manjian2006 at gmail.com>:
> Not yet. Let me forward these mails later.
>
> 2016-08-05 23:26 GMT+08:00 Michael Kruse <llvm-commits at meinersbur.de>:
>> 2016-08-05 17:03 GMT+02:00 林作健 <manjian2006 at gmail.com>:
>>> Hi Michael,
>>>     Thank you for your answer.
>>>     Actually this code snippet is cut from v8 ECMAScript engine, from here:
>>> https://cs.chromium.org/chromium/src/v8/src/arm/assembler-arm.cc?q=assembler-arm.cc&sq=package:chromium&dr&l=1005
>>>     And chromium had fixed this using the resort you mentioned above.
>>
>> OK, then I think we don't need the patch anymore. Do you notify the
>> mailing list about it?
>>
>> Michael


More information about the llvm-commits mailing list