1 ; RUN: opt -passes='print<access-info>' -disable-output < %s 2>&1 | FileCheck %s
3 ; The runtime memory check code and the access grouping
4 ; algorithm both assume that the start and end values
5 ; for an access range are ordered (start <= stop).
6 ; When generating checks for accesses with negative stride
7 ; we need to take this into account and swap the interval
10 ; for (i = 0; i < 10000; i++) {
11 ; B[i] = A[15000 - i] * 3;
14 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
15 target triple = "aarch64"
17 ; CHECK: function 'f':
18 ; CHECK: (Low: (20000 + %a)<nuw> High: (60004 + %a))
20 @B = common global ptr null, align 8
21 @A = common global ptr null, align 8
25 %a = load ptr, ptr @A, align 8
26 %b = load ptr, ptr @B, align 8
29 for.body: ; preds = %for.body, %entry
30 %idx = phi i64 [ 0, %entry ], [ %add, %for.body ]
31 %negidx = sub i64 15000, %idx
33 %arrayidxA0 = getelementptr inbounds i32, ptr %a, i64 %negidx
34 %loadA0 = load i32, ptr %arrayidxA0, align 2
36 %res = mul i32 %loadA0, 3
38 %add = add nuw nsw i64 %idx, 1
40 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %idx
41 store i32 %res, ptr %arrayidxB, align 2
43 %exitcond = icmp eq i64 %idx, 10000
44 br i1 %exitcond, label %for.end, label %for.body
46 for.end: ; preds = %for.body
50 ; CHECK: function 'g':
51 ; When the stride is not constant, we are forced to do umin/umax to get
52 ; the interval limits.
54 ; for (i = 0; i < 10000; i++) {
58 ; Here it is not obvious what the limits are, since 'step' could be negative.
60 ; CHECK: Low: ((60000 + %a) umin (60000 + (-40000 * %step) + %a))
61 ; CHECK: High: (4 + ((60000 + %a) umax (60000 + (-40000 * %step) + %a)))
63 define void @g(i64 %step) {
65 %a = load ptr, ptr @A, align 8
66 %b = load ptr, ptr @B, align 8
69 for.body: ; preds = %for.body, %entry
70 %idx = phi i64 [ 0, %entry ], [ %add, %for.body ]
71 %idx_mul = mul i64 %idx, %step
72 %negidx = sub i64 15000, %idx_mul
74 %arrayidxA0 = getelementptr inbounds i32, ptr %a, i64 %negidx
75 %loadA0 = load i32, ptr %arrayidxA0, align 2
77 %res = mul i32 %loadA0, 3
79 %add = add nuw nsw i64 %idx, 1
81 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %idx
82 store i32 %res, ptr %arrayidxB, align 2
84 %exitcond = icmp eq i64 %idx, 10000
85 br i1 %exitcond, label %for.end, label %for.body
87 for.end: ; preds = %for.body