diff options
Diffstat (limited to 'test/Transforms/Reassociate')
-rw-r--r-- | test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll | 4 | ||||
-rw-r--r-- | test/Transforms/Reassociate/basictest.ll | 24 | ||||
-rw-r--r-- | test/Transforms/Reassociate/crash.ll | 6 | ||||
-rw-r--r-- | test/Transforms/Reassociate/fast-ReassociateVector.ll | 232 | ||||
-rw-r--r-- | test/Transforms/Reassociate/fast-basictest.ll | 18 | ||||
-rw-r--r-- | test/Transforms/Reassociate/looptest.ll | 2 | ||||
-rw-r--r-- | test/Transforms/Reassociate/pr12245.ll | 20 | ||||
-rw-r--r-- | test/Transforms/Reassociate/pr21205.ll | 2 |
8 files changed, 227 insertions, 81 deletions
diff --git a/test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll b/test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll index 003fbb1..1c8f0d2 100644 --- a/test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll +++ b/test/Transforms/Reassociate/2011-01-26-UseAfterFree.ll @@ -5,7 +5,7 @@ target triple = "i386-gnu-linux" define void @exp_averages_intraday__deviation() { entry: - %0 = load i32* undef, align 4 + %0 = load i32, i32* undef, align 4 %1 = shl i32 %0, 2 %2 = add nsw i32 undef, %1 %3 = add nsw i32 %2, undef @@ -22,7 +22,7 @@ entry: unreachable "8": ; preds = %"4" - %8 = getelementptr inbounds i8* undef, i32 %6 + %8 = getelementptr inbounds i8, i8* undef, i32 %6 br i1 undef, label %"13", label %"12" "12": ; preds = %"8", %entry diff --git a/test/Transforms/Reassociate/basictest.ll b/test/Transforms/Reassociate/basictest.ll index 0194ce2..015d3b0 100644 --- a/test/Transforms/Reassociate/basictest.ll +++ b/test/Transforms/Reassociate/basictest.ll @@ -28,9 +28,9 @@ define i32 @test2(i32 %reg109, i32 %reg1111) { @f = external global i32 define void @test3() { - %A = load i32* @a - %B = load i32* @b - %C = load i32* @c + %A = load i32, i32* @a + %B = load i32, i32* @b + %C = load i32, i32* @c %t1 = add i32 %A, %B %t2 = add i32 %t1, %C %t3 = add i32 %C, %A @@ -49,9 +49,9 @@ define void @test3() { } define void @test4() { - %A = load i32* @a - %B = load i32* @b - %C = load i32* @c + %A = load i32, i32* @a + %B = load i32, i32* @b + %C = load i32, i32* @c %t1 = add i32 %A, %B %t2 = add i32 %t1, %C %t3 = add i32 %C, %A @@ -70,9 +70,9 @@ define void @test4() { } define void @test5() { - %A = load i32* @a - %B = load i32* @b - %C = load i32* @c + %A = load i32, i32* @a + %B = load i32, i32* @b + %C = load i32, i32* @c %t1 = add i32 %B, %A %t2 = add i32 %t1, %C %t3 = add i32 %C, %A @@ -91,11 +91,11 @@ define void @test5() { } define i32 @test6() { - %tmp.0 = load i32* @a - %tmp.1 = load i32* @b + %tmp.0 = load i32, i32* @a + %tmp.1 = load i32, i32* @b ; (a+b) %tmp.2 = add i32 %tmp.0, %tmp.1 - %tmp.4 = load i32* @c + %tmp.4 = load i32, i32* @c ; (a+b)+c %tmp.5 = add i32 %tmp.2, %tmp.4 ; (a+c) diff --git a/test/Transforms/Reassociate/crash.ll b/test/Transforms/Reassociate/crash.ll index 770f973..f8774ea 100644 --- a/test/Transforms/Reassociate/crash.ll +++ b/test/Transforms/Reassociate/crash.ll @@ -17,7 +17,7 @@ for.cond: ; preds = %for.body, %entry ; PR5981 define i32 @test2() nounwind ssp { entry: - %0 = load i32* undef, align 4 + %0 = load i32, i32* undef, align 4 %1 = mul nsw i32 undef, %0 %2 = mul nsw i32 undef, %0 %3 = add nsw i32 undef, %1 @@ -50,7 +50,7 @@ _: br label %_33 _33: ; preds = %_33, %_ - %tmp348 = load i8* %arg, align 1 + %tmp348 = load i8, i8* %arg, align 1 %tmp349 = lshr i8 %tmp348, 7 %tmp350 = or i8 %tmp349, 42 %tmp351 = add i8 %tmp350, -42 @@ -123,7 +123,7 @@ for.cond: ; preds = %for.cond, %entry ; PR12963 @a = external global i8 define i8 @f0(i8 %x) { - %t0 = load i8* @a + %t0 = load i8, i8* @a %t1 = mul i8 %x, %x %t2 = mul i8 %t1, %t1 %t3 = mul i8 %t2, %t2 diff --git a/test/Transforms/Reassociate/fast-ReassociateVector.ll b/test/Transforms/Reassociate/fast-ReassociateVector.ll index eeae096..9fbb5cc 100644 --- a/test/Transforms/Reassociate/fast-ReassociateVector.ll +++ b/test/Transforms/Reassociate/fast-ReassociateVector.ll @@ -1,46 +1,192 @@ ; RUN: opt < %s -reassociate -S | FileCheck %s -; Canonicalize operands, but don't optimize floating point vector operations. -define <4 x float> @test1() { -; CHECK-LABEL: test1 -; CHECK-NEXT: %tmp1 = fsub fast <4 x float> zeroinitializer, zeroinitializer -; CHECK-NEXT: %tmp2 = fmul fast <4 x float> %tmp1, zeroinitializer - - %tmp1 = fsub fast <4 x float> zeroinitializer, zeroinitializer - %tmp2 = fmul fast <4 x float> zeroinitializer, %tmp1 - ret <4 x float> %tmp2 -} - -; Commute integer vector operations. -define <2 x i32> @test2(<2 x i32> %x, <2 x i32> %y) { -; CHECK-LABEL: test2 -; CHECK-NEXT: %tmp1 = add <2 x i32> %x, %y -; CHECK-NEXT: %tmp2 = add <2 x i32> %x, %y -; CHECK-NEXT: %tmp3 = add <2 x i32> %tmp1, %tmp2 - - %tmp1 = add <2 x i32> %x, %y - %tmp2 = add <2 x i32> %y, %x - %tmp3 = add <2 x i32> %tmp1, %tmp2 - ret <2 x i32> %tmp3 +; Check that a*c+b*c is turned into (a+b)*c +define <4 x float> @test1(<4 x float> %a, <4 x float> %b, <4 x float> %c) { +; CHECK-LABEL: @test1 +; CHECK-NEXT: %tmp = fadd fast <4 x float> %b, %a +; CHECK-NEXT: %tmp1 = fmul fast <4 x float> %tmp, %c +; CHECK-NEXT: ret <4 x float> %tmp1 + + %mul = fmul fast <4 x float> %a, %c + %mul1 = fmul fast <4 x float> %b, %c + %add = fadd fast <4 x float> %mul, %mul1 + ret <4 x float> %add } -define <2 x i32> @test3(<2 x i32> %x, <2 x i32> %y) { -; CHECK-LABEL: test3 -; CHECK-NEXT: %tmp1 = mul <2 x i32> %x, %y -; CHECK-NEXT: %tmp2 = mul <2 x i32> %x, %y -; CHECK-NEXT: %tmp3 = mul <2 x i32> %tmp1, %tmp2 +; Check that a*a*b+a*a*c is turned into a*(a*(b+c)). +define <2 x float> @test2(<2 x float> %a, <2 x float> %b, <2 x float> %c) { +; CHECK-LABEL: @test2 +; CHECK-NEXT: fadd fast <2 x float> %c, %b +; CHECK-NEXT: fmul fast <2 x float> %a, %tmp2 +; CHECK-NEXT: fmul fast <2 x float> %tmp3, %a +; CHECK-NEXT: ret <2 x float> - %tmp1 = mul <2 x i32> %x, %y - %tmp2 = mul <2 x i32> %y, %x - %tmp3 = mul <2 x i32> %tmp1, %tmp2 - ret <2 x i32> %tmp3 + %t0 = fmul fast <2 x float> %a, %b + %t1 = fmul fast <2 x float> %a, %t0 + %t2 = fmul fast <2 x float> %a, %c + %t3 = fmul fast <2 x float> %a, %t2 + %t4 = fadd fast <2 x float> %t1, %t3 + ret <2 x float> %t4 +} + +; Check that a*b+a*c+d is turned into a*(b+c)+d. +define <2 x double> @test3(<2 x double> %a, <2 x double> %b, <2 x double> %c, <2 x double> %d) { +; CHECK-LABEL: @test3 +; CHECK-NEXT: fadd fast <2 x double> %c, %b +; CHECK-NEXT: fmul fast <2 x double> %tmp, %a +; CHECK-NEXT: fadd fast <2 x double> %tmp1, %d +; CHECK-NEXT: ret <2 x double> + + %t0 = fmul fast <2 x double> %a, %b + %t1 = fmul fast <2 x double> %a, %c + %t2 = fadd fast <2 x double> %t1, %d + %t3 = fadd fast <2 x double> %t0, %t2 + ret <2 x double> %t3 +} + +; No fast-math. +define <2 x float> @test4(<2 x float> %A) { +; CHECK-LABEL: @test4 +; CHECK-NEXT: %X = fadd <2 x float> %A, <float 1.000000e+00, float 1.000000e+00> +; CHECK-NEXT: %Y = fadd <2 x float> %A, <float 1.000000e+00, float 1.000000e+00> +; CHECK-NEXT: %R = fsub <2 x float> %X, %Y +; CHECK-NEXT: ret <2 x float> %R + + %X = fadd <2 x float> %A, < float 1.000000e+00, float 1.000000e+00 > + %Y = fadd <2 x float> %A, < float 1.000000e+00, float 1.000000e+00 > + %R = fsub <2 x float> %X, %Y + ret <2 x float> %R +} + +; Check 47*X + 47*X -> 94*X. +define <2 x float> @test5(<2 x float> %X) { +; CHECK-LABEL: @test5 +; CHECK-NEXT: fmul fast <2 x float> %X, <float 9.400000e+01, float 9.400000e+01> +; CHECK-NEXT: ret <2 x float> + + %Y = fmul fast <2 x float> %X, <float 4.700000e+01, float 4.700000e+01> + %Z = fadd fast <2 x float> %Y, %Y + ret <2 x float> %Z +} + +; Check X+X+X -> 3*X. +define <2 x float> @test6(<2 x float> %X) { +; CHECK-LABEL: @test6 +; CHECK-NEXT: fmul fast <2 x float> %X, <float 3.000000e+00, float 3.000000e+00> +; CHECK-NEXT: ret <2 x float> + + %Y = fadd fast <2 x float> %X ,%X + %Z = fadd fast <2 x float> %Y, %X + ret <2 x float> %Z +} + +; Check 127*W+50*W -> 177*W. +define <2 x double> @test7(<2 x double> %W) { +; CHECK-LABEL: @test7 +; CHECK-NEXT: fmul fast <2 x double> %W, <double 1.770000e+02, double 1.770000e+02> +; CHECK-NEXT: ret <2 x double> + + %X = fmul fast <2 x double> %W, <double 127.0, double 127.0> + %Y = fmul fast <2 x double> %W, <double 50.0, double 50.0> + %Z = fadd fast <2 x double> %Y, %X + ret <2 x double> %Z +} + +; Check X*12*12 -> X*144. +define <2 x float> @test8(<2 x float> %arg) { +; CHECK-LABEL: @test8 +; CHECK: fmul fast <2 x float> %arg, <float 1.440000e+02, float 1.440000e+02> +; CHECK-NEXT: ret <2 x float> %tmp2 + + %tmp1 = fmul fast <2 x float> <float 1.200000e+01, float 1.200000e+01>, %arg + %tmp2 = fmul fast <2 x float> %tmp1, <float 1.200000e+01, float 1.200000e+01> + ret <2 x float> %tmp2 +} + +; Check (b+(a+1234))+-a -> b+1234. +define <2 x double> @test9(<2 x double> %b, <2 x double> %a) { +; CHECK-LABEL: @test9 +; CHECK: fadd fast <2 x double> %b, <double 1.234000e+03, double 1.234000e+03> +; CHECK-NEXT: ret <2 x double> + + %1 = fadd fast <2 x double> %a, <double 1.234000e+03, double 1.234000e+03> + %2 = fadd fast <2 x double> %b, %1 + %3 = fsub fast <2 x double> <double 0.000000e+00, double 0.000000e+00>, %a + %4 = fadd fast <2 x double> %2, %3 + ret <2 x double> %4 +} + +; Check -(-(z*40)*a) -> a*40*z. +define <2 x float> @test10(<2 x float> %a, <2 x float> %b, <2 x float> %z) { +; CHECK-LABEL: @test10 +; CHECK: fmul fast <2 x float> %a, <float 4.000000e+01, float 4.000000e+01> +; CHECK-NEXT: fmul fast <2 x float> %e, %z +; CHECK-NEXT: ret <2 x float> + + %d = fmul fast <2 x float> %z, <float 4.000000e+01, float 4.000000e+01> + %c = fsub fast <2 x float> <float 0.000000e+00, float 0.000000e+00>, %d + %e = fmul fast <2 x float> %a, %c + %f = fsub fast <2 x float> <float 0.000000e+00, float 0.000000e+00>, %e + ret <2 x float> %f +} + +; Check x*y+y*x -> x*y*2. +define <2 x double> @test11(<2 x double> %x, <2 x double> %y) { +; CHECK-LABEL: @test11 +; CHECK-NEXT: %factor = fmul fast <2 x double> %y, <double 2.000000e+00, double 2.000000e+00> +; CHECK-NEXT: %tmp1 = fmul fast <2 x double> %factor, %x +; CHECK-NEXT: ret <2 x double> %tmp1 + + %1 = fmul fast <2 x double> %x, %y + %2 = fmul fast <2 x double> %y, %x + %3 = fadd fast <2 x double> %1, %2 + ret <2 x double> %3 +} + +; FIXME: shifts should be converted to mul to assist further reassociation. +define <2 x i64> @test12(<2 x i64> %b, <2 x i64> %c) { +; CHECK-LABEL: @test12 +; CHECK-NEXT: %mul = mul <2 x i64> %c, %b +; CHECK-NEXT: %shl = shl <2 x i64> %mul, <i64 5, i64 5> +; CHECK-NEXT: ret <2 x i64> %shl + + %mul = mul <2 x i64> %c, %b + %shl = shl <2 x i64> %mul, <i64 5, i64 5> + ret <2 x i64> %shl +} + +; FIXME: expressions with a negative const should be canonicalized to assist +; further reassociation. +; We would expect (-5*b)+a -> a-(5*b) but only the constant operand is commuted. +define <4 x float> @test13(<4 x float> %a, <4 x float> %b) { +; CHECK-LABEL: @test13 +; CHECK-NEXT: %mul = fmul fast <4 x float> %b, <float -5.000000e+00, float -5.000000e+00, float -5.000000e+00, float -5.000000e+00> +; CHECK-NEXT: %add = fadd fast <4 x float> %mul, %a +; CHECK-NEXT: ret <4 x float> %add + + %mul = fmul fast <4 x float> <float -5.000000e+00, float -5.000000e+00, float -5.000000e+00, float -5.000000e+00>, %b + %add = fadd fast <4 x float> %mul, %a + ret <4 x float> %add +} + +; Break up subtract to assist further reassociation. +; Check a+b-c -> a+b+-c. +define <2 x i64> @test14(<2 x i64> %a, <2 x i64> %b, <2 x i64> %c) { +; CHECK-LABEL: @test14 +; CHECK-NEXT: %add = add <2 x i64> %b, %a +; CHECK-NEXT: %c.neg = sub <2 x i64> zeroinitializer, %c +; CHECK-NEXT: %sub = add <2 x i64> %add, %c.neg +; CHECK-NEXT: ret <2 x i64> %sub + + %add = add <2 x i64> %b, %a + %sub = sub <2 x i64> %add, %c + ret <2 x i64> %sub } -define <2 x i32> @test4(<2 x i32> %x, <2 x i32> %y) { -; CHECK-LABEL: test4 -; CHECK-NEXT: %tmp1 = and <2 x i32> %x, %y -; CHECK-NEXT: %tmp2 = and <2 x i32> %x, %y -; CHECK-NEXT: %tmp3 = and <2 x i32> %tmp1, %tmp2 +define <2 x i32> @test15(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: test15 +; CHECK-NEXT: %tmp3 = and <2 x i32> %y, %x +; CHECK-NEXT: ret <2 x i32> %tmp3 %tmp1 = and <2 x i32> %x, %y %tmp2 = and <2 x i32> %y, %x @@ -48,11 +194,10 @@ define <2 x i32> @test4(<2 x i32> %x, <2 x i32> %y) { ret <2 x i32> %tmp3 } -define <2 x i32> @test5(<2 x i32> %x, <2 x i32> %y) { -; CHECK-LABEL: test5 -; CHECK-NEXT: %tmp1 = or <2 x i32> %x, %y -; CHECK-NEXT: %tmp2 = or <2 x i32> %x, %y -; CHECK-NEXT: %tmp3 = or <2 x i32> %tmp1, %tmp2 +define <2 x i32> @test16(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: test16 +; CHECK-NEXT: %tmp3 = or <2 x i32> %y, %x +; CHECK-NEXT: ret <2 x i32> %tmp3 %tmp1 = or <2 x i32> %x, %y %tmp2 = or <2 x i32> %y, %x @@ -60,8 +205,9 @@ define <2 x i32> @test5(<2 x i32> %x, <2 x i32> %y) { ret <2 x i32> %tmp3 } -define <2 x i32> @test6(<2 x i32> %x, <2 x i32> %y) { -; CHECK-LABEL: test6 +; FIXME: Optimize vector xor. Currently only commute operands. +define <2 x i32> @test17(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: test17 ; CHECK-NEXT: %tmp1 = xor <2 x i32> %x, %y ; CHECK-NEXT: %tmp2 = xor <2 x i32> %x, %y ; CHECK-NEXT: %tmp3 = xor <2 x i32> %tmp1, %tmp2 diff --git a/test/Transforms/Reassociate/fast-basictest.ll b/test/Transforms/Reassociate/fast-basictest.ll index 67b07f4..64b74e3 100644 --- a/test/Transforms/Reassociate/fast-basictest.ll +++ b/test/Transforms/Reassociate/fast-basictest.ll @@ -48,9 +48,9 @@ define void @test4() { ; CHECK-NOT: fadd fast float ; CHECK: ret void - %A = load float* @fa - %B = load float* @fb - %C = load float* @fc + %A = load float, float* @fa + %B = load float, float* @fb + %C = load float, float* @fc %t1 = fadd fast float %A, %B %t2 = fadd fast float %t1, %C %t3 = fadd fast float %C, %A @@ -69,9 +69,9 @@ define void @test5() { ; CHECK-NOT: fadd ; CHECK: ret void - %A = load float* @fa - %B = load float* @fb - %C = load float* @fc + %A = load float, float* @fa + %B = load float, float* @fb + %C = load float, float* @fc %t1 = fadd fast float %A, %B %t2 = fadd fast float %t1, %C %t3 = fadd fast float %C, %A @@ -90,9 +90,9 @@ define void @test6() { ; CHECK-NOT: fadd ; CHECK: ret void - %A = load float* @fa - %B = load float* @fb - %C = load float* @fc + %A = load float, float* @fa + %B = load float, float* @fb + %C = load float, float* @fc %t1 = fadd fast float %B, %A %t2 = fadd fast float %t1, %C %t3 = fadd fast float %C, %A diff --git a/test/Transforms/Reassociate/looptest.ll b/test/Transforms/Reassociate/looptest.ll index aad3b20..8b6a409 100644 --- a/test/Transforms/Reassociate/looptest.ll +++ b/test/Transforms/Reassociate/looptest.ll @@ -33,7 +33,7 @@ bb4: ; preds = %bb4, %bb3 %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; <i32> [#uses=2] %reg113 = add i32 %reg115, %reg117 ; <i32> [#uses=1] %reg114 = add i32 %reg113, %reg116 ; <i32> [#uses=1] - %cast227 = getelementptr [4 x i8]* @.LC0, i64 0, i64 0 ; <i8*> [#uses=1] + %cast227 = getelementptr [4 x i8], [4 x i8]* @.LC0, i64 0, i64 0 ; <i8*> [#uses=1] call i32 (i8*, ...)* @printf( i8* %cast227, i32 %reg114 ) ; <i32>:0 [#uses=0] %reg118 = add i32 %reg117, 1 ; <i32> [#uses=2] %cond224 = icmp ne i32 %reg118, %Num ; <i1> [#uses=1] diff --git a/test/Transforms/Reassociate/pr12245.ll b/test/Transforms/Reassociate/pr12245.ll index e9b5355..0e7152e 100644 --- a/test/Transforms/Reassociate/pr12245.ll +++ b/test/Transforms/Reassociate/pr12245.ll @@ -6,34 +6,34 @@ define i32 @fn2() nounwind uwtable ssp { entry: - %0 = load i32* @a, align 4 + %0 = load i32, i32* @a, align 4 %dec = add nsw i32 %0, -1 store i32 %dec, i32* @a, align 4 - %1 = load i32* @d, align 4 + %1 = load i32, i32* @d, align 4 %sub = sub nsw i32 %dec, %1 store i32 %sub, i32* @d, align 4 - %2 = load i32* @a, align 4 + %2 = load i32, i32* @a, align 4 %dec1 = add nsw i32 %2, -1 store i32 %dec1, i32* @a, align 4 - %3 = load i32* @d, align 4 + %3 = load i32, i32* @d, align 4 %sub2 = sub nsw i32 %dec1, %3 store i32 %sub2, i32* @d, align 4 - %4 = load i32* @a, align 4 + %4 = load i32, i32* @a, align 4 %dec3 = add nsw i32 %4, -1 store i32 %dec3, i32* @a, align 4 - %5 = load i32* @d, align 4 + %5 = load i32, i32* @d, align 4 %sub4 = sub nsw i32 %dec3, %5 store i32 %sub4, i32* @d, align 4 - %6 = load i32* @a, align 4 + %6 = load i32, i32* @a, align 4 %dec5 = add nsw i32 %6, -1 store i32 %dec5, i32* @a, align 4 - %7 = load i32* @d, align 4 + %7 = load i32, i32* @d, align 4 %sub6 = sub nsw i32 %dec5, %7 store i32 %sub6, i32* @d, align 4 - %8 = load i32* @a, align 4 + %8 = load i32, i32* @a, align 4 %dec7 = add nsw i32 %8, -1 store i32 %dec7, i32* @a, align 4 - %9 = load i32* @d, align 4 + %9 = load i32, i32* @d, align 4 %sub8 = sub nsw i32 %dec7, %9 store i32 %sub8, i32* @d, align 4 ret i32 0 diff --git a/test/Transforms/Reassociate/pr21205.ll b/test/Transforms/Reassociate/pr21205.ll index fcc7150..0c6fd3a 100644 --- a/test/Transforms/Reassociate/pr21205.ll +++ b/test/Transforms/Reassociate/pr21205.ll @@ -11,7 +11,7 @@ define i32 @test1() { entry: - %0 = load i32* @a, align 4 + %0 = load i32, i32* @a, align 4 %conv = sitofp i32 %0 to float %sub = fsub fast float %conv, undef %sub1 = fadd fast float %sub, -1.000000e+00 |