emit signed integer subtractions as 'sub nsw', patch by

Anton Yartsev!

llvm-svn: 99817
This commit is contained in:
Chris Lattner 2010-03-29 17:28:16 +00:00
parent bd477bef25
commit 5902e7bb22
1 changed files with 5 additions and 0 deletions

View File

@ -1337,6 +1337,11 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
if (Ops.LHS->getType()->isFPOrFPVectorTy())
return Builder.CreateFSub(Ops.LHS, Ops.RHS, "sub");
// Signed integer overflow is undefined behavior.
if (Ops.Ty->isSignedIntegerType())
return Builder.CreateNSWSub(Ops.LHS, Ops.RHS, "sub");
return Builder.CreateSub(Ops.LHS, Ops.RHS, "sub");
}