[llvm] [GISel] Convert zext nneg to sext if it is cheaper (PR #93856)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 01:26:44 PDT 2024


================
@@ -7407,3 +7407,23 @@ bool CombinerHelper::matchZextOfTrunc(const MachineOperand &MO,
 
   return false;
 }
+
+bool CombinerHelper::matchNonNegZext(const MachineOperand &MO,
+                                     BuildFnTy &MatchInfo) {
+  GZext *Zext = cast<GZext>(MRI.getVRegDef(MO.getReg()));
+
+  Register Dst = Zext->getReg(0);
+  Register Src = Zext->getSrcReg();
+
+  LLT DstTy = MRI.getType(Dst);
+  LLT SrcTy = MRI.getType(Src);
+  const auto &TLI = getTargetLowering();
+
+  // Convert zext nneg to sext if sext is the preferred form for the target.
+  if (TLI.isSExtCheaperThanZExt(getMVTForLLT(SrcTy), getMVTForLLT(DstTy))) {
+    MatchInfo = [=](MachineIRBuilder &B) { B.buildSExt(Dst, Src); };
----------------
dtcxzyw wrote:

Done.

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


More information about the llvm-commits mailing list