1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=loop-load-elim -S %s | FileCheck %s
4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
6 define void @non_const_distance(i64 %start, ptr %A, i1 %c) {
7 ; CHECK-LABEL: define void @non_const_distance(
8 ; CHECK-SAME: i64 [[START:%.*]], ptr [[A:%.*]], i1 [[C:%.*]]) {
10 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C]], i64 1, i64 0
11 ; CHECK-NEXT: [[SEL_NOT:%.*]] = xor i64 [[SEL]], -1
12 ; CHECK-NEXT: br label [[LOOP:%.*]]
14 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[START]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
15 ; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[A]], [[ENTRY]] ], [ [[PTR_IV_NEXT:%.*]], [[LOOP]] ]
16 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr i32, ptr [[PTR_IV]], i64 [[SEL_NOT]]
17 ; CHECK-NEXT: [[L:%.*]] = load i32, ptr [[ADD_PTR]], align 4
18 ; CHECK-NEXT: store i32 [[L]], ptr [[PTR_IV]], align 4
19 ; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
20 ; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr i8, ptr [[PTR_IV]], i64 4
21 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV]], 1000
22 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT:%.*]], label [[LOOP]]
24 ; CHECK-NEXT: ret void
27 %sel = select i1 %c, i64 1, i64 0
28 %sel.not = xor i64 %sel, -1
32 %iv = phi i64 [ %start, %entry ], [ %iv.next, %loop ]
33 %ptr.iv = phi ptr [ %A, %entry ], [ %ptr.iv.next, %loop ]
34 %add.ptr = getelementptr i32, ptr %ptr.iv, i64 %sel.not
35 %l = load i32, ptr %add.ptr, align 4
36 store i32 %l, ptr %ptr.iv, align 4
37 %iv.next = add i64 %iv, 1
38 %ptr.iv.next = getelementptr i8, ptr %ptr.iv, i64 4
39 %ec = icmp eq i64 %iv, 1000
40 br i1 %ec, label %exit, label %loop