xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/lea-5.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; test for more complicated forms of lea operands which can be generated
2*9880d681SAndroid Build Coastguard Worker; in loop optimized cases.
3*9880d681SAndroid Build Coastguard Worker; See also http://llvm.org/bugs/show_bug.cgi?id=20016
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-linux -O2        | FileCheck %s
6*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-linux-gnux32 -O2 | FileCheck %s -check-prefix=X32
7*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-nacl -O2 | FileCheck %s -check-prefix=X32
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone uwtable
10*9880d681SAndroid Build Coastguard Workerdefine void @foo(i32 %x, i32 %d) #0 {
11*9880d681SAndroid Build Coastguard Workerentry:
12*9880d681SAndroid Build Coastguard Worker  %a = alloca [8 x i32], align 16
13*9880d681SAndroid Build Coastguard Worker  br label %while.cond
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerwhile.cond:                                       ; preds = %while.cond, %entry
16*9880d681SAndroid Build Coastguard Worker  %d.addr.0 = phi i32 [ %d, %entry ], [ %inc, %while.cond ]
17*9880d681SAndroid Build Coastguard Worker  %arrayidx = getelementptr inbounds [8 x i32], [8 x i32]* %a, i32 0, i32 %d.addr.0
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker; CHECK: leaq	-40(%rsp,%r{{[^,]*}},4), %rax
20*9880d681SAndroid Build Coastguard Worker; X32:   leal	-40(%rsp,%r{{[^,]*}},4), %eax
21*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %arrayidx, align 4
22*9880d681SAndroid Build Coastguard Worker  %cmp1 = icmp eq i32 %0, 0
23*9880d681SAndroid Build Coastguard Worker  %inc = add nsw i32 %d.addr.0, 1
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; CHECK: leaq	4(%r{{[^,]*}}), %r{{[^,]*}}
26*9880d681SAndroid Build Coastguard Worker; X32:   leal	4(%r{{[^,]*}}), %e{{[^,]*}}
27*9880d681SAndroid Build Coastguard Worker  br i1 %cmp1, label %while.end, label %while.cond
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Workerwhile.end:                                        ; preds = %while.cond
30*9880d681SAndroid Build Coastguard Worker  ret void
31*9880d681SAndroid Build Coastguard Worker}
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker; The same test as above but with enforsed stack realignment (%a aligned by 64)
34*9880d681SAndroid Build Coastguard Worker; to check one more case of correct lea generation.
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone uwtable
37*9880d681SAndroid Build Coastguard Workerdefine void @bar(i32 %x, i32 %d) #0 {
38*9880d681SAndroid Build Coastguard Workerentry:
39*9880d681SAndroid Build Coastguard Worker  %a = alloca [8 x i32], align 64
40*9880d681SAndroid Build Coastguard Worker  br label %while.cond
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Workerwhile.cond:                                       ; preds = %while.cond, %entry
43*9880d681SAndroid Build Coastguard Worker  %d.addr.0 = phi i32 [ %d, %entry ], [ %inc, %while.cond ]
44*9880d681SAndroid Build Coastguard Worker  %arrayidx = getelementptr inbounds [8 x i32], [8 x i32]* %a, i32 0, i32 %d.addr.0
45*9880d681SAndroid Build Coastguard Worker
46*9880d681SAndroid Build Coastguard Worker; CHECK: leaq	(%rsp,%r{{[^,]*}},4), %rax
47*9880d681SAndroid Build Coastguard Worker; X32:   leal	(%rsp,%r{{[^,]*}},4), %eax
48*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* %arrayidx, align 4
49*9880d681SAndroid Build Coastguard Worker  %cmp1 = icmp eq i32 %0, 0
50*9880d681SAndroid Build Coastguard Worker  %inc = add nsw i32 %d.addr.0, 1
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker; CHECK: leaq	4(%r{{[^,]*}}), %r{{[^,]*}}
53*9880d681SAndroid Build Coastguard Worker; X32:   leal	4(%r{{[^,]*}}), %e{{[^,]*}}
54*9880d681SAndroid Build Coastguard Worker  br i1 %cmp1, label %while.end, label %while.cond
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Workerwhile.end:                                        ; preds = %while.cond
57*9880d681SAndroid Build Coastguard Worker  ret void
58*9880d681SAndroid Build Coastguard Worker}
59*9880d681SAndroid Build Coastguard Worker
60