blob: 74355961fbf94732ab610f78c05496045c469e9a [file] [log] [blame]
Dan Gohman18800922009-09-11 18:01:28 +00001; RUN: opt < %s -mem2reg -instcombine -S | grep store
Chris Lattnerba613f42005-06-30 07:28:54 +00002; PR590
3
Tanya Lattnerab7872c2008-03-19 07:28:33 +00004
5define void @zero(i8* %p, i32 %n) {
Chris Lattnerba613f42005-06-30 07:28:54 +00006entry:
Tanya Lattnerab7872c2008-03-19 07:28:33 +00007 %p_addr = alloca i8* ; <i8**> [#uses=2]
8 %n_addr = alloca i32 ; <i32*> [#uses=2]
9 %i = alloca i32 ; <i32*> [#uses=6]
10 %out = alloca i32 ; <i32*> [#uses=2]
11 %undef = alloca i32 ; <i32*> [#uses=2]
12 store i8* %p, i8** %p_addr
13 store i32 %n, i32* %n_addr
14 store i32 0, i32* %i
Chris Lattnerba613f42005-06-30 07:28:54 +000015 br label %loopentry
Chris Lattnerba613f42005-06-30 07:28:54 +000016loopentry: ; preds = %endif, %entry
Tanya Lattnerab7872c2008-03-19 07:28:33 +000017 %tmp.0 = load i32* %n_addr ; <i32> [#uses=1]
18 %tmp.1 = add i32 %tmp.0, 1 ; <i32> [#uses=1]
19 %tmp.2 = load i32* %i ; <i32> [#uses=1]
20 %tmp.3 = icmp sgt i32 %tmp.1, %tmp.2 ; <i1> [#uses=2]
21 %tmp.4 = zext i1 %tmp.3 to i32 ; <i32> [#uses=0]
22 br i1 %tmp.3, label %no_exit, label %return
Chris Lattnerba613f42005-06-30 07:28:54 +000023no_exit: ; preds = %loopentry
Tanya Lattnerab7872c2008-03-19 07:28:33 +000024 %tmp.5 = load i32* %undef ; <i32> [#uses=1]
25 store i32 %tmp.5, i32* %out
26 store i32 0, i32* %undef
27 %tmp.6 = load i32* %i ; <i32> [#uses=1]
28 %tmp.7 = icmp sgt i32 %tmp.6, 0 ; <i1> [#uses=2]
29 %tmp.8 = zext i1 %tmp.7 to i32 ; <i32> [#uses=0]
30 br i1 %tmp.7, label %then, label %endif
Chris Lattnerba613f42005-06-30 07:28:54 +000031then: ; preds = %no_exit
Tanya Lattnerab7872c2008-03-19 07:28:33 +000032 %tmp.9 = load i8** %p_addr ; <i8*> [#uses=1]
33 %tmp.10 = load i32* %i ; <i32> [#uses=1]
34 %tmp.11 = sub i32 %tmp.10, 1 ; <i32> [#uses=1]
35 %tmp.12 = getelementptr i8* %tmp.9, i32 %tmp.11 ; <i8*> [#uses=1]
36 %tmp.13 = load i32* %out ; <i32> [#uses=1]
37 %tmp.14 = trunc i32 %tmp.13 to i8 ; <i8> [#uses=1]
38 store i8 %tmp.14, i8* %tmp.12
Chris Lattnerba613f42005-06-30 07:28:54 +000039 br label %endif
Chris Lattnerba613f42005-06-30 07:28:54 +000040endif: ; preds = %then, %no_exit
Tanya Lattnerab7872c2008-03-19 07:28:33 +000041 %tmp.15 = load i32* %i ; <i32> [#uses=1]
42 %inc = add i32 %tmp.15, 1 ; <i32> [#uses=1]
43 store i32 %inc, i32* %i
Chris Lattnerba613f42005-06-30 07:28:54 +000044 br label %loopentry
Chris Lattnerba613f42005-06-30 07:28:54 +000045return: ; preds = %loopentry
46 ret void
47}