[llvm-commits] proposed patch: shift when shift amount >= bit width

Lauro Ramos Venancio lauro.venancio at gmail.com
Tue Jun 12 13:19:00 PDT 2007


The attached patch unify the handle of shifts when the shift amount is
greater or equal the bit width.

Nowadays, LLVM evaluates shl(i32 X,32) to 0 in some places and to
undef in other places.
For compatibility purpose, this patch implements the gcc behavior.

This fix the miscompilation of the file ffmpeg/libavformat/mpeg.c.

Proposed behavior:
=== shl(X,N) =====
if (N<bitwidth(X))   result = X << N
if (N>=bitwidth(X))   result = 0;

=== Lshr(X,N) =====
if (N<bitwidth(X))   result = X >> N
if (N>=bitwidth(X))   result = 0;

=== Ashr(X,N) =====
if (N<bitwidth(X))   result = X >> N
if (N>=bitwidth(X) && X<0)   result = -1;
if (N>=bitwidth(X) && X>=0)   result = 0;


Lauro
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shift.patch
Type: text/x-patch
Size: 14756 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070612/7654832a/attachment.bin>


More information about the llvm-commits mailing list