DAGCombine: clamp hi bit in APInt::getBitsSet to avoid assertion
[oota-llvm.git] / lib / CodeGen / SelectionDAG / DAGCombiner.cpp
index 1c28d6dcaf4c76ee84fc66c421f85857ece73f89..893cf2036a469caa586bda886267db7b57c4fc01 100644 (file)
@@ -7433,7 +7433,8 @@ SDValue DAGCombiner::ReduceLoadOpStoreWidth(SDNode *N) {
     // start at the previous one.
     if (ShAmt % NewBW)
       ShAmt = (((ShAmt + NewBW - 1) / NewBW) * NewBW) - NewBW;
-    APInt Mask = APInt::getBitsSet(BitWidth, ShAmt, ShAmt + NewBW);
+    APInt Mask = APInt::getBitsSet(BitWidth, ShAmt,
+                                   std::min(BitWidth, ShAmt + NewBW));
     if ((Imm & Mask) == Imm) {
       APInt NewImm = (Imm & Mask).lshr(ShAmt).trunc(NewBW);
       if (Opc == ISD::AND)