[PATCH RESEND 2/3] SelectionDAG: Add KnownBits and SignBits computation for EXTRACT_ELEMENT

Jan Vesely jan.vesely at rutgers.edu
Sat Nov 15 14:51:53 PST 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 33620e7..a4645ee 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2323,6 +2323,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)) {
@@ -2522,6 +2534,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