1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s --check-prefixes=LINUX
3; RUN: llc < %s -mtriple=x86_64-win32 | FileCheck %s --check-prefixes=WIN
4; RUN: llc < %s -mtriple=x86_64-linux-gnux32 | FileCheck %s --check-prefixes=LINUX
5; RUN: llc < %s -mtriple=x86_64-nacl | FileCheck %s --check-prefixes=LINUX
6
7define i32 @test1(i32 %x) nounwind {
8; LINUX-LABEL: test1:
9; LINUX:       # %bb.0:
10; LINUX-NEXT:    # kill: def $edi killed $edi def $rdi
11; LINUX-NEXT:    leal 7(,%rdi,8), %eax
12; LINUX-NEXT:    retq
13;
14; WIN-LABEL: test1:
15; WIN:       # %bb.0:
16; WIN-NEXT:    # kill: def $ecx killed $ecx def $rcx
17; WIN-NEXT:    leal 7(,%rcx,8), %eax
18; WIN-NEXT:    retq
19  %tmp1 = shl i32 %x, 3
20  %tmp2 = add i32 %tmp1, 7
21  ret i32 %tmp2
22}
23
24
25; ISel the add of -4 with a neg and use an lea for the rest of the
26; arithmetic.
27define i32 @test2(i32 %x_offs) nounwind readnone {
28; LINUX-LABEL: test2:
29; LINUX:       # %bb.0: # %entry
30; LINUX-NEXT:    # kill: def $edi killed $edi def $rdi
31; LINUX-NEXT:    cmpl $5, %edi
32; LINUX-NEXT:    jl .LBB1_2
33; LINUX-NEXT:  # %bb.1: # %bb.nph
34; LINUX-NEXT:    leal -5(%rdi), %eax
35; LINUX-NEXT:    andl $-4, %eax
36; LINUX-NEXT:    negl %eax
37; LINUX-NEXT:    leal -4(%rdi,%rax), %eax
38; LINUX-NEXT:    retq
39; LINUX-NEXT:  .LBB1_2: # %bb2
40; LINUX-NEXT:    movl %edi, %eax
41; LINUX-NEXT:    retq
42;
43; WIN-LABEL: test2:
44; WIN:       # %bb.0: # %entry
45; WIN-NEXT:    # kill: def $ecx killed $ecx def $rcx
46; WIN-NEXT:    cmpl $5, %ecx
47; WIN-NEXT:    jl .LBB1_2
48; WIN-NEXT:  # %bb.1: # %bb.nph
49; WIN-NEXT:    leal -5(%rcx), %eax
50; WIN-NEXT:    andl $-4, %eax
51; WIN-NEXT:    negl %eax
52; WIN-NEXT:    leal -4(%rcx,%rax), %eax
53; WIN-NEXT:    retq
54; WIN-NEXT:  .LBB1_2: # %bb2
55; WIN-NEXT:    movl %ecx, %eax
56; WIN-NEXT:    retq
57entry:
58  %t0 = icmp sgt i32 %x_offs, 4
59  br i1 %t0, label %bb.nph, label %bb2
60
61bb.nph:
62  %tmp = add i32 %x_offs, -5
63  %tmp6 = lshr i32 %tmp, 2
64  %tmp7 = mul i32 %tmp6, -4
65  %tmp8 = add i32 %tmp7, %x_offs
66  %tmp9 = add i32 %tmp8, -4
67  ret i32 %tmp9
68
69bb2:
70  ret i32 %x_offs
71}
72