blob: 2373ef5888b91e7600c3cc45a926d2812f8746e2 [file] [log] [blame]
Dan Gohman0a6021a2010-11-10 20:37:15 +00001; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
2
3target datalayout = "e-p:64:64:64"
4
5; GVN should ignore the store to p[1] to see that the load from p[0] is
6; fully redundant.
7
Stephen Linc1c7a132013-07-14 01:42:54 +00008; CHECK-LABEL: @yes(
Dan Gohman0a6021a2010-11-10 20:37:15 +00009; CHECK: if.then:
10; CHECK-NEXT: store i32 0, i32* %q
11; CHECK-NEXT: ret void
12
13define void @yes(i1 %c, i32* %p, i32* %q) nounwind {
14entry:
15 store i32 0, i32* %p
David Blaikie79e6c742015-02-27 19:29:02 +000016 %p1 = getelementptr inbounds i32, i32* %p, i64 1
Dan Gohman0a6021a2010-11-10 20:37:15 +000017 store i32 1, i32* %p1
18 br i1 %c, label %if.else, label %if.then
19
20if.then:
David Blaikiea79ac142015-02-27 21:17:42 +000021 %t = load i32, i32* %p
Dan Gohman0a6021a2010-11-10 20:37:15 +000022 store i32 %t, i32* %q
23 ret void
24
25if.else:
26 ret void
27}
28
29; GVN should ignore the store to p[1] to see that the first load from p[0] is
30; fully redundant. However, the second load is larger, so it's not a simple
31; redundancy.
32
Stephen Linc1c7a132013-07-14 01:42:54 +000033; CHECK-LABEL: @watch_out_for_size_change(
Dan Gohman0a6021a2010-11-10 20:37:15 +000034; CHECK: if.then:
35; CHECK-NEXT: store i32 0, i32* %q
36; CHECK-NEXT: ret void
37; CHECK: if.else:
David Blaikiea79ac142015-02-27 21:17:42 +000038; CHECK: load i64, i64* %pc
Dan Gohman0a6021a2010-11-10 20:37:15 +000039; CHECK: store i64
40
41define void @watch_out_for_size_change(i1 %c, i32* %p, i32* %q) nounwind {
42entry:
43 store i32 0, i32* %p
David Blaikie79e6c742015-02-27 19:29:02 +000044 %p1 = getelementptr inbounds i32, i32* %p, i64 1
Dan Gohman0a6021a2010-11-10 20:37:15 +000045 store i32 1, i32* %p1
46 br i1 %c, label %if.else, label %if.then
47
48if.then:
David Blaikiea79ac142015-02-27 21:17:42 +000049 %t = load i32, i32* %p
Dan Gohman0a6021a2010-11-10 20:37:15 +000050 store i32 %t, i32* %q
51 ret void
52
53if.else:
54 %pc = bitcast i32* %p to i64*
55 %qc = bitcast i32* %q to i64*
David Blaikiea79ac142015-02-27 21:17:42 +000056 %t64 = load i64, i64* %pc
Dan Gohman0a6021a2010-11-10 20:37:15 +000057 store i64 %t64, i64* %qc
58 ret void
59}