[PATCH] D63652: [InstCombine] (1 << (C - x)) -> ((1 << C) >> x) if C is bitwidth - 1
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 08:40:02 PDT 2019
lebedev.ri added inline comments.
================
Comment at: lib/Transforms/InstCombine/InstCombineShifts.cpp:677
+ // (1 << (C - x)) -> ((1 << C) >> x) if C is bitwidth - 1
+ if (match(Op0, m_APInt(ShlOp0)) && ShlOp0->getSExtValue() == 1 &&
+ match(Op1, m_Sub(m_APInt(C), m_Value(X))) &&
----------------
nikic wrote:
> getSExtValue will assert if the value is too large. You can use `ShlOp0->isOneValue()` here.
m_One()
================
Comment at: lib/Transforms/InstCombine/InstCombineShifts.cpp:678-679
+ if (match(Op0, m_APInt(ShlOp0)) && ShlOp0->getSExtValue() == 1 &&
+ match(Op1, m_Sub(m_APInt(C), m_Value(X))) &&
+ C->getZExtValue() == BitWidth - 1)
+ return BinaryOperator::CreateLShr(ConstantInt::get(Ty, ShlOp0->shl(*C)), X);
----------------
m_SpecificInt(BitWidth - 1)
================
Comment at: lib/Transforms/InstCombine/InstCombineShifts.cpp:680
+ C->getZExtValue() == BitWidth - 1)
+ return BinaryOperator::CreateLShr(ConstantInt::get(Ty, ShlOp0->shl(*C)), X);
----------------
ConstantInt::get(Ty, APInt::getSignMask(BitWidth))
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63652/new/
https://reviews.llvm.org/D63652
More information about the llvm-commits
mailing list