1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
3 ; RUN: llc < %s -mtriple=aarch64-unknown-unknown | FileCheck %s
5 ; Test LSR for giving small constants, which get re-associated as unfolded
6 ; offset, a chance to get combined with loop-invariant registers (same as
7 ; large constants which do not fit as add immediate operands). LSR
8 ; favors here to bump the base pointer outside the loop.
10 ; float test(float *arr, long long start, float threshold) {
11 ; for (long long i = start; i != 0; ++i) {
12 ; float x = arr[i + 7];
18 define float @test1(float* nocapture readonly %arr, i64 %start, float %threshold) {
20 ; CHECK: // %bb.0: // %entry
21 ; CHECK-NEXT: fmov s2, #-7.00000000
22 ; CHECK-NEXT: cbz x1, .LBB0_4
23 ; CHECK-NEXT: // %bb.1: // %for.body.preheader
24 ; CHECK-NEXT: add x8, x0, #28 // =28
25 ; CHECK-NEXT: .LBB0_2: // %for.body
26 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
27 ; CHECK-NEXT: ldr s1, [x8, x1, lsl #2]
28 ; CHECK-NEXT: fcmp s1, s0
29 ; CHECK-NEXT: b.gt .LBB0_5
30 ; CHECK-NEXT: // %bb.3: // %for.cond
31 ; CHECK-NEXT: // in Loop: Header=BB0_2 Depth=1
32 ; CHECK-NEXT: add x1, x1, #1 // =1
33 ; CHECK-NEXT: cbnz x1, .LBB0_2
34 ; CHECK-NEXT: .LBB0_4:
35 ; CHECK-NEXT: mov v0.16b, v2.16b
37 ; CHECK-NEXT: .LBB0_5: // %cleanup2
38 ; CHECK-NEXT: mov v0.16b, v1.16b
41 %cmp11 = icmp eq i64 %start, 0
42 br i1 %cmp11, label %cleanup2, label %for.body
44 for.cond: ; preds = %for.body
45 %cmp = icmp eq i64 %inc, 0
46 br i1 %cmp, label %cleanup2, label %for.body
48 for.body: ; preds = %entry, %for.cond
49 %i.012 = phi i64 [ %inc, %for.cond ], [ %start, %entry ]
50 %add = add nsw i64 %i.012, 7
51 %arrayidx = getelementptr inbounds float, float* %arr, i64 %add
52 %0 = load float, float* %arrayidx, align 4
53 %cmp1 = fcmp ogt float %0, %threshold
54 %inc = add nsw i64 %i.012, 1
55 br i1 %cmp1, label %cleanup2, label %for.cond
57 cleanup2: ; preds = %for.cond, %for.body, %entry
58 %1 = phi float [ -7.000000e+00, %entry ], [ %0, %for.body ], [ -7.000000e+00, %for.cond ]
62 ; Same as test1, except i has another use:
63 ; if (x > threshold) ---> if (x > threshold + i)
64 define float @test2(float* nocapture readonly %arr, i64 %start, float %threshold) {
66 ; CHECK: // %bb.0: // %entry
67 ; CHECK-NEXT: fmov s2, #-7.00000000
68 ; CHECK-NEXT: cbz x1, .LBB1_4
69 ; CHECK-NEXT: // %bb.1: // %for.body.preheader
70 ; CHECK-NEXT: add x8, x0, #28 // =28
71 ; CHECK-NEXT: .LBB1_2: // %for.body
72 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
73 ; CHECK-NEXT: ldr s1, [x8, x1, lsl #2]
74 ; CHECK-NEXT: scvtf s3, x1
75 ; CHECK-NEXT: fadd s3, s3, s0
76 ; CHECK-NEXT: fcmp s1, s3
77 ; CHECK-NEXT: b.gt .LBB1_5
78 ; CHECK-NEXT: // %bb.3: // %for.cond
79 ; CHECK-NEXT: // in Loop: Header=BB1_2 Depth=1
80 ; CHECK-NEXT: add x1, x1, #1 // =1
81 ; CHECK-NEXT: cbnz x1, .LBB1_2
82 ; CHECK-NEXT: .LBB1_4:
83 ; CHECK-NEXT: mov v0.16b, v2.16b
85 ; CHECK-NEXT: .LBB1_5: // %cleanup4
86 ; CHECK-NEXT: mov v0.16b, v1.16b
89 %cmp14 = icmp eq i64 %start, 0
90 br i1 %cmp14, label %cleanup4, label %for.body
92 for.cond: ; preds = %for.body
93 %cmp = icmp eq i64 %inc, 0
94 br i1 %cmp, label %cleanup4, label %for.body
96 for.body: ; preds = %entry, %for.cond
97 %i.015 = phi i64 [ %inc, %for.cond ], [ %start, %entry ]
98 %add = add nsw i64 %i.015, 7
99 %arrayidx = getelementptr inbounds float, float* %arr, i64 %add
100 %0 = load float, float* %arrayidx, align 4
101 %conv = sitofp i64 %i.015 to float
102 %add1 = fadd float %conv, %threshold
103 %cmp2 = fcmp ogt float %0, %add1
104 %inc = add nsw i64 %i.015, 1
105 br i1 %cmp2, label %cleanup4, label %for.cond
107 cleanup4: ; preds = %for.cond, %for.body, %entry
108 %1 = phi float [ -7.000000e+00, %entry ], [ %0, %for.body ], [ -7.000000e+00, %for.cond ]