[llvm] [GlobalIsel] Combine cast of const integer. (PR #96139)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 06:34:25 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>


================
@@ -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)))
----------------
arsenm wrote:

But the cast isn't actually being performed. I don't think the DAG code makes any more sense. 

https://github.com/llvm/llvm-project/pull/96139


More information about the llvm-commits mailing list