]> granicus.if.org Git - llvm/commitdiff
[X86][SSE] LowerScalarImmediateShift - ensure shift amount correctness. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 3 Jul 2019 10:47:33 +0000 (10:47 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 3 Jul 2019 10:47:33 +0000 (10:47 +0000)
Assert that the shift amount is in range and create vXi8 shift masks in a way that doesn't cause MSVC/cppcheck shift result is truncated then extended warnings.

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

lib/Target/X86/X86ISelLowering.cpp

index 1f5b41ecb09a367c1c9313ec3f24fcf8316edf3f..6050b9217ce44926561d833d5f10161ec49c318f 100644 (file)
@@ -25016,6 +25016,8 @@ static SDValue LowerScalarImmediateShift(SDValue Op, SelectionDAG &DAG,
   APInt APIntShiftAmt;
   if (!isConstantSplat(Amt, APIntShiftAmt))
     return SDValue();
+  assert(APIntShiftAmt.ult(VT.getScalarSizeInBits()) &&
+         "Out of range shift amount");
   uint64_t ShiftAmt = APIntShiftAmt.getZExtValue();
 
   if (SupportedVectorShiftWithImm(VT, Subtarget, Op.getOpcode()))
@@ -25057,8 +25059,8 @@ static SDValue LowerScalarImmediateShift(SDValue Op, SelectionDAG &DAG,
                                                ShiftAmt, DAG);
       SHL = DAG.getBitcast(VT, SHL);
       // Zero out the rightmost bits.
-      return DAG.getNode(ISD::AND, dl, VT, SHL,
-                         DAG.getConstant(uint8_t(-1U << ShiftAmt), dl, VT));
+      APInt Mask = APInt::getHighBitsSet(8, 8 - ShiftAmt);
+      return DAG.getNode(ISD::AND, dl, VT, SHL, DAG.getConstant(Mask, dl, VT));
     }
     if (Op.getOpcode() == ISD::SRL) {
       // Make a large shift.