1 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
3 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
4 target triple = "nvptx64-unknown-unknown"
6 ; LSR used not to be able to generate a float* induction variable in
7 ; these cases due to scalar evolution not propagating nsw from an
8 ; instruction to the SCEV, preventing distributing sext into the
9 ; corresponding addrec.
13 ; for (int i = 0; i < numIterations; ++i)
14 ; sum += ptr[i + offset];
16 define float @testadd(float* %input, i32 %offset, i32 %numIterations) {
17 ; CHECK-LABEL: @testadd
18 ; CHECK: sext i32 %offset to i64
20 ; CHECK-DAG: phi float*
28 %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]
29 %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]
30 %index32 = add nuw nsw i32 %i, %offset
31 %index64 = sext i32 %index32 to i64
32 %ptr = getelementptr inbounds float, float* %input, i64 %index64
33 %addend = load float, float* %ptr, align 4
34 %nextsum = fadd float %sum, %addend
35 %nexti = add nuw nsw i32 %i, 1
36 %exitcond = icmp eq i32 %nexti, %numIterations
37 br i1 %exitcond, label %exit, label %loop
45 ; for (int i = 0; i < numIterations; ++i)
46 ; sum += ptr[i - offset];
48 define float @testsub(float* %input, i32 %offset, i32 %numIterations) {
49 ; CHECK-LABEL: @testsub
50 ; CHECK: sub i32 0, %offset
53 ; CHECK-DAG: phi float*
61 %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]
62 %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]
63 %index32 = sub nuw nsw i32 %i, %offset
64 %index64 = sext i32 %index32 to i64
65 %ptr = getelementptr inbounds float, float* %input, i64 %index64
66 %addend = load float, float* %ptr, align 4
67 %nextsum = fadd float %sum, %addend
68 %nexti = add nuw nsw i32 %i, 1
69 %exitcond = icmp eq i32 %nexti, %numIterations
70 br i1 %exitcond, label %exit, label %loop
78 ; for (int i = 0; i < numIterations; ++i)
79 ; sum += ptr[i * stride];
81 define float @testmul(float* %input, i32 %stride, i32 %numIterations) {
82 ; CHECK-LABEL: @testmul
83 ; CHECK: sext i32 %stride to i64
85 ; CHECK-DAG: phi float*
93 %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]
94 %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]
95 %index32 = mul nuw nsw i32 %i, %stride
96 %index64 = sext i32 %index32 to i64
97 %ptr = getelementptr inbounds float, float* %input, i64 %index64
98 %addend = load float, float* %ptr, align 4
99 %nextsum = fadd float %sum, %addend
100 %nexti = add nuw nsw i32 %i, 1
101 %exitcond = icmp eq i32 %nexti, %numIterations
102 br i1 %exitcond, label %exit, label %loop
110 ; for (int i = 0; i < numIterations; ++i)
111 ; sum += ptr[3 * (i << 7)];
113 ; The multiplication by 3 is to make the address calculation expensive
114 ; enough to force the introduction of a pointer induction variable.
115 define float @testshl(float* %input, i32 %numIterations) {
116 ; CHECK-LABEL: @testshl
118 ; CHECK-DAG: phi float*
126 %i = phi i32 [ %nexti, %loop ], [ 0, %entry ]
127 %sum = phi float [ %nextsum, %loop ], [ 0.000000e+00, %entry ]
128 %index32 = shl nuw nsw i32 %i, 7
129 %index32mul = mul nuw nsw i32 %index32, 3
130 %index64 = sext i32 %index32mul to i64
131 %ptr = getelementptr inbounds float, float* %input, i64 %index64
132 %addend = load float, float* %ptr, align 4
133 %nextsum = fadd float %sum, %addend
134 %nexti = add nuw nsw i32 %i, 1
135 %exitcond = icmp eq i32 %nexti, %numIterations
136 br i1 %exitcond, label %exit, label %loop