[llvm] [GlobalIsel] Combine cast of const integer. (PR #96139)
Dhruv Chawla via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 02:17:38 PDT 2024
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>,
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>,
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/96139 at github.com>
================
@@ -7428,12 +7428,98 @@ bool CombinerHelper::matchNonNegZext(const MachineOperand &MO,
LLT SrcTy = MRI.getType(Src);
const auto &TLI = getTargetLowering();
+ const MachineFunction &MF = *MO.getParent()->getMF();
+ LLVMContext &Ctx = MF.getFunction().getContext();
+ auto &DL = MF.getDataLayout();
+
// Convert zext nneg to sext if sext is the preferred form for the target.
if (isLegalOrBeforeLegalizer({TargetOpcode::G_SEXT, {DstTy, SrcTy}}) &&
- TLI.isSExtCheaperThanZExt(getMVTForLLT(SrcTy), getMVTForLLT(DstTy))) {
+ TLI.isSExtCheaperThanZExt(SrcTy, DstTy, DL, Ctx)) {
MatchInfo = [=](MachineIRBuilder &B) { B.buildSExt(Dst, Src); };
return true;
}
return false;
}
+
+bool CombinerHelper::matchZextInteger(const MachineInstr &MI,
+ APInt &MatchInfo) {
+ const GZext *Zext = cast<GZext>(&MI);
+
+ std::optional<APInt> Input = getIConstantVRegVal(Zext->getSrcReg(), MRI);
+ if (!Input)
+ return false;
+
+ LLT DstTy = MRI.getType(Zext->getReg(0));
+
+ if (!isConstantLegalOrBeforeLegalizer(DstTy))
+ return false;
+
+ MatchInfo = Input->zext(DstTy.getScalarSizeInBits());
+
+ return true;
+}
+
+bool CombinerHelper::matchSextInteger(const MachineInstr &MI,
+ APInt &MatchInfo) {
+ const GSext *Sext = cast<GSext>(&MI);
+
+ std::optional<APInt> Input = getIConstantVRegVal(Sext->getSrcReg(), MRI);
+ if (!Input)
+ return false;
+
+ LLT DstTy = MRI.getType(Sext->getReg(0));
+
+ if (!isConstantLegalOrBeforeLegalizer(DstTy))
+ return false;
+
+ MatchInfo = Input->sext(DstTy.getScalarSizeInBits());
+
+ return true;
+}
+
+bool CombinerHelper::matchTruncInteger(const MachineInstr &MI,
+ APInt &MatchInfo) {
+ const GTrunc *Trunc = cast<GTrunc>(&MI);
+
+ std::optional<APInt> Input = getIConstantVRegVal(Trunc->getSrcReg(), MRI);
+ if (!Input)
+ return false;
+
+ LLT DstTy = MRI.getType(Trunc->getReg(0));
+
+ if (!isConstantLegalOrBeforeLegalizer(DstTy))
+ return false;
+
+ MatchInfo = Input->trunc(DstTy.getScalarSizeInBits());
+
+ return true;
+}
----------------
dc03-work wrote:
The three functions above have effectively the same definitions. Is it possible to merge them?
https://github.com/llvm/llvm-project/pull/96139
More information about the llvm-commits
mailing list