1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -aa-pipeline=basic-aa,globals-aa -passes="require<globals-aa>,function(gvn,instcombine)" -S -enable-unsafe-globalsmodref-alias-results | FileCheck %s
4 ; Note that this test relies on an unsafe feature of GlobalsModRef. While this
5 ; test is correct and safe, GMR's technique for handling this isn't generally.
7 target datalayout = "p:32:32:32"
9 @G = internal global ptr null ; <ptr> [#uses=3]
11 declare noalias ptr @malloc(i32) allockind("alloc,uninitialized") allocsize(0) inaccessiblememonly
12 define void @malloc_init() {
13 ; CHECK-LABEL: @malloc_init(
14 ; CHECK-NEXT: [[A:%.*]] = call dereferenceable_or_null(4) ptr @malloc(i32 4)
15 ; CHECK-NEXT: store ptr [[A]], ptr @G, align 4
16 ; CHECK-NEXT: ret void
18 %a = call ptr @malloc(i32 4)
23 define i32 @malloc_test(ptr %P) {
24 ; CHECK-LABEL: @malloc_test(
25 ; CHECK-NEXT: store i32 123, ptr [[P:%.*]], align 4
26 ; CHECK-NEXT: ret i32 0
28 %g1 = load ptr, ptr @G ; <ptr> [#uses=2]
29 %h1 = load i32, ptr %g1 ; <i32> [#uses=1]
31 %g2 = load ptr, ptr @G ; <ptr> [#uses=0]
32 %h2 = load i32, ptr %g1 ; <i32> [#uses=1]
33 %X = sub i32 %h1, %h2 ; <i32> [#uses=1]
37 @G2 = internal global ptr null ; <ptr> [#uses=3]
39 declare noalias ptr @calloc(i32, i32) allockind("alloc,zeroed") allocsize(0,1) inaccessiblememonly
40 define void @calloc_init() {
41 ; CHECK-LABEL: @calloc_init(
42 ; CHECK-NEXT: [[A:%.*]] = call dereferenceable_or_null(4) ptr @calloc(i32 4, i32 1)
43 ; CHECK-NEXT: store ptr [[A]], ptr @G2, align 4
44 ; CHECK-NEXT: ret void
46 %a = call ptr @calloc(i32 4, i32 1)
51 define i32 @calloc_test(ptr %P) {
52 ; CHECK-LABEL: @calloc_test(
53 ; CHECK-NEXT: store i32 123, ptr [[P:%.*]], align 4
54 ; CHECK-NEXT: ret i32 0
56 %g1 = load ptr, ptr @G2 ; <ptr> [#uses=2]
57 %h1 = load i32, ptr %g1 ; <i32> [#uses=1]
59 %g2 = load ptr, ptr @G2 ; <ptr> [#uses=0]
60 %h2 = load i32, ptr %g1 ; <i32> [#uses=1]
61 %X = sub i32 %h1, %h2 ; <i32> [#uses=1]
65 @G3 = internal global ptr null ; <ptr> [#uses=3]
67 declare noalias ptr @my_alloc(i32)
68 define void @my_alloc_init() {
69 ; CHECK-LABEL: @my_alloc_init(
70 ; CHECK-NEXT: [[A:%.*]] = call ptr @my_alloc(i32 4)
71 ; CHECK-NEXT: store ptr [[A]], ptr @G3, align 4
72 ; CHECK-NEXT: ret void
74 %a = call ptr @my_alloc(i32 4)
79 define i32 @my_alloc_test(ptr %P) {
80 ; CHECK-LABEL: @my_alloc_test(
81 ; CHECK-NEXT: store i32 123, ptr [[P:%.*]], align 4
82 ; CHECK-NEXT: ret i32 0
84 %g1 = load ptr, ptr @G3 ; <ptr> [#uses=2]
85 %h1 = load i32, ptr %g1 ; <i32> [#uses=1]
87 %g2 = load ptr, ptr @G3 ; <ptr> [#uses=0]
88 %h2 = load i32, ptr %g1 ; <i32> [#uses=1]
89 %X = sub i32 %h1, %h2 ; <i32> [#uses=1]