[PATCH] IndVarSimplify: Don't let LFTR compare against a poison value

Andrew Trick atrick at apple.com
Fri Sep 5 13:15:22 PDT 2014


What you've done is the right idea. We want to allow post-increment comparison whenever we can prove no overflow on the increment. Handling the constant case as you've done seems safe, albeit messy.

A more general way to check overflow is something like this (I haven't tested this in your case):

  unsigned BitWidth = SE->getTypeSizeInBits(BECount->getType());
  // BitWidt+1 should actually be sufficient
  Type *WideTy = IntegerType::get(SE->getContext(), BitWidth * 2);
  IVCount = SE->getAddExpr(BackedgeTakenCount,
                           SE->getConstant(BackedgeTakenCount->getType(), 1));
  IVCountWide = SE->getAddExpr(
                  SE->getSignExtendedExpr(BackedgeTakenCount, WideTy),
                  SE->getConstant(WideTy, 1));
  if (getSignExtendExpr(IVCount, WideTy) == IVCountWide)
    // no signed overflow

You may want to give this a try and make sure it's still safe in the problem case.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D5174






More information about the llvm-commits mailing list