xref: /llvm-project/llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll (revision 1228becf7df28c68579f2b9b390b74aa41149a0a)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2
3; RUN: opt -O3 -S < %s | FileCheck %s
4
5define internal i32 @loop(ptr %arg, ptr %arg1) {
6bb:
7  br label %bb2
8
9bb2:
10  %phi = phi ptr [ %arg, %bb ], [ %phi8, %bb11 ]
11  %phi3 = phi i32 [ 0, %bb ], [ %add, %bb11 ]
12  %icmp = icmp ne ptr %arg1, null
13  %icmp4 = icmp eq ptr %phi, %arg1
14  br i1 %icmp4, label %bb7, label %bb5
15
16bb5:
17  %getelementptr = getelementptr inbounds i32, ptr %phi, i64 1
18  br label %bb7
19
20bb7:
21  %phi8 = phi ptr [ %phi, %bb2 ], [ %getelementptr, %bb5 ]
22  %phi9 = phi ptr [ null, %bb2 ], [ %phi, %bb5 ]
23  %icmp10 = icmp eq ptr %phi9, null
24  br i1 %icmp10, label %bb12, label %bb11
25
26bb11:
27  %load = load i32, ptr %phi9, align 4
28  %add = add i32 %load, %phi3
29  br label %bb2
30
31bb12:
32  ret i32 %phi3
33}
34
35define i32 @using_alloca() {
36; CHECK-LABEL: define noundef i32 @using_alloca
37; CHECK-SAME: () local_unnamed_addr #[[ATTR0:[0-9]+]] {
38; CHECK-NEXT:  bb:
39; CHECK-NEXT:    ret i32 6
40;
41bb:
42  %alloca = alloca [3 x i32], align 4
43  store i32 1, ptr %alloca, align 4
44  %getelementptr = getelementptr i32, ptr %alloca, i32 1
45  store i32 2, ptr %getelementptr, align 4
46  %getelementptr1 = getelementptr i32, ptr %alloca, i32 2
47  store i32 3, ptr %getelementptr1, align 4
48  %getelementptr2 = getelementptr i32, ptr %alloca, i32 3
49  %call = call i32 @loop(ptr %alloca, ptr %getelementptr2)
50  ret i32 %call
51}
52
53define i32 @using_malloc() {
54; CHECK-LABEL: define noundef i32 @using_malloc
55; CHECK-SAME: () local_unnamed_addr #[[ATTR0]] {
56; CHECK-NEXT:  bb:
57; CHECK-NEXT:    ret i32 6
58;
59bb:
60  %alloc = call dereferenceable_or_null(64) ptr @malloc(i64 64)
61  store i32 1, ptr %alloc, align 4
62  %getelementptr = getelementptr i32, ptr %alloc, i64 1
63  store i32 2, ptr %getelementptr, align 4
64  %getelementptr1 = getelementptr i32, ptr %alloc, i64 2
65  store i32 3, ptr %getelementptr1, align 4
66  %getelementptr2 = getelementptr i32, ptr %alloc, i64 3
67  %call = call i32 @loop(ptr %alloc, ptr %getelementptr2)
68  ret i32 %call
69}
70
71declare ptr @malloc(i64)
72
73declare void @free(ptr)
74