xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/lea-recursion.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=x86-64 | grep lea | count 13
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; This testcase was written to demonstrate an instruction-selection problem,
4*9880d681SAndroid Build Coastguard Worker; however it also happens to expose a limitation in the DAGCombiner's
5*9880d681SAndroid Build Coastguard Worker; expression reassociation which causes it to miss opportunities for
6*9880d681SAndroid Build Coastguard Worker; constant folding due to the intermediate adds having multiple uses.
7*9880d681SAndroid Build Coastguard Worker; The Reassociate pass has similar limitations. If these limitations are
8*9880d681SAndroid Build Coastguard Worker; fixed, the test commands above will need to be updated to expect fewer
9*9880d681SAndroid Build Coastguard Worker; lea instructions.
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker@g0 = weak global [1000 x i32] zeroinitializer, align 32		; <[1000 x i32]*> [#uses=8]
12*9880d681SAndroid Build Coastguard Worker@g1 = weak global [1000 x i32] zeroinitializer, align 32		; <[1000 x i32]*> [#uses=7]
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerdefine void @foo() {
15*9880d681SAndroid Build Coastguard Workerentry:
16*9880d681SAndroid Build Coastguard Worker	%tmp4 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 0)		; <i32> [#uses=1]
17*9880d681SAndroid Build Coastguard Worker	%tmp8 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g1, i32 0, i32 0)		; <i32> [#uses=1]
18*9880d681SAndroid Build Coastguard Worker	%tmp9 = add i32 %tmp4, 1		; <i32> [#uses=1]
19*9880d681SAndroid Build Coastguard Worker	%tmp10 = add i32 %tmp9, %tmp8		; <i32> [#uses=2]
20*9880d681SAndroid Build Coastguard Worker	store i32 %tmp10, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 1)
21*9880d681SAndroid Build Coastguard Worker	%tmp8.1 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g1, i32 0, i32 1)		; <i32> [#uses=1]
22*9880d681SAndroid Build Coastguard Worker	%tmp9.1 = add i32 %tmp10, 1		; <i32> [#uses=1]
23*9880d681SAndroid Build Coastguard Worker	%tmp10.1 = add i32 %tmp9.1, %tmp8.1		; <i32> [#uses=2]
24*9880d681SAndroid Build Coastguard Worker	store i32 %tmp10.1, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 2)
25*9880d681SAndroid Build Coastguard Worker	%tmp8.2 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g1, i32 0, i32 2)		; <i32> [#uses=1]
26*9880d681SAndroid Build Coastguard Worker	%tmp9.2 = add i32 %tmp10.1, 1		; <i32> [#uses=1]
27*9880d681SAndroid Build Coastguard Worker	%tmp10.2 = add i32 %tmp9.2, %tmp8.2		; <i32> [#uses=2]
28*9880d681SAndroid Build Coastguard Worker	store i32 %tmp10.2, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 3)
29*9880d681SAndroid Build Coastguard Worker	%tmp8.3 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g1, i32 0, i32 3)		; <i32> [#uses=1]
30*9880d681SAndroid Build Coastguard Worker	%tmp9.3 = add i32 %tmp10.2, 1		; <i32> [#uses=1]
31*9880d681SAndroid Build Coastguard Worker	%tmp10.3 = add i32 %tmp9.3, %tmp8.3		; <i32> [#uses=2]
32*9880d681SAndroid Build Coastguard Worker	store i32 %tmp10.3, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 4)
33*9880d681SAndroid Build Coastguard Worker	%tmp8.4 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g1, i32 0, i32 4)		; <i32> [#uses=1]
34*9880d681SAndroid Build Coastguard Worker	%tmp9.4 = add i32 %tmp10.3, 1		; <i32> [#uses=1]
35*9880d681SAndroid Build Coastguard Worker	%tmp10.4 = add i32 %tmp9.4, %tmp8.4		; <i32> [#uses=2]
36*9880d681SAndroid Build Coastguard Worker	store i32 %tmp10.4, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 5)
37*9880d681SAndroid Build Coastguard Worker	%tmp8.5 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g1, i32 0, i32 5)		; <i32> [#uses=1]
38*9880d681SAndroid Build Coastguard Worker	%tmp9.5 = add i32 %tmp10.4, 1		; <i32> [#uses=1]
39*9880d681SAndroid Build Coastguard Worker	%tmp10.5 = add i32 %tmp9.5, %tmp8.5		; <i32> [#uses=2]
40*9880d681SAndroid Build Coastguard Worker	store i32 %tmp10.5, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 6)
41*9880d681SAndroid Build Coastguard Worker	%tmp8.6 = load i32, i32* getelementptr ([1000 x i32], [1000 x i32]* @g1, i32 0, i32 6)		; <i32> [#uses=1]
42*9880d681SAndroid Build Coastguard Worker	%tmp9.6 = add i32 %tmp10.5, 1		; <i32> [#uses=1]
43*9880d681SAndroid Build Coastguard Worker	%tmp10.6 = add i32 %tmp9.6, %tmp8.6		; <i32> [#uses=1]
44*9880d681SAndroid Build Coastguard Worker	store i32 %tmp10.6, i32* getelementptr ([1000 x i32], [1000 x i32]* @g0, i32 0, i32 7)
45*9880d681SAndroid Build Coastguard Worker	ret void
46*9880d681SAndroid Build Coastguard Worker}
47