From 009b1c42aa6266385f2c37e227516b24077e6dd7 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Tue, 2 Jun 2009 17:52:33 +0000 Subject: Import LLVM, at r72732. --- .../Reassociate/2002-05-15-AgressiveSubMove.ll | 9 ++++ .../Reassociate/2002-05-15-MissedTree.ll | 9 ++++ .../Reassociate/2002-05-15-SubReassociate.ll | 12 +++++ .../Reassociate/2002-05-15-SubReassociate2.ll | 13 ++++++ .../Reassociate/2002-07-09-DominanceProblem.ll | 10 ++++ .../Reassociate/2003-08-12-InfiniteLoop.ll | 9 ++++ test/Transforms/Reassociate/2005-08-24-Crash.ll | 13 ++++++ .../Reassociate/2005-09-01-ArrayOutOfBounds.ll | 23 +++++++++ .../Reassociate/2006-04-27-ReassociateVector.ll | 8 ++++ test/Transforms/Reassociate/basictest.ll | 10 ++++ test/Transforms/Reassociate/basictest2.ll | 11 +++++ test/Transforms/Reassociate/basictest3.ll | 54 ++++++++++++++++++++++ test/Transforms/Reassociate/basictest4.ll | 23 +++++++++ test/Transforms/Reassociate/dg.exp | 3 ++ test/Transforms/Reassociate/inverses.ll | 28 +++++++++++ test/Transforms/Reassociate/looptest.ll | 50 ++++++++++++++++++++ test/Transforms/Reassociate/mul-factor3.ll | 16 +++++++ test/Transforms/Reassociate/mul-neg-add.ll | 10 ++++ test/Transforms/Reassociate/mulfactor.ll | 14 ++++++ test/Transforms/Reassociate/mulfactor2.ll | 16 +++++++ test/Transforms/Reassociate/negation.ll | 21 +++++++++ test/Transforms/Reassociate/otherops.ll | 28 +++++++++++ test/Transforms/Reassociate/shift-factor.ll | 13 ++++++ test/Transforms/Reassociate/shifttest.ll | 12 +++++ test/Transforms/Reassociate/subtest.ll | 11 +++++ test/Transforms/Reassociate/subtest2.ll | 13 ++++++ 26 files changed, 439 insertions(+) create mode 100644 test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll create mode 100644 test/Transforms/Reassociate/2002-05-15-MissedTree.ll create mode 100644 test/Transforms/Reassociate/2002-05-15-SubReassociate.ll create mode 100644 test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll create mode 100644 test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll create mode 100644 test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll create mode 100644 test/Transforms/Reassociate/2005-08-24-Crash.ll create mode 100644 test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll create mode 100644 test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll create mode 100644 test/Transforms/Reassociate/basictest.ll create mode 100644 test/Transforms/Reassociate/basictest2.ll create mode 100644 test/Transforms/Reassociate/basictest3.ll create mode 100644 test/Transforms/Reassociate/basictest4.ll create mode 100644 test/Transforms/Reassociate/dg.exp create mode 100644 test/Transforms/Reassociate/inverses.ll create mode 100644 test/Transforms/Reassociate/looptest.ll create mode 100644 test/Transforms/Reassociate/mul-factor3.ll create mode 100644 test/Transforms/Reassociate/mul-neg-add.ll create mode 100644 test/Transforms/Reassociate/mulfactor.ll create mode 100644 test/Transforms/Reassociate/mulfactor2.ll create mode 100644 test/Transforms/Reassociate/negation.ll create mode 100644 test/Transforms/Reassociate/otherops.ll create mode 100644 test/Transforms/Reassociate/shift-factor.ll create mode 100644 test/Transforms/Reassociate/shifttest.ll create mode 100644 test/Transforms/Reassociate/subtest.ll create mode 100644 test/Transforms/Reassociate/subtest2.ll (limited to 'test/Transforms/Reassociate') diff --git a/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll b/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll new file mode 100644 index 000000000000..5465418d00de --- /dev/null +++ b/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | opt -reassociate -instcombine -constprop -dce | llvm-dis | not grep add + +define i32 @test(i32 %A) { + %X = add i32 %A, 1 ; [#uses=1] + %Y = add i32 %A, 1 ; [#uses=1] + %r = sub i32 %X, %Y ; [#uses=1] + ret i32 %r +} + diff --git a/test/Transforms/Reassociate/2002-05-15-MissedTree.ll b/test/Transforms/Reassociate/2002-05-15-MissedTree.ll new file mode 100644 index 000000000000..79afb6e64c13 --- /dev/null +++ b/test/Transforms/Reassociate/2002-05-15-MissedTree.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | opt -reassociate -instcombine -constprop -die | llvm-dis | not grep 5 + +define i32 @test(i32 %A, i32 %B) { + %W = add i32 %B, -5 ; [#uses=1] + %Y = add i32 %A, 5 ; [#uses=1] + %Z = add i32 %W, %Y ; [#uses=1] + ret i32 %Z +} + diff --git a/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll b/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll new file mode 100644 index 000000000000..de0666e95617 --- /dev/null +++ b/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll @@ -0,0 +1,12 @@ +; With sub reassociation, constant folding can eliminate all of the constants. +; +; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -dce | llvm-dis | not grep add + +define i32 @test(i32 %A, i32 %B) { + %W = add i32 5, %B ; [#uses=1] + %X = add i32 -7, %A ; [#uses=1] + %Y = sub i32 %X, %W ; [#uses=1] + %Z = add i32 %Y, 12 ; [#uses=1] + ret i32 %Z +} + diff --git a/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll b/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll new file mode 100644 index 000000000000..070080acf24f --- /dev/null +++ b/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll @@ -0,0 +1,13 @@ +; With sub reassociation, constant folding can eliminate the two 12 constants. +; +; RUN: llvm-as < %s | opt -reassociate -constprop -dce | llvm-dis | not grep 12 + +define i32 @test(i32 %A, i32 %B, i32 %C, i32 %D) { + %M = add i32 %A, 12 ; [#uses=1] + %N = add i32 %M, %B ; [#uses=1] + %O = add i32 %N, %C ; [#uses=1] + %P = sub i32 %D, %O ; [#uses=1] + %Q = add i32 %P, 12 ; [#uses=1] + ret i32 %Q +} + diff --git a/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll b/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll new file mode 100644 index 000000000000..c19baeaae68f --- /dev/null +++ b/test/Transforms/Reassociate/2002-07-09-DominanceProblem.ll @@ -0,0 +1,10 @@ +; The reassociate pass is not preserving dominance properties correctly +; +; RUN: llvm-as < %s | opt -reassociate + +define i32 @compute_dist(i32 %i, i32 %j) { + %reg119 = sub i32 %j, %i ; [#uses=1] + ret i32 %reg119 +} + + diff --git a/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll b/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll new file mode 100644 index 000000000000..41cba63d8fda --- /dev/null +++ b/test/Transforms/Reassociate/2003-08-12-InfiniteLoop.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | opt -reassociate -disable-output + +define i32 @test(i32 %A.1, i32 %B.1, i32 %C.1, i32 %D.1) { + %tmp.16 = and i32 %A.1, %B.1 ; [#uses=1] + %tmp.18 = and i32 %tmp.16, %C.1 ; [#uses=1] + %tmp.20 = and i32 %tmp.18, %D.1 ; [#uses=1] + ret i32 %tmp.20 +} + diff --git a/test/Transforms/Reassociate/2005-08-24-Crash.ll b/test/Transforms/Reassociate/2005-08-24-Crash.ll new file mode 100644 index 000000000000..99c98ef5932c --- /dev/null +++ b/test/Transforms/Reassociate/2005-08-24-Crash.ll @@ -0,0 +1,13 @@ +; RUN: llvm-as < %s | opt -reassociate -disable-output + +define void @test(i32 %a, i32 %b, i32 %c, i32 %d) { + %tmp.2 = xor i32 %a, %b ; [#uses=1] + %tmp.5 = xor i32 %c, %d ; [#uses=1] + %tmp.6 = xor i32 %tmp.2, %tmp.5 ; [#uses=1] + %tmp.9 = xor i32 %c, %a ; [#uses=1] + %tmp.12 = xor i32 %b, %d ; [#uses=1] + %tmp.13 = xor i32 %tmp.9, %tmp.12 ; [#uses=1] + %tmp.16 = xor i32 %tmp.6, %tmp.13 ; [#uses=0] + ret void +} + diff --git a/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll b/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll new file mode 100644 index 000000000000..d11a2ea767a9 --- /dev/null +++ b/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll @@ -0,0 +1,23 @@ +; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis |\ +; RUN: grep {ret i32 0} + +define i32 @f(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) { + %tmp.2 = add i32 %a4, %a3 ; [#uses=1] + %tmp.4 = add i32 %tmp.2, %a2 ; [#uses=1] + %tmp.6 = add i32 %tmp.4, %a1 ; [#uses=1] + %tmp.8 = add i32 %tmp.6, %a0 ; [#uses=1] + %tmp.11 = add i32 %a3, %a2 ; [#uses=1] + %tmp.13 = add i32 %tmp.11, %a1 ; [#uses=1] + %tmp.15 = add i32 %tmp.13, %a0 ; [#uses=1] + %tmp.18 = add i32 %a2, %a1 ; [#uses=1] + %tmp.20 = add i32 %tmp.18, %a0 ; [#uses=1] + %tmp.23 = add i32 %a1, %a0 ; [#uses=1] + %tmp.26 = sub i32 %tmp.8, %tmp.15 ; [#uses=1] + %tmp.28 = add i32 %tmp.26, %tmp.20 ; [#uses=1] + %tmp.30 = sub i32 %tmp.28, %tmp.23 ; [#uses=1] + %tmp.32 = sub i32 %tmp.30, %a4 ; [#uses=1] + %tmp.34 = sub i32 %tmp.32, %a2 ; [#uses=2] + %T = mul i32 %tmp.34, %tmp.34 ; [#uses=1] + ret i32 %T +} + diff --git a/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll b/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll new file mode 100644 index 000000000000..05d6103bbfd3 --- /dev/null +++ b/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | opt -reassociate -disable-output + +define void @foo() { + %tmp162 = sub <4 x float> zeroinitializer, zeroinitializer ; <<4 x float>> [#uses=1] + %tmp164 = mul <4 x float> zeroinitializer, %tmp162 ; <<4 x float>> [#uses=0] + ret void +} + diff --git a/test/Transforms/Reassociate/basictest.ll b/test/Transforms/Reassociate/basictest.ll new file mode 100644 index 000000000000..09db47b1907c --- /dev/null +++ b/test/Transforms/Reassociate/basictest.ll @@ -0,0 +1,10 @@ +; With reassociation, constant folding can eliminate the 12 and -12 constants. +; +; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep add + +define i32 @test(i32 %arg) { + %tmp1 = sub i32 -12, %arg ; [#uses=1] + %tmp2 = add i32 %tmp1, 12 ; [#uses=1] + ret i32 %tmp2 +} + diff --git a/test/Transforms/Reassociate/basictest2.ll b/test/Transforms/Reassociate/basictest2.ll new file mode 100644 index 000000000000..dbde3af35e1b --- /dev/null +++ b/test/Transforms/Reassociate/basictest2.ll @@ -0,0 +1,11 @@ +; With reassociation, constant folding can eliminate the +/- 30 constants. +; +; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 30 + +define i32 @test(i32 %reg109, i32 %reg1111) { + %reg115 = add i32 %reg109, -30 ; [#uses=1] + %reg116 = add i32 %reg115, %reg1111 ; [#uses=1] + %reg117 = add i32 %reg116, 30 ; [#uses=1] + ret i32 %reg117 +} + diff --git a/test/Transforms/Reassociate/basictest3.ll b/test/Transforms/Reassociate/basictest3.ll new file mode 100644 index 000000000000..a88030db2f9a --- /dev/null +++ b/test/Transforms/Reassociate/basictest3.ll @@ -0,0 +1,54 @@ +; RUN: llvm-as < %s | opt -reassociate -gvn | llvm-dis | grep add | count 6 +; Each of these functions should turn into two adds each. + +@e = external global i32 ; [#uses=3] +@a = external global i32 ; [#uses=3] +@b = external global i32 ; [#uses=3] +@c = external global i32 ; [#uses=3] +@f = external global i32 ; [#uses=3] + +define void @test1() { + %A = load i32* @a ; [#uses=2] + %B = load i32* @b ; [#uses=2] + %C = load i32* @c ; [#uses=2] + %t1 = add i32 %A, %B ; [#uses=1] + %t2 = add i32 %t1, %C ; [#uses=1] + %t3 = add i32 %C, %A ; [#uses=1] + %t4 = add i32 %t3, %B ; [#uses=1] + ; e = (a+b)+c; + store i32 %t2, i32* @e + ; f = (a+c)+b + store i32 %t4, i32* @f + ret void +} + +define void @test2() { + %A = load i32* @a ; [#uses=2] + %B = load i32* @b ; [#uses=2] + %C = load i32* @c ; [#uses=2] + %t1 = add i32 %A, %B ; [#uses=1] + %t2 = add i32 %t1, %C ; [#uses=1] + %t3 = add i32 %C, %A ; [#uses=1] + %t4 = add i32 %t3, %B ; [#uses=1] + ; e = c+(a+b) + store i32 %t2, i32* @e + ; f = (c+a)+b + store i32 %t4, i32* @f + ret void +} + +define void @test3() { + %A = load i32* @a ; [#uses=2] + %B = load i32* @b ; [#uses=2] + %C = load i32* @c ; [#uses=2] + %t1 = add i32 %B, %A ; [#uses=1] + %t2 = add i32 %t1, %C ; [#uses=1] + %t3 = add i32 %C, %A ; [#uses=1] + %t4 = add i32 %t3, %B ; [#uses=1] + ; e = c+(b+a) + store i32 %t2, i32* @e + ; f = (c+a)+b + store i32 %t4, i32* @f + ret void +} + diff --git a/test/Transforms/Reassociate/basictest4.ll b/test/Transforms/Reassociate/basictest4.ll new file mode 100644 index 000000000000..608becd9c3a9 --- /dev/null +++ b/test/Transforms/Reassociate/basictest4.ll @@ -0,0 +1,23 @@ +; RUN: llvm-as < %s | opt -reassociate -gvn -instcombine | llvm-dis | not grep add + +@a = weak global i32 0 ; [#uses=1] +@b = weak global i32 0 ; [#uses=1] +@c = weak global i32 0 ; [#uses=1] +@d = weak global i32 0 ; [#uses=0] + +define i32 @foo() { + %tmp.0 = load i32* @a ; [#uses=2] + %tmp.1 = load i32* @b ; [#uses=2] + ; (a+b) + %tmp.2 = add i32 %tmp.0, %tmp.1 ; [#uses=1] + %tmp.4 = load i32* @c ; [#uses=2] + ; (a+b)+c + %tmp.5 = add i32 %tmp.2, %tmp.4 ; [#uses=1] + ; (a+c) + %tmp.8 = add i32 %tmp.0, %tmp.4 ; [#uses=1] + ; (a+c)+b + %tmp.11 = add i32 %tmp.8, %tmp.1 ; [#uses=1] + ; X ^ X = 0 + %RV = xor i32 %tmp.5, %tmp.11 ; [#uses=1] + ret i32 %RV +} diff --git a/test/Transforms/Reassociate/dg.exp b/test/Transforms/Reassociate/dg.exp new file mode 100644 index 000000000000..f2005891a59a --- /dev/null +++ b/test/Transforms/Reassociate/dg.exp @@ -0,0 +1,3 @@ +load_lib llvm.exp + +RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]] diff --git a/test/Transforms/Reassociate/inverses.ll b/test/Transforms/Reassociate/inverses.ll new file mode 100644 index 000000000000..5b08d0eec675 --- /dev/null +++ b/test/Transforms/Reassociate/inverses.ll @@ -0,0 +1,28 @@ +; RUN: llvm-as < %s | opt -reassociate -dce | llvm-dis | \ +; RUN: not grep {\\(and\\|sub\\)} + +define i32 @test1(i32 %a, i32 %b) { + %tmp.2 = and i32 %b, %a ; [#uses=1] + %tmp.4 = xor i32 %a, -1 ; [#uses=1] + ; (A&B)&~A == 0 + %tmp.5 = and i32 %tmp.2, %tmp.4 ; [#uses=1] + ret i32 %tmp.5 +} + +define i32 @test2(i32 %a, i32 %b) { + %tmp.1 = and i32 %a, 1234 ; [#uses=1] + %tmp.2 = and i32 %b, %tmp.1 ; [#uses=1] + %tmp.4 = xor i32 %a, -1 ; [#uses=1] + ; A&~A == 0 + %tmp.5 = and i32 %tmp.2, %tmp.4 ; [#uses=1] + ret i32 %tmp.5 +} + +define i32 @test3(i32 %b, i32 %a) { + %tmp.1 = add i32 %a, 1234 ; [#uses=1] + %tmp.2 = add i32 %b, %tmp.1 ; [#uses=1] + %tmp.4 = sub i32 0, %a ; [#uses=1] + ; (b+(a+1234))+-a -> b+1234 + %tmp.5 = add i32 %tmp.2, %tmp.4 ; [#uses=1] + ret i32 %tmp.5 +} diff --git a/test/Transforms/Reassociate/looptest.ll b/test/Transforms/Reassociate/looptest.ll new file mode 100644 index 000000000000..3b28c2389538 --- /dev/null +++ b/test/Transforms/Reassociate/looptest.ll @@ -0,0 +1,50 @@ +; This testcase comes from this C fragment: +; +; void test(unsigned Num, int *Array) { +; unsigned i, j, k; +; +; for (i = 0; i != Num; ++i) +; for (j = 0; j != Num; ++j) +; for (k = 0; k != Num; ++k) +; printf("%d\n", i+k+j); /* Reassociate to (i+j)+k */ +;} +; +; In this case, we want to reassociate the specified expr so that i+j can be +; hoisted out of the inner most loop. +; +; RUN: llvm-as < %s | opt -reassociate | llvm-dis | grep 115 | not grep 117 +; END. +@.LC0 = internal global [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1] + +declare i32 @printf(i8*, ...) + +define void @test(i32 %Num, i32* %Array) { +bb0: + %cond221 = icmp eq i32 0, %Num ; [#uses=3] + br i1 %cond221, label %bb7, label %bb2 +bb2: ; preds = %bb6, %bb0 + %reg115 = phi i32 [ %reg120, %bb6 ], [ 0, %bb0 ] ; [#uses=2] + br i1 %cond221, label %bb6, label %bb3 +bb3: ; preds = %bb5, %bb2 + %reg116 = phi i32 [ %reg119, %bb5 ], [ 0, %bb2 ] ; [#uses=2] + br i1 %cond221, label %bb5, label %bb4 +bb4: ; preds = %bb4, %bb3 + %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; [#uses=2] + %reg113 = add i32 %reg115, %reg117 ; [#uses=1] + %reg114 = add i32 %reg113, %reg116 ; [#uses=1] + %cast227 = getelementptr [4 x i8]* @.LC0, i64 0, i64 0 ; [#uses=1] + call i32 (i8*, ...)* @printf( i8* %cast227, i32 %reg114 ) ; :0 [#uses=0] + %reg118 = add i32 %reg117, 1 ; [#uses=2] + %cond224 = icmp ne i32 %reg118, %Num ; [#uses=1] + br i1 %cond224, label %bb4, label %bb5 +bb5: ; preds = %bb4, %bb3 + %reg119 = add i32 %reg116, 1 ; [#uses=2] + %cond225 = icmp ne i32 %reg119, %Num ; [#uses=1] + br i1 %cond225, label %bb3, label %bb6 +bb6: ; preds = %bb5, %bb2 + %reg120 = add i32 %reg115, 1 ; [#uses=2] + %cond226 = icmp ne i32 %reg120, %Num ; [#uses=1] + br i1 %cond226, label %bb2, label %bb7 +bb7: ; preds = %bb6, %bb0 + ret void +} diff --git a/test/Transforms/Reassociate/mul-factor3.ll b/test/Transforms/Reassociate/mul-factor3.ll new file mode 100644 index 000000000000..e45e431df545 --- /dev/null +++ b/test/Transforms/Reassociate/mul-factor3.ll @@ -0,0 +1,16 @@ +; This should be one add and two multiplies. + +; RUN: llvm-as < %s | \ +; RUN: opt -reassociate -instcombine | llvm-dis > %t +; RUN: grep mul %t | count 2 +; RUN: grep add %t | count 1 + +define i32 @test(i32 %A, i32 %B, i32 %C) { + %aa = mul i32 %A, %A ; [#uses=1] + %aab = mul i32 %aa, %B ; [#uses=1] + %ac = mul i32 %A, %C ; [#uses=1] + %aac = mul i32 %ac, %A ; [#uses=1] + %r = add i32 %aab, %aac ; [#uses=1] + ret i32 %r +} + diff --git a/test/Transforms/Reassociate/mul-neg-add.ll b/test/Transforms/Reassociate/mul-neg-add.ll new file mode 100644 index 000000000000..1899be79e112 --- /dev/null +++ b/test/Transforms/Reassociate/mul-neg-add.ll @@ -0,0 +1,10 @@ +; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis |\ +; RUN: not grep {sub i32 0} + +define i32 @test(i32 %X, i32 %Y, i32 %Z) { + %A = sub i32 0, %X ; [#uses=1] + %B = mul i32 %A, %Y ; [#uses=1] + ; (-X)*Y + Z -> Z-X*Y + %C = add i32 %B, %Z ; [#uses=1] + ret i32 %C +} diff --git a/test/Transforms/Reassociate/mulfactor.ll b/test/Transforms/Reassociate/mulfactor.ll new file mode 100644 index 000000000000..f80019c95e36 --- /dev/null +++ b/test/Transforms/Reassociate/mulfactor.ll @@ -0,0 +1,14 @@ +; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | grep mul | count 2 + +; This should have exactly 2 multiplies when we're done. + +define i32 @f(i32 %a, i32 %b) { + %tmp.2 = mul i32 %a, %a ; [#uses=1] + %tmp.5 = shl i32 %a, 1 ; [#uses=1] + %tmp.6 = mul i32 %tmp.5, %b ; [#uses=1] + %tmp.10 = mul i32 %b, %b ; [#uses=1] + %tmp.7 = add i32 %tmp.6, %tmp.2 ; [#uses=1] + %tmp.11 = add i32 %tmp.7, %tmp.10 ; [#uses=1] + ret i32 %tmp.11 +} + diff --git a/test/Transforms/Reassociate/mulfactor2.ll b/test/Transforms/Reassociate/mulfactor2.ll new file mode 100644 index 000000000000..62a890b90b68 --- /dev/null +++ b/test/Transforms/Reassociate/mulfactor2.ll @@ -0,0 +1,16 @@ +; This should turn into one multiply and one add. + +; RUN: llvm-as < %s | \ +; RUN: opt -instcombine -reassociate -instcombine | llvm-dis > %t +; RUN: grep mul %t | count 1 +; RUN: grep add %t | count 1 + +define i32 @main(i32 %t) { + %tmp.3 = mul i32 %t, 12 ; [#uses=1] + %tmp.4 = add i32 %tmp.3, 5 ; [#uses=1] + %tmp.6 = mul i32 %t, 6 ; [#uses=1] + %tmp.8 = mul i32 %tmp.4, 3 ; [#uses=1] + %tmp.9 = add i32 %tmp.8, %tmp.6 ; [#uses=1] + ret i32 %tmp.9 +} + diff --git a/test/Transforms/Reassociate/negation.ll b/test/Transforms/Reassociate/negation.ll new file mode 100644 index 000000000000..6b2041898a1d --- /dev/null +++ b/test/Transforms/Reassociate/negation.ll @@ -0,0 +1,21 @@ +; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | not grep sub + +; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z. + +define i32 @test1(i32 %a, i32 %b, i32 %z) { + %c = sub i32 0, %z ; [#uses=1] + %d = mul i32 %a, %b ; [#uses=1] + %e = mul i32 %c, %d ; [#uses=1] + %f = mul i32 %e, 12345 ; [#uses=1] + %g = sub i32 0, %f ; [#uses=1] + ret i32 %g +} + +define i32 @test2(i32 %a, i32 %b, i32 %z) { + %d = mul i32 %z, 40 ; [#uses=1] + %c = sub i32 0, %d ; [#uses=1] + %e = mul i32 %a, %c ; [#uses=1] + %f = sub i32 0, %e ; [#uses=1] + ret i32 %f +} + diff --git a/test/Transforms/Reassociate/otherops.ll b/test/Transforms/Reassociate/otherops.ll new file mode 100644 index 000000000000..3c9b0744a8fc --- /dev/null +++ b/test/Transforms/Reassociate/otherops.ll @@ -0,0 +1,28 @@ +; Reassociation should apply to Add, Mul, And, Or, & Xor +; +; RUN: llvm-as < %s | opt -reassociate -constprop -instcombine -die | llvm-dis | not grep 12 + +define i32 @test_mul(i32 %arg) { + %tmp1 = mul i32 12, %arg ; [#uses=1] + %tmp2 = mul i32 %tmp1, 12 ; [#uses=1] + ret i32 %tmp2 +} + +define i32 @test_and(i32 %arg) { + %tmp1 = and i32 14, %arg ; [#uses=1] + %tmp2 = and i32 %tmp1, 14 ; [#uses=1] + ret i32 %tmp2 +} + +define i32 @test_or(i32 %arg) { + %tmp1 = or i32 14, %arg ; [#uses=1] + %tmp2 = or i32 %tmp1, 14 ; [#uses=1] + ret i32 %tmp2 +} + +define i32 @test_xor(i32 %arg) { + %tmp1 = xor i32 12, %arg ; [#uses=1] + %tmp2 = xor i32 %tmp1, 12 ; [#uses=1] + ret i32 %tmp2 +} + diff --git a/test/Transforms/Reassociate/shift-factor.ll b/test/Transforms/Reassociate/shift-factor.ll new file mode 100644 index 000000000000..05437fd86639 --- /dev/null +++ b/test/Transforms/Reassociate/shift-factor.ll @@ -0,0 +1,13 @@ +; There should be exactly one shift and one add left. +; RUN: llvm-as < %s | \ +; RUN: opt -reassociate -instcombine | llvm-dis > %t +; RUN: grep shl %t | count 1 +; RUN: grep add %t | count 1 + +define i32 @test(i32 %X, i32 %Y) { + %tmp.2 = shl i32 %X, 1 ; [#uses=1] + %tmp.6 = shl i32 %Y, 1 ; [#uses=1] + %tmp.4 = add i32 %tmp.6, %tmp.2 ; [#uses=1] + ret i32 %tmp.4 +} + diff --git a/test/Transforms/Reassociate/shifttest.ll b/test/Transforms/Reassociate/shifttest.ll new file mode 100644 index 000000000000..fd49e7d3f223 --- /dev/null +++ b/test/Transforms/Reassociate/shifttest.ll @@ -0,0 +1,12 @@ +; With shl->mul reassociation, we can see that this is (shl A, 9) * A +; +; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis |\ +; RUN: grep {shl .*, 9} + +define i32 @test(i32 %A, i32 %B) { + %X = shl i32 %A, 5 ; [#uses=1] + %Y = shl i32 %A, 4 ; [#uses=1] + %Z = mul i32 %Y, %X ; [#uses=1] + ret i32 %Z +} + diff --git a/test/Transforms/Reassociate/subtest.ll b/test/Transforms/Reassociate/subtest.ll new file mode 100644 index 000000000000..513984e7722d --- /dev/null +++ b/test/Transforms/Reassociate/subtest.ll @@ -0,0 +1,11 @@ +; With sub reassociation, constant folding can eliminate the 12 and -12 constants. +; +; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | not grep 12 + +define i32 @test(i32 %A, i32 %B) { + %X = add i32 -12, %A ; [#uses=1] + %Y = sub i32 %X, %B ; [#uses=1] + %Z = add i32 %Y, 12 ; [#uses=1] + ret i32 %Z +} + diff --git a/test/Transforms/Reassociate/subtest2.ll b/test/Transforms/Reassociate/subtest2.ll new file mode 100644 index 000000000000..c81e9b38def9 --- /dev/null +++ b/test/Transforms/Reassociate/subtest2.ll @@ -0,0 +1,13 @@ +; With sub reassociation, constant folding can eliminate the uses of %a. +; +; RUN: llvm-as < %s | opt -reassociate -instcombine | llvm-dis | grep %a | count 1 +; PR2047 + +define i32 @test(i32 %a, i32 %b, i32 %c) nounwind { +entry: + %tmp3 = sub i32 %a, %b ; [#uses=1] + %tmp5 = sub i32 %tmp3, %c ; [#uses=1] + %tmp7 = sub i32 %tmp5, %a ; [#uses=1] + ret i32 %tmp7 +} + -- cgit v1.3