[PATCH 3/4] SlectionDAG: Add KnownBits and SignBits computation for EXTRACT_ELEMENT

Jan Vesely jan.vesely at rutgers.edu
Thu Oct 16 11:41:44 PDT 2014


Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
 lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 7fb7aba..618b786 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2315,6 +2315,18 @@ void SelectionDAG::computeKnownBits(SDValue Op, APInt &KnownZero,
     KnownZero = APInt::getHighBitsSet(BitWidth, Leaders);
     break;
   }
+  case ISD::EXTRACT_ELEMENT: {
+    computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1);
+    const unsigned index =
+      cast<ConstantSDNode>(Op.getOperand(1))->getAPIntValue().getLimitedValue();
+    const unsigned bitwidth = Op.getValueType().getSizeInBits();
+
+    KnownZero = KnownZero.getHiBits(KnownZero.getBitWidth() - index * bitwidth);
+    KnownOne = KnownOne.getHiBits(KnownOne.getBitWidth() - index * bitwidth);
+
+    KnownZero = KnownZero.trunc(bitwidth);
+    KnownOne = KnownOne.trunc(bitwidth);
+  }
   case ISD::FrameIndex:
   case ISD::TargetFrameIndex:
     if (unsigned Align = InferPtrAlignment(Op)) {
@@ -2514,6 +2526,15 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, unsigned Depth) const{
     // FIXME: it's tricky to do anything useful for this, but it is an important
     // case for targets like X86.
     break;
+  case ISD::EXTRACT_ELEMENT: {
+    const int knownsign = ComputeNumSignBits(Op.getOperand(0), Depth+1);
+    const int bitwidth = Op.getValueType().getSizeInBits();
+    const int items =
+      Op.getOperand(0).getValueType().getSizeInBits() / bitwidth;
+    const int rindex = items - 1 -
+      cast<ConstantSDNode>(Op.getOperand(1))->getAPIntValue().getLimitedValue();
+    return std::max(std::min(knownsign - rindex * bitwidth, bitwidth), 0);
+  }
   }
 
   // If we are looking at the loaded value of the SDNode.
-- 
1.9.3




More information about the llvm-commits mailing list