; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt -passes=loop-load-elim -S %s | FileCheck %s
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
define void @non_const_distance(i64 %start, ptr %A, i1 %c) {
; CHECK-LABEL: define void @non_const_distance(
; CHECK-SAME: i64 [[START:%.*]], ptr [[A:%.*]], i1 [[C:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C]], i64 1, i64 0
; CHECK-NEXT: [[SEL_NOT:%.*]] = xor i64 [[SEL]], -1
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[START]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[A]], [[ENTRY]] ], [ [[PTR_IV_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr i32, ptr [[PTR_IV]], i64 [[SEL_NOT]]
; CHECK-NEXT: [[L:%.*]] = load i32, ptr [[ADD_PTR]], align 4
; CHECK-NEXT: store i32 [[L]], ptr [[PTR_IV]], align 4
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr i8, ptr [[PTR_IV]], i64 4
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV]], 1000
; CHECK-NEXT: br i1 [[EC]], label [[EXIT:%.*]], label [[LOOP]]
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
%sel = select i1 %c, i64 1, i64 0
%sel.not = xor i64 %sel, -1
br label %loop
loop:
%iv = phi i64 [ %start, %entry ], [ %iv.next, %loop ]
%ptr.iv = phi ptr [ %A, %entry ], [ %ptr.iv.next, %loop ]
%add.ptr = getelementptr i32, ptr %ptr.iv, i64 %sel.not
%l = load i32, ptr %add.ptr, align 4
store i32 %l, ptr %ptr.iv, align 4
%iv.next = add i64 %iv, 1
%ptr.iv.next = getelementptr i8, ptr %ptr.iv, i64 4
%ec = icmp eq i64 %iv, 1000
br i1 %ec, label %exit, label %loop
exit:
ret void
}