[llvm] [AArch64][GlobalISel] Improve MULL generation (PR #112405)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 25 04:01:04 PDT 2024
================
@@ -438,6 +438,109 @@ void applyCombineMulCMLT(MachineInstr &MI, MachineRegisterInfo &MRI,
MI.eraseFromParent();
}
+// Match mul({z/s}ext , {z/s}ext) => {u/s}mull
+bool matchExtMulToMULL(MachineInstr &MI, MachineRegisterInfo &MRI,
+ GISelKnownBits *KB,
+ std::tuple<bool, Register, Register> &MatchInfo) {
+ // Get the instructions that defined the source operand
+ LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
+ MachineInstr *I1 = getDefIgnoringCopies(MI.getOperand(1).getReg(), MRI);
+ MachineInstr *I2 = getDefIgnoringCopies(MI.getOperand(2).getReg(), MRI);
+ unsigned I1Opc = I1->getOpcode();
+ unsigned I2Opc = I2->getOpcode();
+
+ if (!DstTy.isVector() || I1->getNumOperands() < 2 || I2->getNumOperands() < 2)
+ return false;
+
+ auto IsAtLeastDoubleExtend = [&](Register R) {
+ LLT Ty = MRI.getType(R);
+ return DstTy.getScalarSizeInBits() >= Ty.getScalarSizeInBits() * 2;
+ };
+
+ // If the source operands were EXTENDED before, then {U/S}MULL can be used
+ bool IsZExt1 =
+ I1Opc == TargetOpcode::G_ZEXT || I1Opc == TargetOpcode::G_ANYEXT;
+ bool IsZExt2 =
+ I2Opc == TargetOpcode::G_ZEXT || I2Opc == TargetOpcode::G_ANYEXT;
+ if (IsZExt1 && IsZExt2 && IsAtLeastDoubleExtend(I1->getOperand(1).getReg()) &&
+ IsAtLeastDoubleExtend(I2->getOperand(1).getReg())) {
+ get<0>(MatchInfo) = true;
+ get<1>(MatchInfo) = I1->getOperand(1).getReg();
+ get<2>(MatchInfo) = I2->getOperand(1).getReg();
+ return true;
+ }
+
+ bool IsSExt1 =
+ I1Opc == TargetOpcode::G_SEXT || I1Opc == TargetOpcode::G_ANYEXT;
+ bool IsSExt2 =
+ I2Opc == TargetOpcode::G_SEXT || I2Opc == TargetOpcode::G_ANYEXT;
----------------
davemgreen wrote:
The original SDAG code had a similar (separate stand-alone) function, but I deliberately removed them as they were too trivial to be useful. We might want to readd them in the future but for the moment this seems like less code that is simpler to understand.
https://github.com/llvm/llvm-project/pull/112405
More information about the llvm-commits
mailing list