[sdag] Add the helper I most want to the DAG -- building a bitcast
authorChandler Carruth <chandlerc@gmail.com>
Sat, 30 May 2015 04:14:10 +0000 (04:14 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 30 May 2015 04:14:10 +0000 (04:14 +0000)
around a value using its existing SDLoc.

Start using this in just one function to save omg lines of code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238638 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAG.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/Target/X86/X86ISelLowering.cpp

index 89f9005b8b2111f7a7d8eb9a62ca01591222c21a..78fdd040773e3f12bc4edc367fcf716c2cc30228 100644 (file)
@@ -878,6 +878,10 @@ public:
   /// Return an MDNodeSDNode which holds an MDNode.
   SDValue getMDNode(const MDNode *MD);
 
+  /// Return a bitcast using the SDLoc of the value operand, and casting to the
+  /// provided type. Use getNode to set a custom SDLoc.
+  SDValue getBitcast(EVT VT, SDValue V);
+
   /// Return an AddrSpaceCastSDNode.
   SDValue getAddrSpaceCast(SDLoc dl, EVT VT, SDValue Ptr,
                            unsigned SrcAS, unsigned DestAS);
index efd4bd9a4d89369d923b036e3f2f94bfefb1f69e..b9eb8f0d0ff7ca49d6d6be7bdcb9b235f00ac9aa 100644 (file)
@@ -1810,6 +1810,13 @@ SDValue SelectionDAG::getMDNode(const MDNode *MD) {
   return SDValue(N, 0);
 }
 
+SDValue SelectionDAG::getBitcast(EVT VT, SDValue V) {
+  if (VT == V.getValueType())
+    return V;
+
+  return getNode(ISD::BITCAST, SDLoc(V), VT, V);
+}
+
 /// getAddrSpaceCast - Return an AddrSpaceCastSDNode.
 SDValue SelectionDAG::getAddrSpaceCast(SDLoc dl, EVT VT, SDValue Ptr,
                                        unsigned SrcAS, unsigned DestAS) {
index 6e37b7355fc74e7a417a67db85df4c69c5ee9c5d..29adedbae5520171c7001da0df184b268269065c 100644 (file)
@@ -17515,24 +17515,19 @@ static SDValue LowerVectorCTPOPBitmath(SDValue Op, SDLoc DL,
   SDValue V = Op;
 
   // v = v - ((v >> 1) & 0x55555555...)
-  SDValue Srl = DAG.getNode(
-      ISD::BITCAST, DL, VT,
-      GetShift(ISD::SRL, DAG.getNode(ISD::BITCAST, DL, SrlVT, V), 1));
+  SDValue Srl =
+      DAG.getBitcast(VT, GetShift(ISD::SRL, DAG.getBitcast(SrlVT, V), 1));
   SDValue And = GetMask(Srl, APInt::getSplat(Len, APInt(8, 0x55)));
   V = DAG.getNode(ISD::SUB, DL, VT, V, And);
 
   // v = (v & 0x33333333...) + ((v >> 2) & 0x33333333...)
   SDValue AndLHS = GetMask(V, APInt::getSplat(Len, APInt(8, 0x33)));
-  Srl = DAG.getNode(
-      ISD::BITCAST, DL, VT,
-      GetShift(ISD::SRL, DAG.getNode(ISD::BITCAST, DL, SrlVT, V), 2));
+  Srl = DAG.getBitcast(VT, GetShift(ISD::SRL, DAG.getBitcast(SrlVT, V), 2));
   SDValue AndRHS = GetMask(Srl, APInt::getSplat(Len, APInt(8, 0x33)));
   V = DAG.getNode(ISD::ADD, DL, VT, AndLHS, AndRHS);
 
   // v = (v + (v >> 4)) & 0x0F0F0F0F...
-  Srl = DAG.getNode(
-      ISD::BITCAST, DL, VT,
-      GetShift(ISD::SRL, DAG.getNode(ISD::BITCAST, DL, SrlVT, V), 4));
+  Srl = DAG.getBitcast(VT, GetShift(ISD::SRL, DAG.getBitcast(SrlVT, V), 4));
   SDValue Add = DAG.getNode(ISD::ADD, DL, VT, V, Srl);
   V = GetMask(Add, APInt::getSplat(Len, APInt(8, 0x0F)));
 
@@ -17545,19 +17540,18 @@ static SDValue LowerVectorCTPOPBitmath(SDValue Op, SDLoc DL,
   // using the fastest of the two for each size.
   MVT ByteVT = MVT::getVectorVT(MVT::i8, VecSize / 8);
   MVT ShiftVT = MVT::getVectorVT(MVT::i64, VecSize / 64);
-  V = DAG.getNode(ISD::BITCAST, DL, ByteVT, V);
+  V = DAG.getBitcast(ByteVT, V);
   assert(Len <= 64 && "We don't support element sizes of more than 64 bits!");
   assert(isPowerOf2_32(Len) && "Only power of two element sizes supported!");
   for (int i = Len; i > 8; i /= 2) {
-    SDValue Shl = DAG.getNode(
-        ISD::BITCAST, DL, ByteVT,
-        GetShift(ISD::SHL, DAG.getNode(ISD::BITCAST, DL, ShiftVT, V), i / 2));
+    SDValue Shl = DAG.getBitcast(
+        ByteVT, GetShift(ISD::SHL, DAG.getBitcast(ShiftVT, V), i / 2));
     V = DAG.getNode(ISD::ADD, DL, ByteVT, V, Shl);
   }
 
   // The high byte now contains the sum of the element bytes. Shift it right
   // (if needed) to make it the low byte.
-  V = DAG.getNode(ISD::BITCAST, DL, VT, V);
+  V = DAG.getBitcast(VT, V);
   if (Len > 8)
     V = GetShift(ISD::SRL, V, Len - 8);