diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2019-03-18 14:27:51 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2019-03-18 14:27:51 +0000 |
| commit | 6063393536cc8f6129c1bc4d590e812525e16abb (patch) | |
| tree | be0babecd86fed9e7ee0452bd9ab3bb6151c9158 /llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | |
| parent | faf308b11a9f6702575593cf036626358851f318 (diff) | |
| download | bcm5719-llvm-6063393536cc8f6129c1bc4d590e812525e16abb.tar.gz bcm5719-llvm-6063393536cc8f6129c1bc4d590e812525e16abb.zip | |
[InstCombine] allow general vector constants for funnel shift to shift transforms
Follow-up to:
rL356338
rL356369
We can calculate an arbitrary vector constant minus the bitwidth, so there's
no need to limit this transform to scalars and splats.
llvm-svn: 356372
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 938517e64c3..49524d7f42e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2006,40 +2006,33 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { II->setArgOperand(2, ModuloC); return II; } + assert(ConstantExpr::getICmp(ICmpInst::ICMP_UGT, WidthC, ShAmtC) == + ConstantInt::getTrue(CmpInst::makeCmpResultType(Ty)) && + "Shift amount expected to be modulo bitwidth"); + // Canonicalize funnel shift right by constant to funnel shift left. This // is not entirely arbitrary. For historical reasons, the backend may // recognize rotate left patterns but miss rotate right patterns. if (II->getIntrinsicID() == Intrinsic::fshr) { // fshr X, Y, C --> fshl X, Y, (BitWidth - C) - assert(ConstantExpr::getICmp(ICmpInst::ICMP_UGT, WidthC, ShAmtC) == - ConstantInt::getTrue(CmpInst::makeCmpResultType(Ty)) && - "Shift amount expected to be modulo bitwidth"); Constant *LeftShiftC = ConstantExpr::getSub(WidthC, ShAmtC); Module *Mod = II->getModule(); Function *Fshl = Intrinsic::getDeclaration(Mod, Intrinsic::fshl, Ty); return CallInst::Create(Fshl, { Op0, Op1, LeftShiftC }); } - } - - // TODO: Pull this into the block above. We can handle semi-arbitrary vector - // shift amount constants as well as splats. - const APInt *SA; - if (match(II->getArgOperand(2), m_APInt(SA))) { - uint64_t ShiftAmt = SA->urem(BitWidth); - assert(ShiftAmt != 0 && "SimplifyCall should have handled zero shift"); assert(II->getIntrinsicID() == Intrinsic::fshl && "All funnel shifts by simple constants should go left"); - // fshl(X, 0, C) -> shl X, C - // fshl(X, undef, C) -> shl X, C - if (match(Op1, m_Zero()) || match(Op1, m_Undef())) - return BinaryOperator::CreateShl(Op0, ConstantInt::get(Ty, ShiftAmt)); + // fshl(X, 0, C) --> shl X, C + // fshl(X, undef, C) --> shl X, C + if (match(Op1, m_ZeroInt()) || match(Op1, m_Undef())) + return BinaryOperator::CreateShl(Op0, ShAmtC); - // fshl(0, X, C) -> lshr X, (BW-C) - // fshl(undef, X, C) -> lshr X, (BW-C) - if (match(Op0, m_Zero()) || match(Op0, m_Undef())) - return BinaryOperator::CreateLShr( - Op1, ConstantInt::get(Ty, BitWidth - ShiftAmt)); + // fshl(0, X, C) --> lshr X, (BW-C) + // fshl(undef, X, C) --> lshr X, (BW-C) + if (match(Op0, m_ZeroInt()) || match(Op0, m_Undef())) + return BinaryOperator::CreateLShr(Op1, + ConstantExpr::getSub(WidthC, ShAmtC)); } // The shift amount (operand 2) of a funnel shift is modulo the bitwidth, |

