Expand fabs into fneg
authorChris Lattner <sabre@nondot.org>
Sat, 2 Apr 2005 05:26:37 +0000 (05:26 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 2 Apr 2005 05:26:37 +0000 (05:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21013 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

index 2615a50586221d05a866ae377dfb0918c7179b17..731ea55322295efe758346821348f977f796d5d4 100644 (file)
@@ -887,8 +887,16 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
         Tmp2 = DAG.getConstantFP(-0.0, Node->getValueType(0));
         Result = LegalizeOp(DAG.getNode(ISD::SUB, Node->getValueType(0),
                                         Tmp2, Tmp1));
+      } else if (Node->getOpcode() == ISD::FABS) {
+        // Expand Y = FABS(X) -> Y = (X >u 0.0) ? X : fneg(X).
+        MVT::ValueType VT = Node->getValueType(0);
+        Tmp2 = DAG.getConstantFP(0.0, VT);
+        Tmp2 = DAG.getSetCC(ISD::SETUGT, TLI.getSetCCResultTy(), Tmp1, Tmp2);
+        Tmp3 = DAG.getNode(ISD::FNEG, VT, Tmp1);
+        Result = DAG.getNode(ISD::SELECT, VT, Tmp2, Tmp1, Tmp3);
+        Result = LegalizeOp(Result);
       } else {
-        assert(0 && "Expand fneg not impl yet!");
+        assert(0 && "Unreachable!");
       }
       break;
     }