]> granicus.if.org Git - llvm/commit
Bugfix: SCEV incorrectly marks certain expressions as nsw
authorSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 18 Feb 2015 00:43:19 +0000 (00:43 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 18 Feb 2015 00:43:19 +0000 (00:43 +0000)
commit0afc9b33fef2d41d8be638320ed5c65dc1d09d9a
tree61ff7be92b6d1e5380cabcdb5438e187695fdd99
parent40053ce940451c76d066e59e5672224cf1498403
Bugfix: SCEV incorrectly marks certain expressions as nsw

I could not come up with a test case for this one; but I don't think
`getPreStartForSignExtend` can assume `AR` is `nsw` -- there is one
place in scalar evolution that calls `getSignExtendAddRecStart(AR,
...)` without proving that `AR` is `nsw`

(line 1564)

   OperandExtendedAdd =
     getAddExpr(WideStart,
                getMulExpr(WideMaxBECount,
                           getZeroExtendExpr(Step, WideTy)));
   if (SAdd == OperandExtendedAdd) {
     // If AR wraps around then
     //
     //    abs(Step) * MaxBECount > unsigned-max(AR->getType())
     // => SAdd != OperandExtendedAdd
     //
     // Thus (AR is not NW => SAdd != OperandExtendedAdd) <=>
     // (SAdd == OperandExtendedAdd => AR is NW)

     const_cast<SCEVAddRecExpr *>(AR)->setNoWrapFlags(SCEV::FlagNW);

     // Return the expression with the addrec on the outside.
     return getAddRecExpr(getSignExtendAddRecStart(AR, Ty, this),
                          getZeroExtendExpr(Step, Ty),
                          L, AR->getNoWrapFlags());
   }

Differential Revision: http://reviews.llvm.org/D7640

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229594 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ScalarEvolution.cpp