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

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 14:06:49 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;
----------------
aemerson wrote:

Why is this legality check here?

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


More information about the llvm-commits mailing list