[llvm-commits] [llvm] r123030 - in /llvm/trunk: lib/Target/README.txt lib/Transforms/InstCombine/InstCombineCalls.cpp test/Transforms/InstCombine/objsize.ll

Benjamin Kramer benny.kra at googlemail.com
Fri Jan 7 12:42:20 PST 2011


Author: d0k
Date: Fri Jan  7 14:42:20 2011
New Revision: 123030

URL: http://llvm.org/viewvc/llvm-project?rev=123030&view=rev
Log:
Revert 122959, it needs more thought. Add it back to README.txt with additional notes.

Modified:
    llvm/trunk/lib/Target/README.txt
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/objsize.ll

Modified: llvm/trunk/lib/Target/README.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/README.txt?rev=123030&r1=123029&r2=123030&view=diff
==============================================================================
--- llvm/trunk/lib/Target/README.txt (original)
+++ llvm/trunk/lib/Target/README.txt Fri Jan  7 14:42:20 2011
@@ -2009,6 +2009,28 @@
 
 //===---------------------------------------------------------------------===//
 
+This code can be seen in viterbi:
+
+  %64 = call noalias i8* @malloc(i64 %62) nounwind
+...
+  %67 = call i64 @llvm.objectsize.i64(i8* %64, i1 false) nounwind
+  %68 = call i8* @__memset_chk(i8* %64, i32 0, i64 %62, i64 %67) nounwind
+
+llvm.objectsize.i64 should be taught about malloc/calloc, allowing it to
+fold to %62.  This is a security win (overflows of malloc will get caught)
+and also a performance win by exposing more memsets to the optimizer.
+
+This occurs several times in viterbi.
+
+Note that this would change the semantics of @llvm.objectsize which by its
+current definition always folds to a constant. We also should make sure that
+we remove checking in code like
+
+  char *p = malloc(strlen(s)+1);
+  __strcpy_chk(p, s, __builtin_objectsize(p, 0));
+
+//===---------------------------------------------------------------------===//
+
 This code (from Benchmarks/Dhrystone/dry.c):
 
 define i32 @Func1(i32, i32) nounwind readnone optsize ssp {

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=123030&r1=123029&r2=123030&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Fri Jan  7 14:42:20 2011
@@ -304,10 +304,6 @@
         if (Value *NElems = getMallocArraySize(MI, TD, true))
           if (ConstantInt *NElements = dyn_cast<ConstantInt>(NElems))
             Size = NElements->getZExtValue() * TD->getTypeAllocSize(MallocType);
-
-      // If there is no offset we can just return the size passed to malloc.
-      if (Offset == 0)
-        return ReplaceInstUsesWith(CI, MI->getArgOperand(0));
     }
 
     // Do not return "I don't know" here. Later optimization passes could

Modified: llvm/trunk/test/Transforms/InstCombine/objsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/objsize.ll?rev=123030&r1=123029&r2=123030&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/objsize.ll Fri Jan  7 14:42:20 2011
@@ -160,30 +160,3 @@
   ret i32 %objsize
 }
 
-define i32 @test8(i32 %x) {
-; CHECK: @test8
-  %alloc = call noalias i8* @malloc(i32 %x) nounwind
-  %objsize = call i32 @llvm.objectsize.i32(i8* %alloc, i1 false) nounwind readonly
-; CHECK-NEXT: ret i32 %x
-  ret i32 %objsize
-}
-
-define i32 @test9(i32 %x) {
-; CHECK: @test9
-  %alloc = call noalias i8* @malloc(i32 %x) nounwind
-  %gep = getelementptr inbounds i8* %alloc, i32 16
-  %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false) nounwind readonly
-; 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