[llvm-commits] [PATCH] Rotate constant folding bug
John McCall
rjmccall at apple.com
Tue Oct 11 20:18:31 PDT 2011
On Oct 11, 2011, at 6:06 PM, Cameron McInally wrote:
> 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;
> }
Nice catch! One tweak: the old code was written assuming that the shift
operations are destructive, so it copies 'this' twice. Since the shift operations
aren't destructive, those copies are completely unnecessary; please optimize
them out, like so:
APInt hi = shl(rotateAmt);
APInt lo = lshr(BitWidth - rotateAmt);
John.
More information about the llvm-commits
mailing list