[llvm] [DAG] Use copysign in frem power-2 fold. (PR #91751)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat May 11 00:32:59 PDT 2024
================
@@ -17383,15 +17383,22 @@ SDValue DAGCombiner::visitFREM(SDNode *N) {
TLI.isOperationLegalOrCustom(ISD::FMUL, VT) &&
TLI.isOperationLegalOrCustom(ISD::FDIV, VT) &&
TLI.isOperationLegalOrCustom(ISD::FTRUNC, VT) &&
- DAG.isKnownToBeAPowerOfTwoFP(N1) &&
- (Flags.hasNoSignedZeros() || DAG.cannotBeOrderedNegativeFP(N0))) {
- SDValue Div = DAG.getNode(ISD::FDIV, DL, VT, N0, N1);
- SDValue Rnd = DAG.getNode(ISD::FTRUNC, DL, VT, Div);
- if (TLI.isFMAFasterThanFMulAndFAdd(DAG.getMachineFunction(), VT))
- return DAG.getNode(ISD::FMA, DL, VT, DAG.getNode(ISD::FNEG, DL, VT, Rnd),
- N1, N0);
- SDValue Mul = DAG.getNode(ISD::FMUL, DL, VT, Rnd, N1);
- return DAG.getNode(ISD::FSUB, DL, VT, N0, Mul);
+ DAG.isKnownToBeAPowerOfTwoFP(N1)) {
+ bool NeedsCopySign =
+ !Flags.hasNoSignedZeros() && !DAG.cannotBeOrderedNegativeFP(N0);
+ if (!NeedsCopySign || TLI.isOperationLegalOrCustom(ISD::FCOPYSIGN, VT)) {
----------------
arsenm wrote:
I don't see why the legality of copysign matters here. You either need it or not
https://github.com/llvm/llvm-project/pull/91751
More information about the llvm-commits
mailing list