[llvm-commits] [PATCH] Rotate constant folding bug
Eli Friedman
eli.friedman at gmail.com
Tue Oct 11 19:09:44 PDT 2011
On Tue, Oct 11, 2011 at 6:06 PM, Cameron McInally
<cameron.mcinally at nyu.edu> wrote:
> Hey guys,
>
> Constant folding for the rotate operators does not work currently. Here's a
> fix...
>
> royale mcinally/llvm> svn diff
>
> Index: lib/Support/APInt.cpp
>
> ===================================================================
>
> --- lib/Support/APInt.cpp (revision 141748)
>
> +++ lib/Support/APInt.cpp (working copy)
>
> @@ -1334,8 +1334,8 @@
>
> // Don't get too fancy, just use existing shift/or facilities
>
> APInt hi(*this);
>
> APInt lo(*this);
>
> - hi.shl(rotateAmt);
>
> - lo.lshr(BitWidth - rotateAmt);
>
> + hi = hi.shl(rotateAmt);
>
> + lo = lo.lshr(BitWidth - rotateAmt);
>
> return hi | lo;
>
> }
>
>
>
> @@ -1349,8 +1349,8 @@
>
> // Don't get too fancy, just use existing shift/or facilities
>
> APInt hi(*this);
>
> APInt lo(*this);
>
> - lo.lshr(rotateAmt);
>
> - hi.shl(BitWidth - rotateAmt);
>
> + lo = lo.lshr(rotateAmt);
>
> + hi = hi.shl(BitWidth - rotateAmt);
>
> return hi | lo;
>
> }
Err, wow. Nice catch. Would you mind adding a test in
unittests/ADT/APIntTest.cpp ? (Also, we prefer patches to be
attached rather than inlined.)
-Eli
More information about the llvm-commits
mailing list