| OLD | NEW |
| 1 ; RUIN: %llvm2ice -verbose inst %s | FileCheck %s | 1 ; This tests a simple loop that sums the elements of an input array. |
| 2 ; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s | 2 ; The O2 check patterns represent the best code currently achieved. |
| 3 |
| 4 ; RUIN: %llvm2ice -O2 --verbose none %s | FileCheck %s |
| 5 ; RUN: %llvm2ice -Om1 --verbose none %s | FileCheck --check-prefix=OPTM1 %s |
| 6 ; RUN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s |
| 3 ; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s | 7 ; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s |
| 4 | 8 |
| 5 define i32 @simple_loop(i32 %a, i32 %n) { | 9 define i32 @simple_loop(i32 %a, i32 %n) { |
| 6 entry: | 10 entry: |
| 7 %cmp4 = icmp sgt i32 %n, 0 | 11 %cmp4 = icmp sgt i32 %n, 0 |
| 8 br i1 %cmp4, label %for.body, label %for.end | 12 br i1 %cmp4, label %for.body, label %for.end |
| 9 | 13 |
| 10 for.body: | 14 for.body: |
| 11 %i.06 = phi i32 [ %inc, %for.body ], [ 0, %entry ] | 15 %i.06 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| 12 %sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ] | 16 %sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ] |
| 13 %gep_array = mul i32 %i.06, 4 | 17 %gep_array = mul i32 %i.06, 4 |
| 14 %gep = add i32 %a, %gep_array | 18 %gep = add i32 %a, %gep_array |
| 15 %gep.asptr = inttoptr i32 %gep to i32* | 19 %gep.asptr = inttoptr i32 %gep to i32* |
| 16 %v0 = load i32* %gep.asptr, align 1 | 20 %v0 = load i32* %gep.asptr, align 1 |
| 17 %add = add i32 %v0, %sum.05 | 21 %add = add i32 %v0, %sum.05 |
| 18 %inc = add i32 %i.06, 1 | 22 %inc = add i32 %i.06, 1 |
| 19 %cmp = icmp slt i32 %inc, %n | 23 %cmp = icmp slt i32 %inc, %n |
| 20 br i1 %cmp, label %for.body, label %for.end | 24 br i1 %cmp, label %for.body, label %for.end |
| 21 | 25 |
| 22 for.end: | 26 for.end: |
| 23 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ] | 27 %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ] |
| 24 ret i32 %sum.0.lcssa | 28 ret i32 %sum.0.lcssa |
| 25 } | 29 } |
| 26 | 30 |
| 27 ; Checks for verbose instruction output | |
| 28 | |
| 29 ; CHECK: br i1 %cmp4, label %for.body, label %for.end | |
| 30 ; CHECK-NEXT: for.body | |
| 31 ; CHECK: %i.06 = phi i32 [ %inc, %for.body ], [ 0, %entry ] | |
| 32 ; CHECK-NEXT: %sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ] | |
| 33 | |
| 34 ; Checks for emitted assembly | |
| 35 | |
| 36 ; CHECK: .globl simple_loop | 31 ; CHECK: .globl simple_loop |
| 37 | |
| 38 ; CHECK: mov ecx, dword ptr [esp+{{[0-9]+}}] | 32 ; CHECK: mov ecx, dword ptr [esp+{{[0-9]+}}] |
| 39 ; CHECK: cmp ecx, 0 | 33 ; CHECK: cmp ecx, 0 |
| 40 ; CHECK-NEXT: jg {{.*}}for.body | 34 ; CHECK-NEXT: jg {{.*}}for.body |
| 41 ; CHECK-NEXT: jmp {{.*}}for.end | 35 ; CHECK-NEXT: jmp {{.*}}for.end |
| 42 | 36 |
| 43 ; TODO: the mov from ebx to esi seems redundant here - so this may need to be | 37 ; TODO: the mov from ebx to esi seems redundant here - so this may need to be |
| 44 ; modified later | 38 ; modified later |
| 45 | 39 |
| 46 ; CHECK: add [[IREG:[a-z]+]], 1 | 40 ; CHECK: add [[IREG:[a-z]+]], 1 |
| 47 ; CHECK-NEXT: mov [[ICMPREG:[a-z]+]], [[IREG]] | 41 ; CHECK-NEXT: mov [[ICMPREG:[a-z]+]], [[IREG]] |
| 48 ; CHECK: cmp [[ICMPREG]], ecx | 42 ; CHECK: cmp [[ICMPREG]], ecx |
| 49 ; CHECK-NEXT: jl {{.*}}for.body | 43 ; CHECK-NEXT: jl {{.*}}for.body |
| 44 ; |
| 45 ; There's nothing remarkable under Om1 to test for, since Om1 generates |
| 46 ; such atrocious code (by design). |
| 47 ; OPTM1: .globl simple_loop |
| 48 ; OPTM1: cmp {{.*}}, 0 |
| 49 ; OPTM1: jg |
| 50 ; OPTM1: ret |
| 50 | 51 |
| 51 ; ERRORS-NOT: ICE translation error | 52 ; ERRORS-NOT: ICE translation error |
| 52 ; DUMP-NOT: SZ | 53 ; DUMP-NOT: SZ |
| OLD | NEW |