[PATCH] D47981: [InstCombine] Fold (x >> y) << y -> x & (-1 << y)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 10 09:45:06 PDT 2018


lebedev.ri added a comment.

In https://reviews.llvm.org/D47981#1127520, @spatel wrote:

> LGTM.


Thank you for the review.

Even in light of https://reviews.llvm.org/D46760#1127287, i believe we still can do *this* transform, ...



================
Comment at: lib/Transforms/InstCombine/InstCombineShifts.cpp:608
     unsigned BitWidth = I.getType()->getScalarSizeInBits();
     Type *Ty = I.getType();
 
----------------
spatel wrote:
> Remove the duplicate/shadow variable.
Oh, hm, i wonder why there was no `-Wshadow` warning.


================
Comment at: lib/Transforms/InstCombine/InstCombineShifts.cpp:620-624
     // (X >> C) << C --> X & (-1 << C)
     if (match(Op0, m_Shr(m_Value(X), m_Specific(Op1)))) {
       APInt Mask(APInt::getHighBitsSet(BitWidth, BitWidth - ShAmt));
       return BinaryOperator::CreateAnd(X, ConstantInt::get(Ty, Mask));
     }
----------------
... because we already do it here for when the `y` is constant, regardless of `exact`ness of `shr`.
Also, maybe this block should be dropped, now that the more general fold will be done, one not limited to constants?


Repository:
  rL LLVM

https://reviews.llvm.org/D47981





More information about the llvm-commits mailing list