1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -O1 < %s | FileCheck %s
3 ; RUN: opt -S -O2 < %s | FileCheck %s
4 ; RUN: opt -S -O3 < %s | FileCheck %s
6 define void @swap(ptr %p1, ptr %p2) {
8 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[P1:%.*]], align 1
9 ; CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[P2:%.*]], align 1
10 ; CHECK-NEXT: store i64 [[TMP2]], ptr [[P1]], align 1
11 ; CHECK-NEXT: store i64 [[TMP1]], ptr [[P2]], align 1
12 ; CHECK-NEXT: ret void
14 %tmp = alloca [2 x i32]
15 call void @llvm.memcpy.p0.p0.i64(ptr %tmp, ptr %p1, i64 8, i1 false)
16 call void @llvm.memcpy.p0.p0.i64(ptr %p1, ptr %p2, i64 8, i1 false)
17 call void @llvm.memcpy.p0.p0.i64(ptr %p2, ptr %tmp, i64 8, i1 false)
21 define i32 @test(i32 %n) {
23 ; CHECK-NEXT: br label [[LOOP:%.*]]
25 ; CHECK-NEXT: [[P1_SROA_5_0:%.*]] = phi i32 [ 1, [[TMP0:%.*]] ], [ [[V2_NEXT:%.*]], [[LOOP]] ]
26 ; CHECK-NEXT: [[P1_SROA_0_0:%.*]] = phi i32 [ 0, [[TMP0]] ], [ [[V1_INC:%.*]], [[LOOP]] ]
27 ; CHECK-NEXT: [[V1_INC]] = add i32 [[P1_SROA_0_0]], 1
28 ; CHECK-NEXT: [[V2_NEXT]] = shl i32 [[P1_SROA_5_0]], 1
29 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[V1_INC]], [[N:%.*]]
30 ; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[LOOP]]
32 ; CHECK-NEXT: ret i32 [[V2_NEXT]]
34 %p1 = alloca [2 x i32]
35 %p2 = alloca [2 x i32]
36 %p1.2 = getelementptr i32, ptr %p1, i64 1
37 %p2.2 = getelementptr i32, ptr %p2, i64 1
39 store i32 1, ptr %p1.2
43 %v1 = load i32, ptr %p1
44 %v1.inc = add i32 %v1, 1
45 store i32 %v1.inc, ptr %p1
46 %v2 = load i32, ptr %p1.2
47 %v2.next = shl i32 %v2, 1
48 store i32 %v2.next, ptr %p1.2
49 %c = icmp eq i32 %v1.inc, %n
50 br i1 %c, label %exit, label %loop
53 call void @swap(ptr %p1, ptr %p2)
54 %res = load i32, ptr %p2.2
58 declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)