// If we have BMI2's BZHI, we are ok with muti-use patterns.
// Else, if we only have BMI1's BEXTR, we require one-use.
const bool CanHaveExtraUses = Subtarget->hasBMI2();
- auto checkOneUse = [CanHaveExtraUses](SDValue Op, unsigned NUses = 1) {
+ auto checkUses = [CanHaveExtraUses](SDValue Op, unsigned NUses) {
return CanHaveExtraUses ||
Op.getNode()->hasNUsesOfValue(NUses, Op.getResNo());
};
+ auto checkOneUse = [checkUses](SDValue Op) { return checkUses(Op, 1); };
+ auto checkTwoUse = [checkUses](SDValue Op) { return checkUses(Op, 2); };
// a) x & ((1 << nbits) + (-1))
auto matchPatternA = [&checkOneUse, &NBits](SDValue Mask) -> bool {
SDValue X;
// d) x << (32 - y) >> (32 - y)
- auto matchPatternD = [&checkOneUse, Size, &X, &NBits](SDNode *Node) -> bool {
+ auto matchPatternD = [&checkOneUse, &checkTwoUse, Size, &X,
+ &NBits](SDNode *Node) -> bool {
if (Node->getOpcode() != ISD::SRL)
return false;
SDValue N0 = Node->getOperand(0);
SDValue N01 = N0->getOperand(1);
// Both of the shifts must be by the exact same value.
// There should not be any uses of the shift amount outside of the pattern.
- if (N1 != N01 || !checkOneUse(N1, 2))
+ if (N1 != N01 || !checkTwoUse(N1))
return false;
// Skip over a truncate of the shift amount.
if (N1->getOpcode() == ISD::TRUNCATE) {