1 ; RUN: llvm-as < %s | opt -reassociate -gvn | llvm-dis | grep add | count 6
2 ; Each of these functions should turn into two adds each.
4 @e = external global i32 ; <i32*> [#uses=3]
5 @a = external global i32 ; <i32*> [#uses=3]
6 @b = external global i32 ; <i32*> [#uses=3]
7 @c = external global i32 ; <i32*> [#uses=3]
8 @f = external global i32 ; <i32*> [#uses=3]
10 define void @test1() {
11 %A = load i32* @a ; <i32> [#uses=2]
12 %B = load i32* @b ; <i32> [#uses=2]
13 %C = load i32* @c ; <i32> [#uses=2]
14 %t1 = add i32 %A, %B ; <i32> [#uses=1]
15 %t2 = add i32 %t1, %C ; <i32> [#uses=1]
16 %t3 = add i32 %C, %A ; <i32> [#uses=1]
17 %t4 = add i32 %t3, %B ; <i32> [#uses=1]
19 store i32 %t2, i32* @e
21 store i32 %t4, i32* @f
25 define void @test2() {
26 %A = load i32* @a ; <i32> [#uses=2]
27 %B = load i32* @b ; <i32> [#uses=2]
28 %C = load i32* @c ; <i32> [#uses=2]
29 %t1 = add i32 %A, %B ; <i32> [#uses=1]
30 %t2 = add i32 %t1, %C ; <i32> [#uses=1]
31 %t3 = add i32 %C, %A ; <i32> [#uses=1]
32 %t4 = add i32 %t3, %B ; <i32> [#uses=1]
34 store i32 %t2, i32* @e
36 store i32 %t4, i32* @f
40 define void @test3() {
41 %A = load i32* @a ; <i32> [#uses=2]
42 %B = load i32* @b ; <i32> [#uses=2]
43 %C = load i32* @c ; <i32> [#uses=2]
44 %t1 = add i32 %B, %A ; <i32> [#uses=1]
45 %t2 = add i32 %t1, %C ; <i32> [#uses=1]
46 %t3 = add i32 %C, %A ; <i32> [#uses=1]
47 %t4 = add i32 %t3, %B ; <i32> [#uses=1]
49 store i32 %t2, i32* @e
51 store i32 %t4, i32* @f