blob: 168bd95e5392e837636219e63f89776046b86ac8 [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
Dan Gohman620c38f2010-11-12 02:02:39 +00008; CHECK: @test
9; 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) {
13 %DEAD = load i32* %Q ; <i32> [#uses=1]
14 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
Dan Gohman620c38f2010-11-12 02:02:39 +000020; CHECK: @test2
21; 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) {
25 %Q = getelementptr {i32, i32} *%P, i32 0, i32 1
26 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
Nick Lewyckyf2905af2011-11-05 10:48:42 +000032; CHECK: @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
38 %m1 = getelementptr i8* %m, i64 1
39 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
45; CHECK: @test4
46; 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}