blob: e57dd40f0047596508f4c7d878121d9fc7991772 [file] [log] [blame]
John Brawncd73fe82018-07-30 11:52:08 +00001; RUN: opt < %s -phi-values -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
2; RUN: opt < %s -aa-pipeline=basic-aa -passes='require<phi-values>,aa-eval' -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +00003target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4target triple = "x86_64-unknown-linux-gnu"
5
Evan Chengc10e88d2009-10-13 22:02:20 +00006; rdar://7282591
7
Evan Chengc745bf22009-10-14 01:45:10 +00008@X = common global i32 0
9@Y = common global i32 0
10@Z = common global i32 0
Evan Chengc10e88d2009-10-13 22:02:20 +000011
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000012; CHECK-LABEL: foo
Bill Wendlingcd6df162012-04-24 09:15:38 +000013; CHECK: NoAlias: i32* %P, i32* @Z
14
Dan Gohman22e0e1c2010-11-11 21:08:46 +000015define void @foo(i32 %cond) nounwind {
Evan Chengc10e88d2009-10-13 22:02:20 +000016entry:
Evan Chengc745bf22009-10-14 01:45:10 +000017 %"alloca point" = bitcast i32 0 to i32
18 %tmp = icmp ne i32 %cond, 0
19 br i1 %tmp, label %bb, label %bb1
Evan Chengc10e88d2009-10-13 22:02:20 +000020
Evan Chengc745bf22009-10-14 01:45:10 +000021bb:
22 br label %bb2
Evan Chengc10e88d2009-10-13 22:02:20 +000023
Evan Chengc745bf22009-10-14 01:45:10 +000024bb1:
25 br label %bb2
Evan Chengc10e88d2009-10-13 22:02:20 +000026
Evan Chengc745bf22009-10-14 01:45:10 +000027bb2:
28 %P = phi i32* [ @X, %bb ], [ @Y, %bb1 ]
David Blaikiea79ac142015-02-27 21:17:42 +000029 %tmp1 = load i32, i32* @Z, align 4
Evan Chengc745bf22009-10-14 01:45:10 +000030 store i32 123, i32* %P, align 4
David Blaikiea79ac142015-02-27 21:17:42 +000031 %tmp2 = load i32, i32* @Z, align 4
Evan Chengc745bf22009-10-14 01:45:10 +000032 br label %return
Evan Chengc10e88d2009-10-13 22:02:20 +000033
Evan Chengc745bf22009-10-14 01:45:10 +000034return:
Evan Chengc10e88d2009-10-13 22:02:20 +000035 ret void
36}
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000037
38; Pointers can vary in between iterations of loops.
39; PR18068
40
41; CHECK-LABEL: pr18068
42; CHECK: MayAlias: i32* %0, i32* %arrayidx5
Quentin Colombet5989bc62015-08-31 22:32:47 +000043; CHECK: NoAlias: i32* %arrayidx13, i32* %arrayidx5
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000044
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000045define i32 @pr18068(i32* %jj7, i32* %j) {
46entry:
47 %oa5 = alloca [100 x i32], align 16
48 br label %codeRepl
49
50codeRepl:
51 %0 = phi i32* [ %arrayidx13, %for.body ], [ %j, %entry ]
52 %targetBlock = call i1 @cond(i32* %jj7)
53 br i1 %targetBlock, label %for.body, label %bye
54
55for.body:
David Blaikiea79ac142015-02-27 21:17:42 +000056 %1 = load i32, i32* %jj7, align 4
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000057 %idxprom4 = zext i32 %1 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000058 %arrayidx5 = getelementptr inbounds [100 x i32], [100 x i32]* %oa5, i64 0, i64 %idxprom4
David Blaikiea79ac142015-02-27 21:17:42 +000059 %2 = load i32, i32* %arrayidx5, align 4
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000060 %sub6 = sub i32 %2, 6
61 store i32 %sub6, i32* %arrayidx5, align 4
62 ; %0 and %arrayidx5 can alias! It is not safe to DSE the above store.
David Blaikiea79ac142015-02-27 21:17:42 +000063 %3 = load i32, i32* %0, align 4
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000064 store i32 %3, i32* %arrayidx5, align 4
65 %sub11 = add i32 %1, -1
66 %idxprom12 = zext i32 %sub11 to i64
David Blaikie79e6c742015-02-27 19:29:02 +000067 %arrayidx13 = getelementptr inbounds [100 x i32], [100 x i32]* %oa5, i64 0, i64 %idxprom12
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000068 call void @inc(i32* %jj7)
69 br label %codeRepl
70
71bye:
David Blaikiea79ac142015-02-27 21:17:42 +000072 %.reload = load i32, i32* %jj7, align 4
Arnold Schwaighofer0d10a9d2014-01-02 03:31:36 +000073 ret i32 %.reload
74}
75
76declare i1 @cond(i32*)
77
78declare void @inc(i32*)
79
80
John Brawncd73fe82018-07-30 11:52:08 +000081; When we have a chain of phis in nested loops we should recognise if there's
82; actually only one underlying value.
83; CHECK-LABEL: loop_phi_chain
84; CHECK: NoAlias: i32* %val1, i32* @Y
85; CHECK: NoAlias: i32* %val2, i32* @Y
86; CHECK: NoAlias: i32* %val3, i32* @Y
87define void @loop_phi_chain(i32 %a, i32 %b, i32 %c) {
88entry:
89 br label %loop1
90
91loop1:
92 %n1 = phi i32 [ 0, %entry ], [ %add1, %loop2 ]
93 %val1 = phi i32* [ @X, %entry ], [ %val2, %loop2 ]
94 %add1 = add i32 %n1, 1
95 %cmp1 = icmp ne i32 %n1, 32
96 br i1 %cmp1, label %loop2, label %end
97
98loop2:
99 %n2 = phi i32 [ 0, %loop1 ], [ %add2, %loop3 ]
100 %val2 = phi i32* [ %val1, %loop1 ], [ %val3, %loop3 ]
101 %add2 = add i32 %n2, 1
102 %cmp2 = icmp ne i32 %n2, 32
103 br i1 %cmp2, label %loop3, label %loop1
104
105loop3:
106 %n3 = phi i32 [ 0, %loop2 ], [ %add3, %loop3 ]
107 %val3 = phi i32* [ %val2, %loop2 ], [ %val3, %loop3 ]
108 store i32 0, i32* %val3, align 4
109 store i32 0, i32* @Y, align 4
110 %add3 = add i32 %n3, 1
111 %cmp3 = icmp ne i32 %n3, 32
112 br i1 %cmp3, label %loop3, label %loop2
113
114end:
115 ret void
116}