radeon/llvm: Add optimization for FP_ROUND
authorTom Stellard <thomas.stellard@amd.com>
Thu, 13 Sep 2012 15:08:40 +0000 (15:08 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Fri, 21 Sep 2012 19:30:57 +0000 (19:30 +0000)
src/gallium/drivers/radeon/R600ISelLowering.cpp
src/gallium/drivers/radeon/R600ISelLowering.h

index a9b0c70fd951456f71dbe6a447a8626f32b19fcf..e84983df514580d2a3357ae5a1d432c9fa875730 100644 (file)
@@ -50,6 +50,9 @@ R600TargetLowering::R600TargetLowering(TargetMachine &TM) :
   setOperationAction(ISD::SETCC, MVT::i32, Custom);
   setOperationAction(ISD::SETCC, MVT::f32, Custom);
   setOperationAction(ISD::FP_TO_UINT, MVT::i1, Custom);
+
+  setTargetDAGCombine(ISD::FP_ROUND);
+
   setSchedulingPreference(Sched::VLIW);
 }
 
@@ -603,3 +606,26 @@ SDValue R600TargetLowering::LowerFormalArguments(
   }
   return Chain;
 }
+
+//===----------------------------------------------------------------------===//
+// Custom DAG Optimizations
+//===----------------------------------------------------------------------===//
+
+SDValue R600TargetLowering::PerformDAGCombine(SDNode *N,
+                                              DAGCombinerInfo &DCI) const
+{
+  SelectionDAG &DAG = DCI.DAG;
+
+  switch (N->getOpcode()) {
+  // (f32 fp_round (f64 uint_to_fp a)) -> (f32 uint_to_fp a)
+  case ISD::FP_ROUND: {
+      SDValue Arg = N->getOperand(0);
+      if (Arg.getOpcode() == ISD::UINT_TO_FP && Arg.getValueType() == MVT::f64) {
+        return DAG.getNode(ISD::UINT_TO_FP, N->getDebugLoc(), N->getValueType(0),
+                           Arg.getOperand(0));
+      }
+      break;
+    }
+  }
+  return SDValue();
+}
index f2999a30acab372b2b7af60603d131f907152e9d..017c6dba7a7286170566bca378a34eef18ca654f 100644 (file)
@@ -27,6 +27,7 @@ public:
   virtual MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr *MI,
       MachineBasicBlock * BB) const;
   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
+  virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
   void ReplaceNodeResults(SDNode * N,
       SmallVectorImpl<SDValue> &Results,
       SelectionDAG &DAG) const;