[llvm] [GlobalIsel] Combine cast of const integer. (PR #96139)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 13:23:59 PDT 2024
================
@@ -7491,3 +7491,27 @@ bool CombinerHelper::matchTruncInteger(const MachineInstr &MI,
return true;
}
+
+bool CombinerHelper::matchAnyextInteger(const MachineInstr &MI,
+ APInt &MatchInfo) {
+ const GAnyExt *Anyext = cast<GAnyExt>(&MI);
+
+ std::optional<APInt> Input = getIConstantVRegVal(Anyext->getSrcReg(), MRI);
+ if (!Input)
+ return false;
+
+ LLT DstTy = MRI.getType(Anyext->getReg(0));
+ LLT SrcTy = MRI.getType(Anyext->getSrcReg());
+ const auto &TLI = getTargetLowering();
+
+ if (!isConstantLegalOrBeforeLegalizer(DstTy))
+ return false;
+
+ // Some targets like RISCV prefer to sign extend some types.
+ if (TLI.isSExtCheaperThanZExt(getMVTForLLT(SrcTy), getMVTForLLT(DstTy)))
----------------
tschuett wrote:
It is not a profitability check. It is about that RISC-V picks sext for anyext and AArch64 picks zext. The result may differ.
https://github.com/llvm/llvm-project/pull/96139
More information about the llvm-commits
mailing list