Alex Bradbury | c2f78f8 | 2018-04-26 12:57:29 +0000 | [diff] [blame] | 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 | |
| 11 | define i32 @main() nounwind { |
| 12 | ; RV32I-LABEL: main: |
| 13 | ; RV32I: # %bb.0: # %entry |
Alex Bradbury | 5c41ece | 2018-04-26 13:00:37 +0000 | [diff] [blame] | 14 | ; RV32I-NEXT: lui a0, %hi(b) |
| 15 | ; RV32I-NEXT: addi a0, a0, %lo(b) |
| 16 | ; RV32I-NEXT: lui a1, %hi(a) |
| 17 | ; RV32I-NEXT: addi a1, a1, %lo(a) |
| 18 | ; RV32I-NEXT: lui a2, 1 |
| 19 | ; RV32I-NEXT: mv a3, zero |
Alex Bradbury | c2f78f8 | 2018-04-26 12:57:29 +0000 | [diff] [blame] | 20 | ; RV32I-NEXT: .LBB0_1: # %for.body |
| 21 | ; RV32I-NEXT: # =>This Inner Loop Header: Depth=1 |
Alex Bradbury | 5c41ece | 2018-04-26 13:00:37 +0000 | [diff] [blame] | 22 | ; RV32I-NEXT: addi a4, a3, -2048 |
Alex Bradbury | c2f78f8 | 2018-04-26 12:57:29 +0000 | [diff] [blame] | 23 | ; RV32I-NEXT: sw a4, 0(a1) |
Alex Bradbury | c2f78f8 | 2018-04-26 12:57:29 +0000 | [diff] [blame] | 24 | ; RV32I-NEXT: addi a1, a1, 4 |
Alex Bradbury | 5c41ece | 2018-04-26 13:00:37 +0000 | [diff] [blame] | 25 | ; RV32I-NEXT: sw a3, 0(a0) |
| 26 | ; RV32I-NEXT: addi a0, a0, 4 |
| 27 | ; RV32I-NEXT: addi a3, a3, 1 |
| 28 | ; RV32I-NEXT: bne a3, a2, .LBB0_1 |
Alex Bradbury | c2f78f8 | 2018-04-26 12:57:29 +0000 | [diff] [blame] | 29 | ; RV32I-NEXT: # %bb.2: # %for.end |
| 30 | ; RV32I-NEXT: mv a0, zero |
| 31 | ; RV32I-NEXT: ret |
| 32 | entry: |
| 33 | br label %for.body |
| 34 | |
| 35 | for.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 | |
| 46 | for.end: |
| 47 | ret i32 0 |
| 48 | } |