Author: hans Date: Thu Jan 22 10:58:19 2015 New Revision: 226839 URL: http://llvm.org/viewvc/llvm-project?rev=226839&view=rev Log: Merging r226755: ------------------------------------------------------------------------ r226755 | sanjoy | 2015-01-21 16:48:47 -0800 (Wed, 21 Jan 2015) | 11 lines
Make ScalarEvolution less aggressive with respect to no-wrap flags. ScalarEvolution currently lowers a subtraction recurrence to an add recurrence with the same no-wrap flags as the subtraction. This is incorrect because `sub nsw X, Y` is not the same as `add nsw X, -Y` and `sub nuw X, Y` is not the same as `add nuw X, -Y`. This patch fixes the issue, and adds two test cases demonstrating the bug. Differential Revision: http://reviews.llvm.org/D7081 ------------------------------------------------------------------------ Added: llvm/branches/release_36/test/Analysis/ScalarEvolution/nw-sub-is-not-nw-add.ll - copied unchanged from r226755, llvm/trunk/test/Analysis/ScalarEvolution/nw-sub-is-not-nw-add.ll Modified: llvm/branches/release_36/ (props changed) llvm/branches/release_36/lib/Analysis/ScalarEvolution.cpp Propchange: llvm/branches/release_36/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Jan 22 10:58:19 2015 @@ -1,3 +1,3 @@ /llvm/branches/Apple/Pertwee:110850,110961 /llvm/branches/type-system-rewrite:133420-134817 -/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473 +/llvm/trunk:155241,226023,226029,226044,226046,226048,226058,226075,226170-226171,226182,226473,226755 Modified: llvm/branches/release_36/lib/Analysis/ScalarEvolution.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_36/lib/Analysis/ScalarEvolution.cpp?rev=226839&r1=226838&r2=226839&view=diff ============================================================================== --- llvm/branches/release_36/lib/Analysis/ScalarEvolution.cpp (original) +++ llvm/branches/release_36/lib/Analysis/ScalarEvolution.cpp Thu Jan 22 10:58:19 2015 @@ -3154,8 +3154,9 @@ const SCEV *ScalarEvolution::getMinusSCE if (LHS == RHS) return getConstant(LHS->getType(), 0); - // X - Y --> X + -Y - return getAddExpr(LHS, getNegativeSCEV(RHS), Flags); + // X - Y --> X + -Y. + // X -(nsw || nuw) Y --> X + -Y. + return getAddExpr(LHS, getNegativeSCEV(RHS)); } /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion of the @@ -3461,12 +3462,10 @@ const SCEV *ScalarEvolution::createNodeF if (isKnownPositive(getMinusSCEV(getSCEV(GEP), Ptr))) Flags = setFlags(Flags, SCEV::FlagNUW); } - } else if (const SubOperator *OBO = - dyn_cast<SubOperator>(BEValueV)) { - if (OBO->hasNoUnsignedWrap()) - Flags = setFlags(Flags, SCEV::FlagNUW); - if (OBO->hasNoSignedWrap()) - Flags = setFlags(Flags, SCEV::FlagNSW); + + // We cannot transfer nuw and nsw flags from subtraction + // operations -- sub nuw X, Y is not the same as add nuw X, -Y + // for instance. } const SCEV *StartVal = getSCEV(StartValueV); _______________________________________________ llvm-branch-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/llvm-branch-commits
