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

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 05:08:39 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:

See
https://github.com/llvm/llvm-project/blob/cc4ec6daf0d4f43110e8220d542c1155b8c1ef51/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L6375

and 

https://github.com/llvm/llvm-project/blob/efab4a380f36dcd23561633f8bba484036c500f3/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp#L7432

There is a legality check for DstTy above.

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


More information about the llvm-commits mailing list