def C3LeftShift : PatLeaf<(imm), [{
uint64_t C = N->getZExtValue();
- return C > 3 && ((C % 3) == 0) && isPowerOf2_64(C / 3);
+ return C > 3 && (C >> llvm::countr_zero(C)) == 3;
}]>;
def C5LeftShift : PatLeaf<(imm), [{
uint64_t C = N->getZExtValue();
- return C > 5 && ((C % 5) == 0) && isPowerOf2_64(C / 5);
+ return C > 5 && (C >> llvm::countr_zero(C)) == 5;
}]>;
def C9LeftShift : PatLeaf<(imm), [{
uint64_t C = N->getZExtValue();
- return C > 9 && ((C % 9) == 0) && isPowerOf2_64(C / 9);
+ return C > 5 && (C >> llvm::countr_zero(C)) == 9;
}]>;
// Constant of the form (3 << C) where C is less than 32.
def C3LeftShiftUW : PatLeaf<(imm), [{
uint64_t C = N->getZExtValue();
- if (C <= 3 || (C % 3) != 0)
- return false;
- C /= 3;
- return isPowerOf2_64(C) && C < (1ULL << 32);
+ unsigned Shift = llvm::countr_zero(C);
+ return 1 <= Shift && Shift < 32 && (C >> Shift) == 3;
}]>;
// Constant of the form (5 << C) where C is less than 32.
def C5LeftShiftUW : PatLeaf<(imm), [{
uint64_t C = N->getZExtValue();
- if (C <= 5 || (C % 5) != 0)
- return false;
- C /= 5;
- return isPowerOf2_64(C) && C < (1ULL << 32);
+ unsigned Shift = llvm::countr_zero(C);
+ return 1 <= Shift && Shift < 32 && (C >> Shift) == 5;
}]>;
// Constant of the form (9 << C) where C is less than 32.
def C9LeftShiftUW : PatLeaf<(imm), [{
uint64_t C = N->getZExtValue();
- if (C <= 9 || (C % 9) != 0)
- return false;
- C /= 9;
- return isPowerOf2_64(C) && C < (1ULL << 32);
+ unsigned Shift = llvm::countr_zero(C);
+ return 1 <= Shift && Shift < 32 && (C >> Shift) == 9;
}]>;
def CSImm12MulBy4 : PatLeaf<(imm), [{