Add an assertion to the form of SelectionDAG::getConstant that takes
a uint64_t to verify that the value is in range for the given type,
to help catch accidental overflow. Fix a few places that relied on
getConstant implicitly truncating the value.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63128 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index d1759c1..d4df880 100644
--- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2434,11 +2434,12 @@
     if (ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101)) {
       MVT TruncVT = N1.getValueType();
       SDValue N100 = N1.getOperand(0).getOperand(0);
+      uint64_t TruncC = TruncVT.getIntegerVTBitMask() &
+                        N101C->getZExtValue();
       return DAG.getNode(ISD::SHL, VT, N0,
                          DAG.getNode(ISD::AND, TruncVT,
                                      DAG.getNode(ISD::TRUNCATE, TruncVT, N100),
-                                     DAG.getConstant(N101C->getZExtValue(),
-                                                     TruncVT)));
+                                     DAG.getConstant(TruncC, TruncVT)));
     }
   }
 
@@ -2561,11 +2562,12 @@
     if (ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101)) {
       MVT TruncVT = N1.getValueType();
       SDValue N100 = N1.getOperand(0).getOperand(0);
+      uint64_t TruncC = TruncVT.getIntegerVTBitMask() &
+                        N101C->getZExtValue();
       return DAG.getNode(ISD::SRA, VT, N0,
                          DAG.getNode(ISD::AND, TruncVT,
                                      DAG.getNode(ISD::TRUNCATE, TruncVT, N100),
-                                     DAG.getConstant(N101C->getZExtValue(),
-                                                     TruncVT)));
+                                     DAG.getConstant(TruncC, TruncVT)));
     }
   }
 
@@ -2678,11 +2680,12 @@
     if (ConstantSDNode *N101C = dyn_cast<ConstantSDNode>(N101)) {
       MVT TruncVT = N1.getValueType();
       SDValue N100 = N1.getOperand(0).getOperand(0);
+      uint64_t TruncC = TruncVT.getIntegerVTBitMask() &
+                        N101C->getZExtValue();
       return DAG.getNode(ISD::SRL, VT, N0,
                          DAG.getNode(ISD::AND, TruncVT,
                                      DAG.getNode(ISD::TRUNCATE, TruncVT, N100),
-                                     DAG.getConstant(N101C->getZExtValue(),
-                                                     TruncVT)));
+                                     DAG.getConstant(TruncC, TruncVT)));
     }
   }