[llvm] [GlobalIsel] Modernize truncate of ext. (PR #100338)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 05:07:42 PDT 2024
================
@@ -113,3 +113,45 @@ bool CombinerHelper::matchNonNegZext(const MachineOperand &MO,
return false;
}
+
+bool CombinerHelper::matchTruncateOfExt(const MachineInstr &Root,
+ const MachineInstr &ExtMI,
+ BuildFnTy &MatchInfo) {
+ const GTrunc *Trunc = cast<GTrunc>(&Root);
+ const GExtOp *Ext = cast<GExtOp>(&ExtMI);
+
+ if (!MRI.hasOneNonDBGUse(Ext->getReg(0)))
+ return false;
+
+ Register Dst = Trunc->getReg(0);
+ Register Src = Ext->getSrcReg();
+ LLT DstTy = MRI.getType(Dst);
+ LLT SrcTy = MRI.getType(Src);
+
+ if (SrcTy == DstTy) {
+ // The source and the destination are equally sized. We need to copy.
+ MatchInfo = [=](MachineIRBuilder &B) { B.buildCopy(Dst, Src); };
+
+ return true;
+ } else if (SrcTy.getScalarSizeInBits() < DstTy.getScalarSizeInBits()) {
+ // Protect against scalable vectors.
----------------
arsenm wrote:
That makes it make less sense? getScalarSizeInBits should still work for scalable
https://github.com/llvm/llvm-project/pull/100338
More information about the llvm-commits
mailing list