[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 14:34:21 PST 2025


================
@@ -7062,6 +7062,36 @@ 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;
----------------
mshockwave wrote:

Oops must be left there by accident. It's removed now.

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


More information about the llvm-commits mailing list