1 ; RUN: opt -instcombine -S < %s | FileCheck %s --dump-input-on-failure
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.14.0"
6 ; Function Attrs: nounwind ssp uwtable
7 define i64 @weird_identity_but_ok(i64 %sz) {
9 %call = tail call i8* @malloc(i64 %sz)
10 %calc_size = tail call i64 @llvm.objectsize.i64.p0i8(i8* %call, i1 false, i1 true, i1 true)
11 tail call void @free(i8* %call)
15 ; CHECK: define i64 @weird_identity_but_ok(i64 %sz)
17 ; CHECK-NEXT: ret i64 %sz
20 define i64 @phis_are_neat(i1 %which) {
22 br i1 %which, label %first_label, label %second_label
25 %first_call = call i8* @malloc(i64 10)
29 %second_call = call i8* @malloc(i64 30)
33 %joined = phi i8* [ %first_call, %first_label ], [ %second_call, %second_label ]
34 %calc_size = tail call i64 @llvm.objectsize.i64.p0i8(i8* %joined, i1 false, i1 true, i1 true)
38 ; CHECK: %0 = phi i64 [ 10, %first_label ], [ 30, %second_label ]
39 ; CHECK-NEXT: ret i64 %0
41 define i64 @internal_pointer(i64 %sz) {
43 %ptr = call i8* @malloc(i64 %sz)
44 %ptr2 = getelementptr inbounds i8, i8* %ptr, i32 2
45 %calc_size = call i64 @llvm.objectsize.i64.p0i8(i8* %ptr2, i1 false, i1 true, i1 true)
49 ; CHECK: define i64 @internal_pointer(i64 %sz)
51 ; CHECK-NEXT: %0 = add i64 %sz, -2
52 ; CHECK-NEXT: %1 = icmp ult i64 %sz, 2
53 ; CHECK-NEXT: %2 = select i1 %1, i64 0, i64 %0
54 ; CHECK-NEXT: ret i64 %2
57 define i64 @uses_nullptr_no_fold() {
59 %res = call i64 @llvm.objectsize.i64.p0i8(i8* null, i1 false, i1 true, i1 true)
63 ; CHECK: %res = call i64 @llvm.objectsize.i64.p0i8(i8* null, i1 false, i1 true, i1 true)
65 define i64 @uses_nullptr_fold() {
67 ; NOTE: the third parameter to this call is false, unlike above.
68 %res = call i64 @llvm.objectsize.i64.p0i8(i8* null, i1 false, i1 false, i1 true)
74 @d = common global i8 0, align 1
75 @c = common global i32 0, align 4
77 ; Function Attrs: nounwind
80 %.pr = load i32, i32* @c, align 4
81 %tobool4 = icmp eq i32 %.pr, 0
82 br i1 %tobool4, label %for.end, label %for.body
84 for.body: ; preds = %entry, %for.body
85 %dp.05 = phi i8* [ %add.ptr, %for.body ], [ @d, %entry ]
86 %0 = tail call i64 @llvm.objectsize.i64.p0i8(i8* %dp.05, i1 false, i1 true, i1 true)
87 %conv = trunc i64 %0 to i32
88 tail call void @bury(i32 %conv) #3
89 %1 = load i32, i32* @c, align 4
90 %idx.ext = sext i32 %1 to i64
91 %add.ptr.offs = add i64 %idx.ext, 0
92 %2 = add i64 undef, %add.ptr.offs
93 %add.ptr = getelementptr inbounds i8, i8* %dp.05, i64 %idx.ext
94 %add = shl nsw i32 %1, 1
95 store i32 %add, i32* @c, align 4
96 %tobool = icmp eq i32 %1, 0
97 br i1 %tobool, label %for.end, label %for.body
99 for.end: ; preds = %for.body, %entry
103 ; CHECK: define void @f()
104 ; CHECK: call i64 @llvm.objectsize.i64.p0i8(
106 declare void @bury(i32) local_unnamed_addr #2
108 ; Function Attrs: nounwind allocsize(0)
109 declare i8* @malloc(i64)
111 declare i8* @get_unknown_buffer()
113 ; Function Attrs: nounwind
114 declare void @free(i8* nocapture)
116 ; Function Attrs: nounwind readnone speculatable
117 declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1)