pranavk updated this revision to Diff 521114. pranavk added a comment. [AArch64][InstCombine] Bail out for bitselect instructions
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D147266/new/ https://reviews.llvm.org/D147266 Files: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -56,6 +56,29 @@ /// /// FIXME: It's possible to create more instructions than previously existed. static bool cheapToScalarize(Value *V, Value *EI) { + // Pattern: or(and(a, mask), and(b, ~mask)) can be efficiently folded to bitselect instructions + // where ~mask = xor mask, -1 + if (isa<Instruction>(V)) { + Instruction *TI = cast<Instruction>(V); + if (TI->getOpcode() == Instruction::Or) { + Value *LHS = TI->getOperand(0); + Value *RHS = TI->getOperand(1); + Value *MaskValue = nullptr; + Value *MaskConst = nullptr; + + if (match(LHS, m_And(m_Value(), m_Value(MaskValue))) && + match(RHS, m_And(m_Value(), m_Xor(m_Specific(MaskValue), m_Value(MaskConst))))) { + if (auto *CI = dyn_cast<ConstantDataVector>(MaskConst)) { + Constant *C = CI->getSplatValue(); + if (C->isAllOnesValue()) { + llvm::outs() << "return false from cheap\n"; + return false; + } + } + } + } + } + ConstantInt *CEI = dyn_cast<ConstantInt>(EI); // If we can pick a scalar constant value out of a vector, that is free.
Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -56,6 +56,29 @@ /// /// FIXME: It's possible to create more instructions than previously existed. static bool cheapToScalarize(Value *V, Value *EI) { + // Pattern: or(and(a, mask), and(b, ~mask)) can be efficiently folded to bitselect instructions + // where ~mask = xor mask, -1 + if (isa<Instruction>(V)) { + Instruction *TI = cast<Instruction>(V); + if (TI->getOpcode() == Instruction::Or) { + Value *LHS = TI->getOperand(0); + Value *RHS = TI->getOperand(1); + Value *MaskValue = nullptr; + Value *MaskConst = nullptr; + + if (match(LHS, m_And(m_Value(), m_Value(MaskValue))) && + match(RHS, m_And(m_Value(), m_Xor(m_Specific(MaskValue), m_Value(MaskConst))))) { + if (auto *CI = dyn_cast<ConstantDataVector>(MaskConst)) { + Constant *C = CI->getSplatValue(); + if (C->isAllOnesValue()) { + llvm::outs() << "return false from cheap\n"; + return false; + } + } + } + } + } + ConstantInt *CEI = dyn_cast<ConstantInt>(EI); // If we can pick a scalar constant value out of a vector, that is free.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits