Skip to content

Commit 820e041

Browse files
committed
DAGCombine: prevent formation of illegal ConstantFP nodes.
llvm-svn: 207850
1 parent ea3aca8 commit 820e041

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7181,11 +7181,16 @@ SDValue DAGCombiner::visitFNEG(SDNode *N) {
71817181
// (fneg (fmul c, x)) -> (fmul -c, x)
71827182
if (N0.getOpcode() == ISD::FMUL) {
71837183
ConstantFPSDNode *CFP1 = dyn_cast<ConstantFPSDNode>(N0.getOperand(1));
7184-
if (CFP1)
7185-
return DAG.getNode(ISD::FMUL, SDLoc(N), VT,
7186-
N0.getOperand(0),
7187-
DAG.getNode(ISD::FNEG, SDLoc(N), VT,
7188-
N0.getOperand(1)));
7184+
if (CFP1) {
7185+
APFloat CVal = CFP1->getValueAPF();
7186+
CVal.changeSign();
7187+
if (Level >= AfterLegalizeDAG &&
7188+
(TLI.isFPImmLegal(CVal, N->getValueType(0)) ||
7189+
TLI.isOperationLegal(ISD::ConstantFP, N->getValueType(0))))
7190+
return DAG.getNode(
7191+
ISD::FMUL, SDLoc(N), VT, N0.getOperand(0),
7192+
DAG.getNode(ISD::FNEG, SDLoc(N), VT, N0.getOperand(1)));
7193+
}
71897194
}
71907195

71917196
return SDValue();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc -mtriple=arm64 -fp-contract=fast -o - %s | FileCheck %s
2+
3+
4+
; Make sure we don't try to fold an fneg into +0.0, creating an illegal constant
5+
; -0.0. It's also good, though not essential, that we don't resort to a litpool.
6+
define double @test_fms_fold(double %a, double %b) {
7+
; CHECK-LABEL: test_fms_fold:
8+
; CHECK: fmov {{d[0-9]+}}, xzr
9+
; CHECK: ret
10+
%mul = fmul double %a, 0.000000e+00
11+
%mul1 = fmul double %b, 0.000000e+00
12+
%sub = fsub double %mul, %mul1
13+
ret double %sub
14+
}

0 commit comments

Comments
 (0)