@@ -8406,30 +8406,29 @@ SDValue DAGCombiner::visitFREM(SDNode *N) {
8406
8406
}
8407
8407
8408
8408
SDValue DAGCombiner::visitFSQRT(SDNode *N) {
8409
- if (DAG.getTarget().Options.UnsafeFPMath &&
8410
- !TLI.isFsqrtCheap()) {
8411
- // Compute this as X * (1/sqrt(X)) = X * (X ** -0.5)
8412
- if (SDValue RV = BuildRsqrtEstimate(N->getOperand(0))) {
8413
- EVT VT = RV.getValueType();
8414
- SDLoc DL(N);
8415
- RV = DAG.getNode(ISD::FMUL, DL, VT, N->getOperand(0), RV);
8416
- AddToWorklist(RV.getNode());
8417
-
8418
- // Unfortunately, RV is now NaN if the input was exactly 0.
8419
- // Select out this case and force the answer to 0.
8420
- SDValue Zero = DAG.getConstantFP(0.0, DL, VT);
8421
- SDValue ZeroCmp =
8422
- DAG.getSetCC(DL, TLI.getSetCCResultType(*DAG.getContext(), VT),
8423
- N->getOperand(0), Zero, ISD::SETEQ);
8424
- AddToWorklist(ZeroCmp.getNode());
8425
- AddToWorklist(RV.getNode());
8409
+ if (!DAG.getTarget().Options.UnsafeFPMath || TLI.isFsqrtCheap())
8410
+ return SDValue();
8426
8411
8427
- RV = DAG.getNode(VT.isVector() ? ISD::VSELECT : ISD::SELECT,
8428
- DL, VT, ZeroCmp, Zero, RV);
8429
- return RV;
8430
- }
8431
- }
8432
- return SDValue();
8412
+ // Compute this as X * (1/sqrt(X)) = X * (X ** -0.5)
8413
+ SDValue RV = BuildRsqrtEstimate(N->getOperand(0));
8414
+ if (!RV)
8415
+ return SDValue();
8416
+
8417
+ EVT VT = RV.getValueType();
8418
+ SDLoc DL(N);
8419
+ RV = DAG.getNode(ISD::FMUL, DL, VT, N->getOperand(0), RV);
8420
+ AddToWorklist(RV.getNode());
8421
+
8422
+ // Unfortunately, RV is now NaN if the input was exactly 0.
8423
+ // Select out this case and force the answer to 0.
8424
+ SDValue Zero = DAG.getConstantFP(0.0, DL, VT);
8425
+ EVT CCVT = TLI.getSetCCResultType(*DAG.getContext(), VT);
8426
+ SDValue ZeroCmp = DAG.getSetCC(DL, CCVT, N->getOperand(0), Zero, ISD::SETEQ);
8427
+ AddToWorklist(ZeroCmp.getNode());
8428
+ AddToWorklist(RV.getNode());
8429
+
8430
+ return DAG.getNode(VT.isVector() ? ISD::VSELECT : ISD::SELECT, DL, VT,
8431
+ ZeroCmp, Zero, RV);
8433
8432
}
8434
8433
8435
8434
SDValue DAGCombiner::visitFCOPYSIGN(SDNode *N) {
0 commit comments