summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-01-06 14:22:52 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-01-06 14:22:52 +0000
commitae67cc13a99e65b00f5e706514e2ca4e6ea880fd (patch)
treef40003976ad23bbf8f299f090741ce8c138cfc81
parent605f21a6c857260e2a46f09333ef223ad4cdee52 (diff)
downloadbcm5719-llvm-ae67cc13a99e65b00f5e706514e2ca4e6ea880fd.tar.gz
bcm5719-llvm-ae67cc13a99e65b00f5e706514e2ca4e6ea880fd.zip
InstCombine: Turn _chk functions into the "unsafe" variant if length and max langth are equal.
This happens when we take the (non-constant) length from a malloc. llvm-svn: 122961
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp2
-rw-r--r--llvm/test/Transforms/InstCombine/objsize.ll11
2 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 603a01075a5..ecd2243c35d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -722,6 +722,8 @@ protected:
NewInstruction = IC->ReplaceInstUsesWith(*CI, With);
}
bool isFoldable(unsigned SizeCIOp, unsigned SizeArgOp, bool isString) const {
+ if (CI->getArgOperand(SizeCIOp) == CI->getArgOperand(SizeArgOp))
+ return true;
if (ConstantInt *SizeCI =
dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp))) {
if (SizeCI->isAllOnesValue())
diff --git a/llvm/test/Transforms/InstCombine/objsize.ll b/llvm/test/Transforms/InstCombine/objsize.ll
index 9950e5f4cc6..4154ea0afbb 100644
--- a/llvm/test/Transforms/InstCombine/objsize.ll
+++ b/llvm/test/Transforms/InstCombine/objsize.ll
@@ -176,3 +176,14 @@ define i32 @test9(i32 %x) {
; CHECK-NOT: ret i32 %x
ret i32 %objsize
}
+
+define i8* @test10(i32 %x) {
+; CHECK: @test10
+ %alloc = call noalias i8* @malloc(i32 %x) nounwind
+ %objsize = call i32 @llvm.objectsize.i32(i8* %alloc, i1 false) nounwind readonly
+ tail call i8* @__memset_chk(i8* %alloc, i32 0, i32 %x, i32 %objsize) nounwind
+; CHECK-NOT: @llvm.objectsize
+; CHECK: @llvm.memset
+ ret i8* %alloc
+; CHECK: ret i8*
+}
OpenPOWER on IntegriCloud