aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprScalar.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-03-29 17:28:16 +0000
committerChris Lattner <sabre@nondot.org>2010-03-29 17:28:16 +0000
commit2eb91e4812d54a1cf634c265a16633a3d3edcf91 (patch)
treef1265b38cfcd3a41552d4058a1e60bb2af4bbb84 /lib/CodeGen/CGExprScalar.cpp
parentadb507df13aeb2334eddef64e6bbdf41a44dc5b1 (diff)
emit signed integer subtractions as 'sub nsw', patch by
Anton Yartsev! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r--lib/CodeGen/CGExprScalar.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 7e26971414..1ef06ccf6f 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -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");
}