[llvm] [GISel] Combine `(neg (min/max x, (neg x)))` into `(max/min x, (neg x))` (PR #120998)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 09:52:40 PST 2025


================
@@ -7045,6 +7045,41 @@ bool CombinerHelper::matchSelectIMinMax(const MachineOperand &MO,
   }
 }
 
+// (neg (min/max x, (neg x))) --> (max/min x, (neg x))
+bool CombinerHelper::matchSimplifyNegMinMax(MachineInstr &MI,
+                                            BuildFnTy &MatchInfo) const {
+  assert(MI.getOpcode() == TargetOpcode::G_SUB);
+  Register DestReg = MI.getOperand(0).getReg();
+  LLT DestTy = MRI.getType(DestReg);
+  if (!isLegal({TargetOpcode::G_SUB, {DestTy}}))
+    return false;
+
+  // GISel doesn't have m_Deferred at this moment, so we have to
----------------
mshockwave wrote:

> Why can't you use `m_DeferredReg`?

oh it was this patch that _inspired_ my `m_DeferredReg/Type` patch. I'll update this patch to use `m_DeferredReg` shortly.

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


More information about the llvm-commits mailing list