[PATCH] D88475: [InstCombine] visitTrunc - trunc (lshr (sext A), C) --> (ashr A, C) non-uniform support
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 05:58:59 PDT 2020
lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.
LGTM
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp:830-855
+ Constant *C;
+ if (match(Src, m_LShr(m_SExt(m_Value(A)), m_Constant(C)))) {
unsigned AWidth = A->getType()->getScalarSizeInBits();
unsigned MaxShiftAmt = SrcWidth - std::max(DestWidth, AWidth);
// If the shift is small enough, all zero bits created by the shift are
// removed by the trunc.
----------------
lebedev.ri wrote:
>
Err, that should of course be
```
// Note that since we will perform the shift in narrower type, we need to clamp the shift amount.
Constant *MaxAmt = ConstantInt::get(SrcTy, AWidth - 1, false);
Constant *ShAmt = ConstantExpr::getUMin(C, MaxAmt);
ShAmt = ConstantExpr::getTrunc(ShAmt, A->getType());
```
================
Comment at: llvm/test/Transforms/InstCombine/cast.ll:1563
-; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
-; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 6, i32 undef>
-; ALL-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
----------------
It would be kind of good to preserve `undef`, but there is no nice way to do that currently.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88475/new/
https://reviews.llvm.org/D88475
More information about the llvm-commits
mailing list