[llvm] [GlobalIsel][NFC] Modernize UBFX combine (PR #97513)
Dhruv Chawla via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 22:27:02 PDT 2024
================
@@ -4521,19 +4521,21 @@ bool CombinerHelper::matchBitfieldExtractFromSExtInReg(
}
/// Form a G_UBFX from "(a srl b) & mask", where b and mask are constants.
-bool CombinerHelper::matchBitfieldExtractFromAnd(
- MachineInstr &MI, std::function<void(MachineIRBuilder &)> &MatchInfo) {
- assert(MI.getOpcode() == TargetOpcode::G_AND);
- Register Dst = MI.getOperand(0).getReg();
+bool CombinerHelper::matchBitfieldExtractFromAnd(MachineInstr &MI,
+ BuildFnTy &MatchInfo) {
+ GAnd *And = cast<GAnd>(&MI);
+ Register Dst = And->getReg(0);
LLT Ty = MRI.getType(Dst);
LLT ExtractTy = getTargetLowering().getPreferredShiftAmountTy(Ty);
+ // Note that isLegalOrBeforeLegalizer is stricter and does not take custom
+ // into account.
if (LI && !LI->isLegalOrCustom({TargetOpcode::G_UBFX, {Ty, ExtractTy}}))
return false;
int64_t AndImm, LSBImm;
Register ShiftSrc;
const unsigned Size = Ty.getScalarSizeInBits();
- if (!mi_match(MI.getOperand(0).getReg(), MRI,
+ if (!mi_match(And->getReg(0), MRI,
m_GAnd(m_OneNonDBGUse(m_GLShr(m_Reg(ShiftSrc), m_ICst(LSBImm))),
m_ICst(AndImm))))
----------------
dc03-work wrote:
> 1. It is collecting registers and int64_t s.
> 2. `mi_match` returns a boolean. I don't want to and cannot ignore it.
> 3. I could add a comment: "Cannot fail due to pattern."
1. You can add those as function parameters and pass them from the TableGen.
2. The only part of this match that differs from the TableGen is the `m_OneNonDBGUse` bit, which you can add as a separate condition. You can also use the `HasOneUse` predicate (#91578).
https://github.com/llvm/llvm-project/pull/97513
More information about the llvm-commits
mailing list