aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms
diff options
context:
space:
mode:
authorMichael Ilseman <milseman@apple.com>2012-12-12 00:27:46 +0000
committerMichael Ilseman <milseman@apple.com>2012-12-12 00:27:46 +0000
commit09ee250e728ccdb7afc6354d777f8319c5a0465c (patch)
tree41e7a8c97d5b62f99aff6058bac1248ee5defb66 /test/Transforms
parent1d4b1507045075273cb301efec8722b961b78c22 (diff)
downloadexternal_llvm-09ee250e728ccdb7afc6354d777f8319c5a0465c.zip
external_llvm-09ee250e728ccdb7afc6354d777f8319c5a0465c.tar.gz
external_llvm-09ee250e728ccdb7afc6354d777f8319c5a0465c.tar.bz2
Added a slew of SimplifyInstruction floating-point optimizations, many of which take advantage of fast-math flags. Test cases included.
fsub X, +0 ==> X fsub X, -0 ==> X, when we know X is not -0 fsub +/-0.0, (fsub -0.0, X) ==> X fsub nsz +/-0.0, (fsub +/-0.0, X) ==> X fsub nnan ninf X, X ==> 0.0 fadd nsz X, 0 ==> X fadd [nnan ninf] X, (fsub [nnan ninf] 0, X) ==> 0 where nnan and ninf have to occur at least once somewhere in this expression fmul X, 1.0 ==> X git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169940 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms')
-rw-r--r--test/Transforms/InstSimplify/fast-math.ll72
-rw-r--r--test/Transforms/InstSimplify/floating-point-arithmetic.ll35
2 files changed, 107 insertions, 0 deletions
diff --git a/test/Transforms/InstSimplify/fast-math.ll b/test/Transforms/InstSimplify/fast-math.ll
index e4b3ea3..154b967 100644
--- a/test/Transforms/InstSimplify/fast-math.ll
+++ b/test/Transforms/InstSimplify/fast-math.ll
@@ -33,3 +33,75 @@ define float @no_mul_zero_3(float %a) {
; CHECK: ret float %b
ret float %b
}
+
+; fadd [nnan ninf] X, (fsub [nnan ninf] 0, X) ==> 0
+; where nnan and ninf have to occur at least once somewhere in this
+; expression
+; CHECK: fadd_fsub_0
+define float @fadd_fsub_0(float %a) {
+; X + -X ==> 0
+ %t1 = fsub nnan ninf float 0.0, %a
+ %zero1 = fadd nnan ninf float %t1, %a
+
+ %t2 = fsub nnan float 0.0, %a
+ %zero2 = fadd ninf float %t2, %a
+
+ %t3 = fsub nnan ninf float 0.0, %a
+ %zero3 = fadd float %t3, %a
+
+ %t4 = fsub float 0.0, %a
+ %zero4 = fadd nnan ninf float %t4, %a
+
+; Dont fold this
+; CHECK: %nofold = fsub float 0.0
+ %nofold = fsub float 0.0, %a
+; CHECK: %no_zero = fadd nnan float %nofold, %a
+ %no_zero = fadd nnan float %nofold, %a
+
+; Coalesce the folded zeros
+ %zero5 = fadd float %zero1, %zero2
+ %zero6 = fadd float %zero3, %zero4
+ %zero7 = fadd float %zero5, %zero6
+
+; Should get folded
+ %ret = fadd nsz float %no_zero, %zero7
+
+; CHECK: ret float %no_zero
+ ret float %ret
+}
+
+; fsub nnan ninf x, x ==> 0.0
+; CHECK: @fsub_x_x
+define float @fsub_x_x(float %a) {
+; X - X ==> 0
+ %zero1 = fsub nnan ninf float %a, %a
+
+; Dont fold
+; CHECK: %no_zero1 = fsub
+ %no_zero1 = fsub ninf float %a, %a
+; CHECK: %no_zero2 = fsub
+ %no_zero2 = fsub nnan float %a, %a
+; CHECK: %no_zero = fadd
+ %no_zero = fadd float %no_zero1, %no_zero2
+
+; Should get folded
+ %ret = fadd nsz float %no_zero, %zero1
+
+; CHECK: ret float %no_zero
+ ret float %ret
+}
+
+; fadd nsz X, 0 ==> X
+; CHECK: @nofold_fadd_x_0
+define float @nofold_fadd_x_0(float %a) {
+; Dont fold
+; CHECK: %no_zero1 = fadd
+ %no_zero1 = fadd ninf float %a, 0.0
+; CHECK: %no_zero2 = fadd
+ %no_zero2 = fadd nnan float %a, 0.0
+; CHECK: %no_zero = fadd
+ %no_zero = fadd float %no_zero1, %no_zero2
+
+; CHECK: ret float %no_zero
+ ret float %no_zero
+}
diff --git a/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/test/Transforms/InstSimplify/floating-point-arithmetic.ll
new file mode 100644
index 0000000..f9c364c
--- /dev/null
+++ b/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -0,0 +1,35 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+; fsub 0, (fsub 0, X) ==> X
+; CHECK: @fsub_0_0_x
+define float @fsub_0_0_x(float %a) {
+ %t1 = fsub float -0.0, %a
+ %ret = fsub float -0.0, %t1
+
+; CHECK: ret float %a
+ ret float %ret
+}
+
+; fsub X, 0 ==> X
+; CHECK: @fsub_x_0
+define float @fsub_x_0(float %a) {
+ %ret = fsub float %a, 0.0
+; CHECK ret float %a
+ ret float %ret
+}
+
+; fadd X, -0 ==> X
+; CHECK: @fadd_x_n0
+define float @fadd_x_n0(float %a) {
+ %ret = fadd float %a, -0.0
+; CHECK ret float %a
+ ret float %ret
+}
+
+; fmul X, 1.0 ==> X
+; CHECK: @fmul_X_1
+define double @fmul_X_1(double %a) {
+ %b = fmul double 1.000000e+00, %a ; <double> [#uses=1]
+ ; CHECK: ret double %a
+ ret double %b
+}