[llvm] [GISel][RISCV] Implement selectShiftMask. (PR #77572)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 20:45:15 PST 2024
================
@@ -159,9 +160,72 @@ RISCVInstructionSelector::RISCVInstructionSelector(
InstructionSelector::ComplexRendererFns
RISCVInstructionSelector::selectShiftMask(MachineOperand &Root) const {
- // TODO: Also check if we are seeing the result of an AND operation which
- // could be bypassed since we only check the lower log2(xlen) bits.
- return {{[=](MachineInstrBuilder &MIB) { MIB.add(Root); }}};
+ if (!Root.isReg())
+ return std::nullopt;
+
+ using namespace llvm::MIPatternMatch;
+ MachineRegisterInfo &MRI = MF->getRegInfo();
+
+ Register RootReg = Root.getReg();
+ Register ShAmtReg = RootReg;
+ const LLT ShiftLLT = MRI.getType(RootReg);
+ unsigned ShiftWidth = ShiftLLT.getSizeInBits();
+ assert(isPowerOf2_32(ShiftWidth) && "Unexpected max shift amount!");
+ // Peek through zext.
+ Register ZExtSrcReg;
+ if (mi_match(ShAmtReg, MRI, m_GZExt(m_Reg(ZExtSrcReg)))) {
+ ShAmtReg = ZExtSrcReg;
+ }
+
+ APInt AndMask;
+ Register AndSrcReg;
+ if (mi_match(ShAmtReg, MRI, m_GAnd(m_Reg(AndSrcReg), m_ICst(AndMask)))) {
+ APInt ShMask(AndMask.getBitWidth(), ShiftWidth - 1);
+ if (ShMask.isSubsetOf(AndMask)) {
+ ShAmtReg = AndSrcReg;
+ } else {
+ // TODO:
----------------
topperc wrote:
What's the TODO?
https://github.com/llvm/llvm-project/pull/77572
More information about the llvm-commits
mailing list