Skip to content

Commit 54ef895

Browse files
committedFeb 26, 2015
SCEVExpander incorrectly marks generated subtractions as nuw/nsw
It is not sound to mark the increment operation as `nuw` or `nsw` based on a proof off of the add recurrence if the increment operation we emit happens to be a `sub` instruction. I could not come up with a test case for this -- the cases where SCEVExpander decides to emit a `sub` instruction is quite small, and I cannot think of a way I'd be able to get SCEV to prove that the increment does not overflow in those cases. Differential Revision: http://reviews.llvm.org/D7899 llvm-svn: 230673
1 parent fa147e0 commit 54ef895

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed
 

‎llvm/lib/Analysis/ScalarEvolutionExpander.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1182,9 +1182,6 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
11821182
}
11831183
}
11841184

1185-
bool IncrementIsNUW = IsIncrementNUW(SE, Normalized);
1186-
bool IncrementIsNSW = IsIncrementNSW(SE, Normalized);
1187-
11881185
// Save the original insertion point so we can restore it when we're done.
11891186
BuilderType::InsertPointGuard Guard(Builder);
11901187

@@ -1219,6 +1216,12 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
12191216
// Expand the step somewhere that dominates the loop header.
12201217
Value *StepV = expandCodeFor(Step, IntTy, L->getHeader()->begin());
12211218

1219+
// The no-wrap behavior proved by IsIncrement(NUW|NSW) is only applicable if
1220+
// we actually do emit an addition. It does not apply if we emit a
1221+
// subtraction.
1222+
bool IncrementIsNUW = !useSubtract && IsIncrementNUW(SE, Normalized);
1223+
bool IncrementIsNSW = !useSubtract && IsIncrementNSW(SE, Normalized);
1224+
12221225
// Create the PHI.
12231226
BasicBlock *Header = L->getHeader();
12241227
Builder.SetInsertPoint(Header, Header->begin());

0 commit comments

Comments
 (0)
Please sign in to comment.