[PATCH] D40649: [InstCombine] Don't crash on out of bounds shifts

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 08:59:59 PST 2017


spatel added reviewers: efriedma, majnemer, nlopes.
spatel added a comment.

We should stub this out sooner and in one place. I think we can extend what we did in https://reviews.llvm.org/D38637:

  Index: lib/Analysis/ValueTracking.cpp
  ===================================================================
  --- lib/Analysis/ValueTracking.cpp	(revision 319435)
  +++ lib/Analysis/ValueTracking.cpp	(working copy)
  @@ -800,8 +800,14 @@
     unsigned BitWidth = Known.getBitWidth();
   
     if (auto *SA = dyn_cast<ConstantInt>(I->getOperand(1))) {
  +    if (SA->getZExtValue() >= BitWidth) {
  +      // This shift produces poison because the shift amount is too big. We can
  +      // return anything we want. Choose 0 for the best folding opportunity.
  +      Known.setAllZero();
  +      return;
  +    }
  +
       unsigned ShiftAmt = SA->getLimitedValue(BitWidth-1);
  -
       computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
       Known.Zero = KZF(Known.Zero, ShiftAmt);
       Known.One  = KOF(Known.One, ShiftAmt);


https://reviews.llvm.org/D40649





More information about the llvm-commits mailing list