[llvm-commits] [llvm] r122961 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCalls.cpp test/Transforms/InstCombine/objsize.ll
Benjamin Kramer
benny.kra at googlemail.com
Thu Jan 6 06:22:52 PST 2011
Author: d0k
Date: Thu Jan 6 08:22:52 2011
New Revision: 122961
URL: http://llvm.org/viewvc/llvm-project?rev=122961&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/objsize.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=122961&r1=122960&r2=122961&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu Jan 6 08:22:52 2011
@@ -722,6 +722,8 @@
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())
Modified: llvm/trunk/test/Transforms/InstCombine/objsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/objsize.ll?rev=122961&r1=122960&r2=122961&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/objsize.ll Thu Jan 6 08:22:52 2011
@@ -176,3 +176,14 @@
; 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*
+}
More information about the llvm-commits
mailing list