[llvm-commits] [llvm] r156324 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/ARM/unsafe-fsub.ll

Owen Anderson resistor at mac.com
Mon May 7 13:51:26 PDT 2012


Author: resistor
Date: Mon May  7 15:51:25 2012
New Revision: 156324

URL: http://llvm.org/viewvc/llvm-project?rev=156324&view=rev
Log:
Teach DAG combine to fold x-x to 0.0 when unsafe FP math is enabled.

Added:
    llvm/trunk/test/CodeGen/ARM/unsafe-fsub.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=156324&r1=156323&r2=156324&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon May  7 15:51:25 2012
@@ -5670,9 +5670,13 @@
                        GetNegatedExpression(N1, DAG, LegalOperations));
 
   // If 'unsafe math' is enabled, fold
+  //    (fsub x, x) -> 0.0 &
   //    (fsub x, (fadd x, y)) -> (fneg y) &
   //    (fsub x, (fadd y, x)) -> (fneg y)
   if (DAG.getTarget().Options.UnsafeFPMath) {
+    if (N0 == N1)
+      return DAG.getConstantFP(0.0f, VT);
+
     if (N1.getOpcode() == ISD::FADD) {
       SDValue N10 = N1->getOperand(0);
       SDValue N11 = N1->getOperand(1);

Added: llvm/trunk/test/CodeGen/ARM/unsafe-fsub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/unsafe-fsub.ll?rev=156324&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/unsafe-fsub.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/unsafe-fsub.ll Mon May  7 15:51:25 2012
@@ -0,0 +1,18 @@
+; RUN: llc -march=arm -mcpu=cortex-a9 < %s | FileCheck -check-prefix=SAFE %s
+; RUN: llc -march=arm -mcpu=cortex-a9 -enable-unsafe-fp-math < %s | FileCheck -check-prefix=FAST %s
+
+target triple = "armv7-apple-ios"
+
+; SAFE: test
+; FAST: test
+define float @test(float %x, float %y) {
+entry:
+; SAFE: vmul.f32
+; SAFE: vsub.f32
+; FAST: mov r0, #0
+  %0 = fmul float %x, %y
+  %1 = fsub float %0, %0
+  ret float %1
+}
+
+





More information about the llvm-commits mailing list