[DAGCombiner] Recognize another rotation idiom

Richard Sandiford rsandifo at linux.vnet.ibm.com
Thu Mar 6 01:34:50 PST 2014


Sorry for the slow reply!

Adam Nemet <anemet at apple.com> writes:
> This is the new idiom:
>
>   x<<(y&31) | x>>((0-y)&31)
>
> which is recognized as:
>
>   x ROTL (y&31)
>
> The change refines matchRotateSub.  In
> Neg & (OpSize - 1) == (OpSize - Pos) & (OpSize - 1), if Pos is
> Pos' & (OpSize - 1) we can just use Pos' instead of Pos.
>
> There are two patches attached.  I cover the actual functional change in
> the second.  In the first I tried to fix two minor issues that confused
> me somewhat while trying to understand matchRotateSub:
>
> 1. Slightly change the wording in the function comment. Originally, it can be
> understood as if we turned the input into two subsequent rotates.
>
> 2. Better connect the comment which talks about Mask and the code which used
> LoBits.  Renamed variable to MaskLoBits.
>
> Thanks,
> Adam
>
>
> diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> index 5057850..2305687 100644
> --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> @@ -3352,7 +3352,7 @@ static bool MatchRotateHalf(SDValue Op, SDValue &Shift, SDValue &Mask) {
>  //
>  //     (or (shift1 X, Neg), (shift2 X, Pos))
>  //
> -// reduces to a rotate in direction shift2 by Pos and a rotate in direction
> +// reduces to a rotate in direction shift2 by Pos or a rotate in direction
>  // shift1 by Neg.  The range [0, OpSize) means that we only need to consider
>  // shift amounts with defined behavior.
>  static bool matchRotateSub(SDValue Pos, SDValue Neg, unsigned OpSize) {

I take your point, but "or" kind-of suggests that these are two separate
conditions, whereas they're really just two ways of expressing the same
condition.  Maybe "or (equivalently)"?

Both patches LGTM otherwise, thanks.

Richard




More information about the llvm-commits mailing list