diff --git a/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll b/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll index 5780990c761..24300352a62 100644 --- a/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll +++ b/test/Transforms/Reassociate/2002-05-15-AgressiveSubMove.ll @@ -1,9 +1,10 @@ -; RUN: opt < %s -reassociate -instcombine -constprop -dce -S | not grep add +; RUN: opt < %s -reassociate -S | FileCheck %s -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 +define i32 @test1(i32 %A) { +; CHECK-LABEL: test1 +; CHECK: ret i32 0 + %X = add i32 %A, 1 + %Y = add i32 %A, 1 + %r = sub i32 %X, %Y + ret i32 %r } - diff --git a/test/Transforms/Reassociate/2002-05-15-MissedTree.ll b/test/Transforms/Reassociate/2002-05-15-MissedTree.ll index e8bccbde28e..5f3c9209aed 100644 --- a/test/Transforms/Reassociate/2002-05-15-MissedTree.ll +++ b/test/Transforms/Reassociate/2002-05-15-MissedTree.ll @@ -1,9 +1,11 @@ -; RUN: opt < %s -reassociate -instcombine -constprop -die -S | not grep 5 +; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s -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] +define i32 @test1(i32 %A, i32 %B) { +; CHECK-LABEL: test1 +; CHECK: %Z = add i32 %B, %A +; CHECK: ret i32 %Z + %W = add i32 %B, -5 + %Y = add i32 %A, 5 + %Z = add i32 %W, %Y ret i32 %Z } - diff --git a/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll b/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll index c18af5e07ef..29c178ffec3 100644 --- a/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll +++ b/test/Transforms/Reassociate/2002-05-15-SubReassociate.ll @@ -1,12 +1,30 @@ +; RUN: opt < %s -reassociate -constprop -instcombine -dce -S | FileCheck %s + ; With sub reassociation, constant folding can eliminate all of the constants. -; -; RUN: opt < %s -reassociate -constprop -instcombine -dce -S | not grep add +define i32 @test1(i32 %A, i32 %B) { +; CHECK-LABEL: test1 +; CHECK-NEXT: %Z = sub i32 %A, %B +; CHECK-NEXT: ret i32 %Z -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 + %W = add i32 5, %B + %X = add i32 -7, %A + %Y = sub i32 %X, %W + %Z = add i32 %Y, 12 + ret i32 %Z } + +; With sub reassociation, constant folding can eliminate the two 12 constants. +define i32 @test2(i32 %A, i32 %B, i32 %C, i32 %D) { +; CHECK-LABEL: test2 +; CHECK-NEXT: %sum = add i32 %B, %A +; CHECK-NEXT: %sum1 = add i32 %sum, %C +; CHECK-NEXT: %Q = sub i32 %D, %sum1 +; CHECK-NEXT: ret i32 %Q + %M = add i32 %A, 12 + %N = add i32 %M, %B + %O = add i32 %N, %C + %P = sub i32 %D, %O + %Q = add i32 %P, 12 + ret i32 %Q +} diff --git a/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll b/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll deleted file mode 100644 index 5848821e10f..00000000000 --- a/test/Transforms/Reassociate/2002-05-15-SubReassociate2.ll +++ /dev/null @@ -1,13 +0,0 @@ -; With sub reassociation, constant folding can eliminate the two 12 constants. -; -; RUN: opt < %s -reassociate -constprop -dce -S | 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/2005-09-01-ArrayOutOfBounds.ll b/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll index f66148bb4ab..f6cef35b177 100644 --- a/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll +++ b/test/Transforms/Reassociate/2005-09-01-ArrayOutOfBounds.ll @@ -1,23 +1,24 @@ -; RUN: opt < %s -reassociate -instcombine -S |\ -; RUN: grep "ret i32 0" +; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s -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 +define i32 @f1(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) { +; CHECK-LABEL: f1 +; CHECK-NEXT: ret i32 0 + + %tmp.2 = add i32 %a4, %a3 + %tmp.4 = add i32 %tmp.2, %a2 + %tmp.6 = add i32 %tmp.4, %a1 + %tmp.8 = add i32 %tmp.6, %a0 + %tmp.11 = add i32 %a3, %a2 + %tmp.13 = add i32 %tmp.11, %a1 + %tmp.15 = add i32 %tmp.13, %a0 + %tmp.18 = add i32 %a2, %a1 + %tmp.20 = add i32 %tmp.18, %a0 + %tmp.23 = add i32 %a1, %a0 + %tmp.26 = sub i32 %tmp.8, %tmp.15 + %tmp.28 = add i32 %tmp.26, %tmp.20 + %tmp.30 = sub i32 %tmp.28, %tmp.23 + %tmp.32 = sub i32 %tmp.30, %a4 + %tmp.34 = sub i32 %tmp.32, %a2 + %T = mul i32 %tmp.34, %tmp.34 + ret i32 %T } - diff --git a/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll b/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll index 384cbc90a74..f7839554002 100644 --- a/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll +++ b/test/Transforms/Reassociate/2006-04-27-ReassociateVector.ll @@ -1,8 +1,12 @@ -; RUN: opt < %s -reassociate -disable-output +; RUN: opt < %s -reassociate -S | FileCheck %s -define void @foo() { - %tmp162 = fsub <4 x float> zeroinitializer, zeroinitializer ; <<4 x float>> [#uses=1] - %tmp164 = fmul <4 x float> zeroinitializer, %tmp162 ; <<4 x float>> [#uses=0] - ret void +define <4 x float> @test1() { +; CHECK-LABEL: test1 +; CHECK-NEXT: %tmp1 = fsub <4 x float> zeroinitializer, zeroinitializer +; CHECK-NEXT: %tmp2 = fmul <4 x float> zeroinitializer, %tmp1 +; CHECK-NEXT: ret <4 x float> %tmp2 + + %tmp1 = fsub <4 x float> zeroinitializer, zeroinitializer + %tmp2 = fmul <4 x float> zeroinitializer, %tmp1 + ret <4 x float> %tmp2 } - diff --git a/test/Transforms/Reassociate/basictest.ll b/test/Transforms/Reassociate/basictest.ll index fda0ca6be1a..d70bfcbb72c 100644 --- a/test/Transforms/Reassociate/basictest.ll +++ b/test/Transforms/Reassociate/basictest.ll @@ -1,46 +1,47 @@ -; With reassociation, constant folding can eliminate the 12 and -12 constants. -; -; RUN: opt < %s -reassociate -gvn -instcombine -S | FileCheck %s +; RUN: opt < %s -reassociate -gvn -instcombine -S | FileCheck %s define i32 @test1(i32 %arg) { - %tmp1 = sub i32 -12, %arg - %tmp2 = add i32 %tmp1, 12 - ret i32 %tmp2 -; CHECK-LABEL: @test1( + %tmp1 = sub i32 -12, %arg + %tmp2 = add i32 %tmp1, 12 + ret i32 %tmp2 + +; CHECK-LABEL: @test1 ; CHECK-NEXT: sub i32 0, %arg ; CHECK-NEXT: ret i32 } define i32 @test2(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 -; CHECK-LABEL: @test2( -; CHECK-NEXT: add i32 %reg1111, %reg109 -; CHECK-NEXT: ret i32 + %reg115 = add i32 %reg109, -30 + %reg116 = add i32 %reg115, %reg1111 + %reg117 = add i32 %reg116, 30 + ret i32 %reg117 + +; CHECK-LABEL: @test2 +; CHECK-NEXT: %reg117 = add i32 %reg1111, %reg109 +; CHECK-NEXT: ret i32 %reg117 } -@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] +@e = external global i32 +@a = external global i32 +@b = external global i32 +@c = external global i32 +@f = external global i32 define void @test3() { - %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 -; CHECK-LABEL: @test3( + %A = load i32* @a + %B = load i32* @b + %C = load i32* @c + %t1 = add i32 %A, %B + %t2 = add i32 %t1, %C + %t3 = add i32 %C, %A + %t4 = add i32 %t3, %B + ; e = (a+b)+c; + store i32 %t2, i32* @e + ; f = (a+c)+b + store i32 %t4, i32* @f + ret void + +; CHECK-LABEL: @test3 ; CHECK: add i32 ; CHECK: add i32 ; CHECK-NOT: add i32 @@ -48,19 +49,20 @@ define void @test3() { } define void @test4() { - %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 -; CHECK-LABEL: @test4( + %A = load i32* @a + %B = load i32* @b + %C = load i32* @c + %t1 = add i32 %A, %B + %t2 = add i32 %t1, %C + %t3 = add i32 %C, %A + %t4 = add i32 %t3, %B + ; e = c+(a+b) + store i32 %t2, i32* @e + ; f = (c+a)+b + store i32 %t4, i32* @f + ret void + +; CHECK-LABEL: @test4 ; CHECK: add i32 ; CHECK: add i32 ; CHECK-NOT: add i32 @@ -68,19 +70,20 @@ define void @test4() { } define void @test5() { - %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 -; CHECK-LABEL: @test5( + %A = load i32* @a + %B = load i32* @b + %C = load i32* @c + %t1 = add i32 %B, %A + %t2 = add i32 %t1, %C + %t3 = add i32 %C, %A + %t4 = add i32 %t3, %B + ; e = c+(b+a) + store i32 %t2, i32* @e + ; f = (c+a)+b + store i32 %t4, i32* @f + ret void + +; CHECK-LABEL: @test5 ; CHECK: add i32 ; CHECK: add i32 ; CHECK-NOT: add i32 @@ -88,60 +91,61 @@ define void @test5() { } define i32 @test6() { - %tmp.0 = load i32* @a - %tmp.1 = load i32* @b - ; (a+b) - %tmp.2 = add i32 %tmp.0, %tmp.1 - %tmp.4 = load i32* @c - ; (a+b)+c - %tmp.5 = add i32 %tmp.2, %tmp.4 - ; (a+c) - %tmp.8 = add i32 %tmp.0, %tmp.4 - ; (a+c)+b - %tmp.11 = add i32 %tmp.8, %tmp.1 - ; X ^ X = 0 - %RV = xor i32 %tmp.5, %tmp.11 - ret i32 %RV -; CHECK-LABEL: @test6( + %tmp.0 = load i32* @a + %tmp.1 = load i32* @b + ; (a+b) + %tmp.2 = add i32 %tmp.0, %tmp.1 + %tmp.4 = load i32* @c + ; (a+b)+c + %tmp.5 = add i32 %tmp.2, %tmp.4 + ; (a+c) + %tmp.8 = add i32 %tmp.0, %tmp.4 + ; (a+c)+b + %tmp.11 = add i32 %tmp.8, %tmp.1 + ; X ^ X = 0 + %RV = xor i32 %tmp.5, %tmp.11 + ret i32 %RV + +; CHECK-LABEL: @test6 ; CHECK: ret i32 0 } ; This should be one add and two multiplies. define i32 @test7(i32 %A, i32 %B, i32 %C) { - ; A*A*B + A*C*A - %aa = mul i32 %A, %A - %aab = mul i32 %aa, %B - %ac = mul i32 %A, %C - %aac = mul i32 %ac, %A - %r = add i32 %aab, %aac - ret i32 %r -; CHECK-LABEL: @test7( + ; A*A*B + A*C*A + %aa = mul i32 %A, %A + %aab = mul i32 %aa, %B + %ac = mul i32 %A, %C + %aac = mul i32 %ac, %A + %r = add i32 %aab, %aac + ret i32 %r + +; CHECK-LABEL: @test7 ; CHECK-NEXT: add i32 %C, %B ; CHECK-NEXT: mul i32 ; CHECK-NEXT: mul i32 ; CHECK-NEXT: ret i32 } - define i32 @test8(i32 %X, i32 %Y, i32 %Z) { - %A = sub i32 0, %X - %B = mul i32 %A, %Y - ; (-X)*Y + Z -> Z-X*Y - %C = add i32 %B, %Z - ret i32 %C -; CHECK-LABEL: @test8( + %A = sub i32 0, %X + %B = mul i32 %A, %Y + ; (-X)*Y + Z -> Z-X*Y + %C = add i32 %B, %Z + ret i32 %C + +; CHECK-LABEL: @test8 ; CHECK-NEXT: %A = mul i32 %Y, %X ; CHECK-NEXT: %C = sub i32 %Z, %A ; CHECK-NEXT: ret i32 %C } - ; PR5458 define i32 @test9(i32 %X) { %Y = mul i32 %X, 47 %Z = add i32 %Y, %Y ret i32 %Z -; CHECK-LABEL: @test9( +; CHECK-LABEL: @test9 ; CHECK-NEXT: mul i32 %X, 94 ; CHECK-NEXT: ret i32 } @@ -150,7 +154,7 @@ define i32 @test10(i32 %X) { %Y = add i32 %X ,%X %Z = add i32 %Y, %X ret i32 %Z -; CHECK-LABEL: @test10( +; CHECK-LABEL: @test10 ; CHECK-NEXT: mul i32 %X, 3 ; CHECK-NEXT: ret i32 } @@ -160,7 +164,7 @@ define i32 @test11(i32 %W) { %Y = add i32 %X ,%X %Z = add i32 %Y, %X ret i32 %Z -; CHECK-LABEL: @test11( +; CHECK-LABEL: @test11 ; CHECK-NEXT: mul i32 %W, 381 ; CHECK-NEXT: ret i32 } @@ -169,11 +173,10 @@ define i32 @test12(i32 %X) { %A = sub i32 1, %X %B = sub i32 2, %X %C = sub i32 3, %X - %Y = add i32 %A ,%B %Z = add i32 %Y, %C ret i32 %Z -; CHECK-LABEL: @test12( +; CHECK-LABEL: @test12 ; CHECK-NEXT: mul i32 %X, -3 ; CHECK-NEXT: add i32{{.*}}, 6 ; CHECK-NEXT: ret i32 @@ -185,7 +188,7 @@ define i32 @test13(i32 %X1, i32 %X2, i32 %X3) { %C = mul i32 %X1, %X3 ; X1*X3 %D = add i32 %B, %C ; -X1*X2 + X1*X3 -> X1*(X3-X2) ret i32 %D -; CHECK-LABEL: @test13( +; CHECK-LABEL: @test13 ; CHECK-NEXT: sub i32 %X3, %X2 ; CHECK-NEXT: mul i32 {{.*}}, %X1 ; CHECK-NEXT: ret i32 @@ -197,9 +200,10 @@ define i32 @test14(i32 %X1, i32 %X2) { %C = mul i32 %X2, -47 ; X2*-47 %D = add i32 %B, %C ; X1*47 + X2*-47 -> 47*(X1-X2) ret i32 %D -; CHECK-LABEL: @test14( + +; CHECK-LABEL: @test14 ; CHECK-NEXT: sub i32 %X1, %X2 -; CHECK-NEXT: mul i32 {{.*}}, 47 +; CHECK-NEXT: mul i32 %tmp, 47 ; CHECK-NEXT: ret i32 } @@ -210,7 +214,6 @@ define i32 @test15(i32 %X1, i32 %X2, i32 %X3) { %C = and i1 %A, %B %D = select i1 %C, i32 %X1, i32 0 ret i32 %D -; CHECK-LABEL: @test15( +; CHECK-LABEL: @test15 ; CHECK: and i1 %A, %B } - diff --git a/test/Transforms/Reassociate/fp-commute.ll b/test/Transforms/Reassociate/fp-commute.ll index 025689bb0c1..eac5b5920ac 100644 --- a/test/Transforms/Reassociate/fp-commute.ll +++ b/test/Transforms/Reassociate/fp-commute.ll @@ -1,18 +1,19 @@ ; RUN: opt -reassociate -S < %s | FileCheck %s -target triple = "armv7-apple-ios" - declare void @use(float) -; CHECK: test -define void @test(float %x, float %y) { -entry: +define void @test1(float %x, float %y) { +; CHECK-LABEL: test1 ; CHECK: fmul float %x, %y ; CHECK: fmul float %x, %y - %0 = fmul float %x, %y - %1 = fmul float %y, %x - %2 = fsub float %0, %1 - call void @use(float %0) - call void @use(float %2) +; CHECK: fsub float %1, %2 +; CHECK: call void @use(float %{{.*}}) +; CHECK: call void @use(float %{{.*}}) + + %1 = fmul float %x, %y + %2 = fmul float %y, %x + %3 = fsub float %1, %2 + call void @use(float %1) + call void @use(float %3) ret void } diff --git a/test/Transforms/Reassociate/looptest.ll b/test/Transforms/Reassociate/looptest.ll index 91723bc37b0..aad3b206f69 100644 --- a/test/Transforms/Reassociate/looptest.ll +++ b/test/Transforms/Reassociate/looptest.ll @@ -18,6 +18,7 @@ declare i32 @printf(i8*, ...) +; FIXME: No longer works. define void @test(i32 %Num, i32* %Array) { bb0: %cond221 = icmp eq i32 0, %Num ; [#uses=3] diff --git a/test/Transforms/Reassociate/mightymul.ll b/test/Transforms/Reassociate/mightymul.ll index cfbc485ffa0..ae915da8e57 100644 --- a/test/Transforms/Reassociate/mightymul.ll +++ b/test/Transforms/Reassociate/mightymul.ll @@ -1,7 +1,7 @@ -; RUN: opt < %s -reassociate +; RUN: opt < %s -reassociate -disable-output ; PR13021 -define i32 @foo(i32 %x) { +define i32 @test1(i32 %x) { %t0 = mul i32 %x, %x %t1 = mul i32 %t0, %t0 %t2 = mul i32 %t1, %t1 diff --git a/test/Transforms/Reassociate/multistep.ll b/test/Transforms/Reassociate/multistep.ll index d79464753f1..12eaeeea7b7 100644 --- a/test/Transforms/Reassociate/multistep.ll +++ b/test/Transforms/Reassociate/multistep.ll @@ -28,4 +28,3 @@ define i64 @multistep2(i64 %a, i64 %b, i64 %c, i64 %d) { ; CHECK-NEXT: ret ret i64 %t3 } - diff --git a/test/Transforms/Reassociate/negation.ll b/test/Transforms/Reassociate/negation.ll index 6a3dfd3b820..12d2c86192b 100644 --- a/test/Transforms/Reassociate/negation.ll +++ b/test/Transforms/Reassociate/negation.ll @@ -1,21 +1,31 @@ -; RUN: opt < %s -reassociate -instcombine -S | not grep sub +; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s ; 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 +; CHECK-LABEL: test1 +; CHECK-NEXT: %e = mul i32 %a, 12345 +; CHECK-NEXT: %f = mul i32 %e, %b +; CHECK-NEXT: %g = mul i32 %f, %z +; CHECK-NEXT: ret i32 %g + + %c = sub i32 0, %z + %d = mul i32 %a, %b + %e = mul i32 %c, %d + %f = mul i32 %e, 12345 + %g = sub i32 0, %f + 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 -} +; CHECK-LABEL: test2 +; CHECK-NEXT: %e = mul i32 %a, 40 +; CHECK-NEXT: %f = mul i32 %e, %z +; CHECK-NEXT: ret i32 %f + %d = mul i32 %z, 40 + %c = sub i32 0, %d + %e = mul i32 %a, %c + %f = sub i32 0, %e + ret i32 %f +} diff --git a/test/Transforms/Reassociate/otherops.ll b/test/Transforms/Reassociate/otherops.ll index d68d00818cb..7718881d8e5 100644 --- a/test/Transforms/Reassociate/otherops.ll +++ b/test/Transforms/Reassociate/otherops.ll @@ -1,28 +1,42 @@ ; Reassociation should apply to Add, Mul, And, Or, & Xor ; -; RUN: opt < %s -reassociate -constprop -instcombine -die -S | not grep 12 +; RUN: opt < %s -reassociate -constprop -instcombine -die -S | FileCheck %s define i32 @test_mul(i32 %arg) { - %tmp1 = mul i32 12, %arg ; [#uses=1] - %tmp2 = mul i32 %tmp1, 12 ; [#uses=1] - ret i32 %tmp2 +; CHECK-LABEL: test_mul +; CHECK-NEXT: %tmp2 = mul i32 %arg, 144 +; CHECK-NEXT: ret i32 %tmp2 + + %tmp1 = mul i32 12, %arg + %tmp2 = mul i32 %tmp1, 12 + 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 +; CHECK-LABEL: test_and +; CHECK-NEXT: %tmp2 = and i32 %arg, 14 +; CHECK-NEXT: ret i32 %tmp2 + + %tmp1 = and i32 14, %arg + %tmp2 = and i32 %tmp1, 14 + 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 +; CHECK-LABEL: test_or +; CHECK-NEXT: %tmp2 = or i32 %arg, 14 +; CHECK-NEXT: ret i32 %tmp2 + + %tmp1 = or i32 14, %arg + %tmp2 = or i32 %tmp1, 14 + 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 -} +; CHECK-LABEL: test_xor +; CHECK-NEXT: ret i32 %arg + %tmp1 = xor i32 12, %arg + %tmp2 = xor i32 %tmp1, 12 + ret i32 %tmp2 +} diff --git a/test/Transforms/Reassociate/shift-factor.ll b/test/Transforms/Reassociate/shift-factor.ll index 73af5e5304e..8fbf1b9d4bc 100644 --- a/test/Transforms/Reassociate/shift-factor.ll +++ b/test/Transforms/Reassociate/shift-factor.ll @@ -1,12 +1,14 @@ ; There should be exactly one shift and one add left. -; RUN: opt < %s -reassociate -instcombine -S > %t -; RUN: grep shl %t | count 1 -; RUN: grep add %t | count 1 +; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s -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 +define i32 @test1(i32 %X, i32 %Y) { +; CHECK-LABEL: test1 +; CHECK-NEXT: %tmp = add i32 %Y, %X +; CHECK-NEXT: %tmp1 = shl i32 %tmp, 1 +; CHECK-NEXT: ret i32 %tmp1 + + %tmp.2 = shl i32 %X, 1 + %tmp.6 = shl i32 %Y, 1 + %tmp.4 = add i32 %tmp.6, %tmp.2 + ret i32 %tmp.4 } - diff --git a/test/Transforms/Reassociate/subtest.ll b/test/Transforms/Reassociate/subtest.ll index 4c63d1238a6..e6263d85522 100644 --- a/test/Transforms/Reassociate/subtest.ll +++ b/test/Transforms/Reassociate/subtest.ll @@ -1,11 +1,26 @@ -; With sub reassociation, constant folding can eliminate the 12 and -12 constants. -; -; RUN: opt < %s -reassociate -instcombine -S | not grep 12 +; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s -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 +; With sub reassociation, constant folding can eliminate the 12 and -12 constants. +define i32 @test1(i32 %A, i32 %B) { +; CHECK-LABEL: @test1 +; CHECK-NEXT: %Z = sub i32 %A, %B +; CHECK-NEXT: ret i32 %Z + %X = add i32 -12, %A + %Y = sub i32 %X, %B + %Z = add i32 %Y, 12 + ret i32 %Z } +; PR2047 +; With sub reassociation, constant folding can eliminate the uses of %a. +define i32 @test2(i32 %a, i32 %b, i32 %c) nounwind { +; CHECK-LABEL: @test2 +; CHECK-NEXT: %sum = add i32 %c, %b +; CHECK-NEXT: %tmp7 = sub i32 0, %sum +; CHECK-NEXT: ret i32 %tmp7 + + %tmp3 = sub i32 %a, %b + %tmp5 = sub i32 %tmp3, %c + %tmp7 = sub i32 %tmp5, %a + ret i32 %tmp7 +} diff --git a/test/Transforms/Reassociate/subtest2.ll b/test/Transforms/Reassociate/subtest2.ll deleted file mode 100644 index 0513c5fc1b6..00000000000 --- a/test/Transforms/Reassociate/subtest2.ll +++ /dev/null @@ -1,13 +0,0 @@ -; With sub reassociation, constant folding can eliminate the uses of %a. -; -; RUN: opt < %s -reassociate -instcombine -S | 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 -} -