aboutsummaryrefslogtreecommitdiff
path: root/test/Transforms/Reassociate
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-04-26 05:30:30 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-04-26 05:30:30 +0000
commit464bda3a167bb761eb3c9c178db3fa8ed26fe825 (patch)
treeb0737bd074f12125c550e88e4c1511fc1b21e6cb /test/Transforms/Reassociate
parentcac31de146e7131f411715dc6cb1958ea59bd754 (diff)
Teach the reassociate pass to fold chains of multiplies with repeated
elements to minimize the number of multiplies required to compute the final result. This uses a heuristic to attempt to form near-optimal binary exponentiation-style multiply chains. While there are some cases it misses, it seems to at least a decent job on a very diverse range of inputs. Initial benchmarks show no interesting regressions, and an 8% improvement on SPASS. Let me know if any other interesting results (in either direction) crop up! Credit to Richard Smith for the core algorithm, and helping code the patch itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155616 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/Reassociate')
-rw-r--r--test/Transforms/Reassociate/mulfactor.ll99
1 files changed, 99 insertions, 0 deletions
diff --git a/test/Transforms/Reassociate/mulfactor.ll b/test/Transforms/Reassociate/mulfactor.ll
index 5e6fbeb1ca..6c099b43b3 100644
--- a/test/Transforms/Reassociate/mulfactor.ll
+++ b/test/Transforms/Reassociate/mulfactor.ll
@@ -33,3 +33,102 @@ entry:
ret i32 %d
}
+define i32 @test3(i32 %x) {
+; (x^8)
+; CHECK: @test3
+; CHECK: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: ret
+
+entry:
+ %a = mul i32 %x, %x
+ %b = mul i32 %a, %x
+ %c = mul i32 %b, %x
+ %d = mul i32 %c, %x
+ %e = mul i32 %d, %x
+ %f = mul i32 %e, %x
+ %g = mul i32 %f, %x
+ ret i32 %g
+}
+
+define i32 @test4(i32 %x) {
+; (x^7)
+; CHECK: @test4
+; CHECK: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: ret
+
+entry:
+ %a = mul i32 %x, %x
+ %b = mul i32 %a, %x
+ %c = mul i32 %b, %x
+ %d = mul i32 %c, %x
+ %e = mul i32 %d, %x
+ %f = mul i32 %e, %x
+ ret i32 %f
+}
+
+define i32 @test5(i32 %x, i32 %y) {
+; (x^4) * (y^2)
+; CHECK: @test5
+; CHECK: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: ret
+
+entry:
+ %a = mul i32 %x, %y
+ %b = mul i32 %a, %y
+ %c = mul i32 %b, %x
+ %d = mul i32 %c, %x
+ %e = mul i32 %d, %x
+ ret i32 %e
+}
+
+define i32 @test6(i32 %x, i32 %y, i32 %z) {
+; (x^5) * (y^3) * z
+; CHECK: @test6
+; CHECK: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: ret
+
+entry:
+ %a = mul i32 %x, %y
+ %b = mul i32 %a, %x
+ %c = mul i32 %b, %y
+ %d = mul i32 %c, %x
+ %e = mul i32 %d, %y
+ %f = mul i32 %e, %x
+ %g = mul i32 %f, %z
+ %h = mul i32 %g, %x
+ ret i32 %h
+}
+
+define i32 @test7(i32 %x, i32 %y, i32 %z) {
+; (x^4) * (y^3) * (z^2)
+; CHECK: @test7
+; CHECK: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: mul
+; CHECK-NEXT: ret
+
+entry:
+ %a = mul i32 %y, %x
+ %b = mul i32 %a, %z
+ %c = mul i32 %b, %z
+ %d = mul i32 %c, %x
+ %e = mul i32 %d, %y
+ %f = mul i32 %e, %y
+ %g = mul i32 %f, %x
+ %h = mul i32 %g, %x
+ ret i32 %h
+}