1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s -check-prefix=X64
3; RUN: llc < %s -mtriple=i686-unknown   | FileCheck %s -check-prefix=X86
4
5%struct.SA = type { i32 , i32 , i32 , i32 , i32};
6
7define void @foo(%struct.SA* nocapture %ctx, i32 %n) local_unnamed_addr #0 {
8; X64-LABEL: foo:
9; X64:       # %bb.0: # %entry
10; X64-NEXT:    .p2align 4, 0x90
11; X64-NEXT:  .LBB0_1: # %loop
12; X64-NEXT:    # =>This Inner Loop Header: Depth=1
13; X64-NEXT:    movl (%rdi), %eax
14; X64-NEXT:    movl 16(%rdi), %ecx
15; X64-NEXT:    leal 1(%rax,%rcx), %edx
16; X64-NEXT:    movl %edx, 12(%rdi)
17; X64-NEXT:    decl %esi
18; X64-NEXT:    jne .LBB0_1
19; X64-NEXT:  # %bb.2: # %exit
20; X64-NEXT:    addl %ecx, %eax
21; X64-NEXT:    leal 1(%rcx,%rax), %eax
22; X64-NEXT:    movl %eax, 16(%rdi)
23; X64-NEXT:    retq
24;
25; X86-LABEL: foo:
26; X86:       # %bb.0: # %entry
27; X86-NEXT:    pushl %edi
28; X86-NEXT:    .cfi_def_cfa_offset 8
29; X86-NEXT:    pushl %esi
30; X86-NEXT:    .cfi_def_cfa_offset 12
31; X86-NEXT:    .cfi_offset %esi, -12
32; X86-NEXT:    .cfi_offset %edi, -8
33; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
34; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
35; X86-NEXT:    .p2align 4, 0x90
36; X86-NEXT:  .LBB0_1: # %loop
37; X86-NEXT:    # =>This Inner Loop Header: Depth=1
38; X86-NEXT:    movl (%eax), %edx
39; X86-NEXT:    movl 16(%eax), %esi
40; X86-NEXT:    leal 1(%edx,%esi), %edi
41; X86-NEXT:    movl %edi, 12(%eax)
42; X86-NEXT:    decl %ecx
43; X86-NEXT:    jne .LBB0_1
44; X86-NEXT:  # %bb.2: # %exit
45; X86-NEXT:    addl %esi, %edx
46; X86-NEXT:    leal 1(%esi,%edx), %ecx
47; X86-NEXT:    movl %ecx, 16(%eax)
48; X86-NEXT:    popl %esi
49; X86-NEXT:    .cfi_def_cfa_offset 8
50; X86-NEXT:    popl %edi
51; X86-NEXT:    .cfi_def_cfa_offset 4
52; X86-NEXT:    retl
53 entry:
54   br label %loop
55
56 loop:
57   %iter = phi i32 [%n ,%entry ] ,[ %iter.ctr ,%loop]
58   %h0 = getelementptr inbounds %struct.SA, %struct.SA* %ctx, i64 0, i32 0
59   %0 = load i32, i32* %h0, align 8
60   %h3 = getelementptr inbounds %struct.SA, %struct.SA* %ctx, i64 0, i32 3
61   %h4 = getelementptr inbounds %struct.SA, %struct.SA* %ctx, i64 0, i32 4
62   %1 = load i32, i32* %h4, align 8
63   %add = add i32 %0, 1
64   %add4 = add i32 %add, %1
65   store i32 %add4, i32* %h3, align 4
66   %add29 = add i32 %add4, %1
67   %iter.ctr = sub i32 %iter , 1
68   %res = icmp ne i32 %iter.ctr , 0
69   br i1 %res , label %loop , label %exit
70
71 exit:
72   store i32 %add29, i32* %h4, align 8
73   ret void
74}
75