[llvm] [SelectionDAG] Handle `fneg`/`fabs`/`fcopysign` in `SimplifyDemandedBits` (PR #139239)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 01:33:39 PDT 2025


================
@@ -2966,6 +2966,81 @@ bool TargetLowering::SimplifyDemandedBits(
     }
     break;
   }
+  case ISD::FABS: {
+    SDValue Op0 = Op.getOperand(0);
+    APInt SignMask = APInt::getSignMask(BitWidth);
+
+    if (!DemandedBits.intersects(SignMask))
+      return TLO.CombineTo(Op, Op0);
+
+    if (SimplifyDemandedBits(Op0, ~SignMask & DemandedBits, DemandedElts, Known,
+                             TLO, Depth + 1))
+      return true;
+
+    if (Known.isNonNegative())
----------------
RKSimon wrote:

If you're not demanding the signbit how can you guarantee that the Known signbit is set correctly? Unless its demanded each KnownBit bit returned by SimplifyDemandedBits is effectively UB

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


More information about the llvm-commits mailing list