[llvm] [AMDGPU] Fold fneg into select source modifiers (PR #201426)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 9 02:55:26 PDT 2026


================
@@ -5468,8 +5497,13 @@ SDValue AMDGPUTargetLowering::performFNegCombine(SDNode *N,
   }
   case ISD::SELECT: {
     // fneg (select c, a, b) -> select c, (fneg a), (fneg b)
-    // TODO: Invert conditions of foldFreeOpFromSelect
-    return SDValue();
+    if (!shouldFoldFNegIntoSelect(SDValue(N, 0), N0.getOperand(1),
+                                  N0.getOperand(2)))
+      return SDValue();
+
+    SDValue NegT = DAG.getNode(ISD::FNEG, SL, VT, N0.getOperand(1));
+    SDValue NegF = DAG.getNode(ISD::FNEG, SL, VT, N0.getOperand(2));
+    return DAG.getNode(ISD::SELECT, SL, VT, N0.getOperand(0), NegT, NegF);
----------------
arsenm wrote:

Should try to preserve flags

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


More information about the llvm-commits mailing list