1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3; RUN:   | FileCheck %s -check-prefix=RV32I
4
5@a = global [4096 x i32] zeroinitializer, align 4
6@b = global [4096 x i32] zeroinitializer, align 4
7
8; This test demonstrates very slightly improved codegen in the case that
9; a correct isLegalAddImmediate is implemented, thanks to LoopStrengthReduce.
10
11define i32 @main() nounwind {
12; RV32I-LABEL: main:
13; RV32I:       # %bb.0: # %entry
14; RV32I-NEXT:    mv a0, zero
15; RV32I-NEXT:    lui a1, %hi(b)
16; RV32I-NEXT:    addi a1, a1, %lo(b)
17; RV32I-NEXT:    lui a2, %hi(a)
18; RV32I-NEXT:    addi a2, a2, %lo(a)
19; RV32I-NEXT:    lui a3, 1
20; RV32I-NEXT:  .LBB0_1: # %for.body
21; RV32I-NEXT:    # =>This Inner Loop Header: Depth=1
22; RV32I-NEXT:    addi a4, a0, -2048
23; RV32I-NEXT:    sw a4, 0(a2)
24; RV32I-NEXT:    sw a0, 0(a1)
25; RV32I-NEXT:    addi a0, a0, 1
26; RV32I-NEXT:    addi a1, a1, 4
27; RV32I-NEXT:    addi a2, a2, 4
28; RV32I-NEXT:    bne a0, a3, .LBB0_1
29; RV32I-NEXT:  # %bb.2: # %for.end
30; RV32I-NEXT:    mv a0, zero
31; RV32I-NEXT:    ret
32entry:
33  br label %for.body
34
35for.body:
36  %i.08 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
37  %sub = add nsw i32 %i.08, -2048
38  %arrayidx = getelementptr inbounds [4096 x i32], [4096 x i32]* @a, i32 0, i32 %i.08
39  store i32 %sub, i32* %arrayidx, align 4
40  %arrayidx1 = getelementptr inbounds [4096 x i32], [4096 x i32]* @b, i32 0, i32 %i.08
41  store i32 %i.08, i32* %arrayidx1, align 4
42  %inc = add nuw nsw i32 %i.08, 1
43  %exitcond = icmp eq i32 %inc, 4096
44  br i1 %exitcond, label %for.end, label %for.body
45
46for.end:
47  ret i32 0
48}
49