[llvm-commits] [poolalloc] r163158 - /poolalloc/trunk/test/dsa/local/struct_malloc.ll

Will Dietz wdietz2 at illinois.edu
Tue Sep 4 12:24:41 PDT 2012


Author: wdietz2
Date: Tue Sep  4 14:24:41 2012
New Revision: 163158

URL: http://llvm.org/viewvc/llvm-project?rev=163158&view=rev
Log:
Add failing testcase demonstrating unnecessary folding.

The C source for this is something like:

struct mytype *s = malloc(sizeof(mytype));
s->field1 = 0;
s->field2 = 0;

(Nothing special)

The problem is that DSA folds the DSNode for 's', instead of reporting
that it's either:
* Array of i32's of unknown size
* Struct containing at least 2 i32's

This is the source of a large amount of unnecessary aliasing in 401.bzip2,
(collapses the primary struct used to store state) which among other things
makes all the indirect calls using that struct unresolvable.

More generally, this seems like a significant failure of the analysis
to work with perfectly reasonable C code...
(Although it's unfortunate the IR loses the struct type information)

FWIW, a complete C program that exhibits this behavior with mainline clang:

----------------------------------------
typedef struct {
  int a;
  int b;
} twoints;

void foo(twoints* T) {
  printf("%d\n", T->a);
}

int main(int argc, char ** argv) {
  twoints* T = NULL;
  T = malloc(sizeof(T));
  T->a = 0;
  T->b = 0;
  foo(T);
  return 0;
}

Added:
    poolalloc/trunk/test/dsa/local/struct_malloc.ll

Added: poolalloc/trunk/test/dsa/local/struct_malloc.ll
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/test/dsa/local/struct_malloc.ll?rev=163158&view=auto
==============================================================================
--- poolalloc/trunk/test/dsa/local/struct_malloc.ll (added)
+++ poolalloc/trunk/test/dsa/local/struct_malloc.ll Tue Sep  4 14:24:41 2012
@@ -0,0 +1,22 @@
+;RUN: dsaopt %s -dsa-local -analyze -check-type=func:struct,0:i32Array
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare noalias i8* @malloc(i64) nounwind
+
+define void @func() nounwind {
+entry:
+  ; Allocate 2 x i32 = 8 bytes
+  %struct = call noalias i8* @malloc(i64 8) nounwind
+
+  ; Index into first, store 0 there
+  %ptr = getelementptr inbounds i8* %struct, i64 0
+  %conv = bitcast i8* %ptr to i32*
+  store i32 0, i32* %conv, align 4
+
+  ; Index into second, store 0 there also
+  %ptr2 = getelementptr inbounds i8* %struct, i64 4
+  %conv2 = bitcast i8* %ptr2 to i32*
+  store i32 0, i32* %conv2, align 4
+  ret void
+}





More information about the llvm-commits mailing list