1; RUN: opt -aa-pipeline=basic-aa -passes='print<memoryssa>' -verify-memoryssa < %s 2>&1 | FileCheck %s
2;
3; Things that BasicAA can prove points to constant memory should be
4; liveOnEntry, as well.
5
6declare void @clobberAllTheThings()
7
8@str = private unnamed_addr constant [2 x i8] c"hi"
9
10define i8 @foo() {
11; CHECK: 1 = MemoryDef(liveOnEntry)
12; CHECK-NEXT: call void @clobberAllTheThings()
13  call void @clobberAllTheThings()
14  %1 = getelementptr [2 x i8], [2 x i8]* @str, i64 0, i64 0
15; CHECK: MemoryUse(liveOnEntry)
16; CHECK-NEXT: %2 = load i8
17  %2 = load i8, i8* %1, align 1
18  %3 = getelementptr [2 x i8], [2 x i8]* @str, i64 0, i64 1
19; CHECK: MemoryUse(liveOnEntry)
20; CHECK-NEXT: %4 = load i8
21  %4 = load i8, i8* %3, align 1
22  %5 = add i8 %2, %4
23  ret i8 %5
24}
25
26define i8 @select(i1 %b) {
27  %1 = alloca i8, align 1
28; CHECK: 1 = MemoryDef(liveOnEntry)
29; CHECK-NEXT: store i8 0
30  store i8 0, i8* %1, align 1
31
32; CHECK: 2 = MemoryDef(1)
33; CHECK-NEXT: call void @clobberAllTheThings()
34  call void @clobberAllTheThings()
35  %2 = getelementptr [2 x i8], [2 x i8]* @str, i64 0, i64 0
36  %3 = select i1 %b, i8* %2, i8* %1
37; CHECK: MemoryUse(2)
38; CHECK-NEXT: %4 = load i8
39  %4 = load i8, i8* %3, align 1
40  ret i8 %4
41}
42