[llvm] [SelectOpt] Add support for AShr/LShr operands (PR #118495)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 9 00:15:24 PST 2024
================
@@ -784,30 +801,53 @@ void SelectOptimizeImpl::collectSelectGroups(BasicBlock &BB,
bool Inverted = match(Cond, m_Not(m_Value(Cond)));
return SelectInfo.insert({I, {Cond, false, Inverted, 0}}).first;
}
-
- // An Or(zext(i1 X), Y) can also be treated like a select, with condition X
- // and values Y|1 and Y.
- if (auto *BO = dyn_cast<BinaryOperator>(I)) {
- switch (I->getOpcode()) {
- case Instruction::Add:
- case Instruction::Sub: {
- Value *X;
- if (!((PatternMatch::match(I->getOperand(0),
- m_OneUse(m_ZExt(m_Value(X)))) ||
- PatternMatch::match(I->getOperand(1),
- m_OneUse(m_ZExt(m_Value(X))))) &&
- X->getType()->isIntegerTy(1)))
+ Value *Val;
+ ConstantInt *Shift;
+ if (match(I, m_Shr(m_Value(Val), m_ConstantInt(Shift))) &&
+ I->getType()->getIntegerBitWidth() == Shift->getZExtValue() + 1) {
+ for (auto *CmpI : SeenCmp) {
+ auto Pred = CmpI->getPredicate();
+ if (Val != CmpI->getOperand(0))
return SelectInfo.end();
----------------
davemgreen wrote:
`continue` here to check other icmps in SeenCmp?
https://github.com/llvm/llvm-project/pull/118495
More information about the llvm-commits
mailing list