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

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 08:14:36 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
----------------
lenary wrote:

Why can't you use `m_DeferredReg`?

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


More information about the llvm-commits mailing list