blob: 6b69ec860202f46711051da15187478c3d98d3e8 [file] [log] [blame]
Dan Gohman620c38f2010-11-12 02:02:39 +00001; RUN: opt < %s -basicaa -dse -S | FileCheck %s
Chris Lattnerfb7dd4c2004-07-25 07:57:50 +00002
Dan Gohman620c38f2010-11-12 02:02:39 +00003target datalayout = "e-p:64:64:64"
4
Nick Lewyckyf2905af2011-11-05 10:48:42 +00005declare void @free(i8* nocapture)
6declare noalias i8* @malloc(i64)
7
Stephen Linc1c7a132013-07-14 01:42:54 +00008; CHECK-LABEL: @test(
Dan Gohman620c38f2010-11-12 02:02:39 +00009; CHECK-NEXT: bitcast
10; CHECK-NEXT: @free
11; CHECK-NEXT: ret void
Tanya Lattner5640bd12008-03-01 09:15:35 +000012define void @test(i32* %Q, i32* %P) {
David Blaikiea79ac142015-02-27 21:17:42 +000013 %DEAD = load i32, i32* %Q ; <i32> [#uses=1]
Tanya Lattner5640bd12008-03-01 09:15:35 +000014 store i32 %DEAD, i32* %P
Chris Lattnerb90ed222011-06-17 03:14:27 +000015 %1 = bitcast i32* %P to i8*
16 tail call void @free(i8* %1)
Tanya Lattner5640bd12008-03-01 09:15:35 +000017 ret void
Chris Lattnerfb7dd4c2004-07-25 07:57:50 +000018}
Chris Lattner57e91ea2008-12-06 00:53:22 +000019
Stephen Linc1c7a132013-07-14 01:42:54 +000020; CHECK-LABEL: @test2(
Dan Gohman620c38f2010-11-12 02:02:39 +000021; CHECK-NEXT: bitcast
22; CHECK-NEXT: @free
23; CHECK-NEXT: ret void
Chris Lattner57e91ea2008-12-06 00:53:22 +000024define void @test2({i32, i32}* %P) {
David Blaikie79e6c742015-02-27 19:29:02 +000025 %Q = getelementptr {i32, i32}, {i32, i32} *%P, i32 0, i32 1
Chris Lattner57e91ea2008-12-06 00:53:22 +000026 store i32 4, i32* %Q
Chris Lattnerb90ed222011-06-17 03:14:27 +000027 %1 = bitcast {i32, i32}* %P to i8*
28 tail call void @free(i8* %1)
Chris Lattner57e91ea2008-12-06 00:53:22 +000029 ret void
30}
Dan Gohman620c38f2010-11-12 02:02:39 +000031
Stephen Linc1c7a132013-07-14 01:42:54 +000032; CHECK-LABEL: @test3(
Dan Gohmand4b7fff2010-11-12 02:19:17 +000033; CHECK-NOT: store
34; CHECK: ret void
Nick Lewyckyf2905af2011-11-05 10:48:42 +000035define void @test3() {
Dan Gohmand4b7fff2010-11-12 02:19:17 +000036 %m = call i8* @malloc(i64 24)
37 store i8 0, i8* %m
David Blaikie79e6c742015-02-27 19:29:02 +000038 %m1 = getelementptr i8, i8* %m, i64 1
Dan Gohmand4b7fff2010-11-12 02:19:17 +000039 store i8 1, i8* %m1
40 call void @free(i8* %m)
41 ret void
42}
43
Nick Lewyckyf2905af2011-11-05 10:48:42 +000044; PR11240
Stephen Linc1c7a132013-07-14 01:42:54 +000045; CHECK-LABEL: @test4(
Nick Lewyckyf2905af2011-11-05 10:48:42 +000046; CHECK-NOT: store
47; CHECK: ret void
48define void @test4(i1 %x) nounwind {
49entry:
50 %alloc1 = tail call noalias i8* @malloc(i64 4) nounwind
51 br i1 %x, label %skipinit1, label %init1
52
53init1:
54 store i8 1, i8* %alloc1
55 br label %skipinit1
56
57skipinit1:
58 tail call void @free(i8* %alloc1) nounwind
59 ret void
60}
Nick Lewyckyfe970722011-12-08 22:36:35 +000061
Stephen Linc1c7a132013-07-14 01:42:54 +000062; CHECK-LABEL: @test5(
Nick Lewyckyfe970722011-12-08 22:36:35 +000063define void @test5() {
64 br label %bb
65
66bb:
67 tail call void @free(i8* undef) nounwind
68 br label %bb
69}
70