[PATCH] IndVarSimplify: Don't let LFTR compare against a poison value
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,
IVCountWide = SE->getAddExpr(
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.
More information about the llvm-commits