[llvm] [GlobalIsel] Modernize truncate of ext. (PR #100338)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 05:12:01 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.
----------------
tschuett wrote:
I removed the comment. Wait a minute. `getScalarSizeInBits` works with all kinds of shapes.
https://github.com/llvm/llvm-project/pull/100338
More information about the llvm-commits
mailing list