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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 05:04:02 PDT 2024


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:

I don't think this profitability check makes much sense. It would make more sense to check if the resulting immediate is legal, and if it's not, check if it is legal in the other extended case.

If you're going to use it, add an LLT overload and don't have the LLT->MVT conversion be done here.



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


More information about the llvm-commits mailing list