diff options
| author | Owen Anderson <resistor@mac.com> | 2012-05-30 18:50:39 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2012-05-30 18:50:39 +0000 |
| commit | c7aaf523e17788dba8b993a224295945dae52d98 (patch) | |
| tree | b8ca14b584286232af5c99630ec6c05628655b95 | |
| parent | fba46a64aad660effe31259044422520553d4f8b (diff) | |
| download | bcm5719-llvm-c7aaf523e17788dba8b993a224295945dae52d98.tar.gz bcm5719-llvm-c7aaf523e17788dba8b993a224295945dae52d98.zip | |
Teach DAGCombine to canonicalize the position of a constant in the term operands of an FMA node.
llvm-svn: 157707
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/CodeGen/ARM/fusedMAC.ll | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index af614937de3..647ff6b6b20 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -5770,6 +5770,10 @@ SDValue DAGCombiner::visitFMA(SDNode *N) { if (N1CFP && N1CFP->isExactlyValue(1.0)) return DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N0, N2); + // Canonicalize (fma c, x, y) -> (fma x, c, y) + if (!N0CFP && N1CFP) + return DAG.getNode(ISD::FMA, N->getDebugLoc(), VT, N1, N0, N2); + return SDValue(); } diff --git a/llvm/test/CodeGen/ARM/fusedMAC.ll b/llvm/test/CodeGen/ARM/fusedMAC.ll index fd7fdd5405a..8ebca02df99 100644 --- a/llvm/test/CodeGen/ARM/fusedMAC.ll +++ b/llvm/test/CodeGen/ARM/fusedMAC.ll @@ -189,6 +189,15 @@ define float @test_fma_const_fold(float %a, float %b) nounwind { ret float %ret } +define float @test_fma_canonicalize(float %a, float %b) nounwind { +; CHECK: test_fma_canonicalize +; CHECK: vmov.f32 s0 +; CHECK: vfma.f32 s2, s0, s1 + %ret = call float @llvm.fma.f32(float 2.0, float %a, float %b) + ret float %ret +} + + declare float @llvm.fma.f32(float, float, float) nounwind readnone declare double @llvm.fma.f64(double, double, double) nounwind readnone declare <2 x float> @llvm.fma.v2f32(<2 x float>, <2 x float>, <2 x float>) nounwind readnone |

