summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-08-07 19:49:13 +0000
committerSanjay Patel <spatel@rotateright.com>2018-08-07 19:49:13 +0000
commit50976393ed8734e043bed2351ef274e1670dc96e (patch)
tree7c2a929ae259d8a939b2f029ccea385f06d59311
parent7add5820322a571f19e9ea5bed514d87c3799fa7 (diff)
downloadbcm5719-llvm-50976393ed8734e043bed2351ef274e1670dc96e.tar.gz
bcm5719-llvm-50976393ed8734e043bed2351ef274e1670dc96e.zip
[InstSimplify] add tests for fadd/fsub; NFC
Instcombine gets some, but not all, of these cases via it's internal reassociation transforms. It fails in all cases with vector types. llvm-svn: 339168
-rw-r--r--llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll174
1 files changed, 174 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
index 79eb349ed7e..0481ee45651 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -733,3 +733,177 @@ define float @maxnum_x_y_maxnum_z(float %x, float %y, float %z) {
ret float %b
}
+; Y - (Y - X) --> X
+
+define float @fsub_fsub_common_op(float %x, float %y) {
+; CHECK-LABEL: @fsub_fsub_common_op(
+; CHECK-NEXT: [[S:%.*]] = fsub float [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[Y]], [[S]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %s = fsub float %y, %x
+ %r = fsub reassoc nsz float %y, %s
+ ret float %r
+}
+
+define <2 x float> @fsub_fsub_common_op_vec(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @fsub_fsub_common_op_vec(
+; CHECK-NEXT: [[S:%.*]] = fsub <2 x float> [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> [[Y]], [[S]]
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %s = fsub <2 x float> %y, %x
+ %r = fsub reassoc nsz <2 x float> %y, %s
+ ret <2 x float> %r
+}
+
+; Negative test - fsub is not commutative.
+; Y - (X - Y) --> (Y - X) + Y (canonicalized)
+
+define float @fsub_fsub_wrong_common_op(float %x, float %y) {
+; CHECK-LABEL: @fsub_fsub_wrong_common_op(
+; CHECK-NEXT: [[S:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[Y]], [[S]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %s = fsub float %x, %y
+ %r = fsub reassoc nsz float %y, %s
+ ret float %r
+}
+
+; Negative test - negated operand needed.
+; (Y - X) - Y --> -X
+
+define float @fsub_fsub_common_op_wrong_commute(float %x, float %y) {
+; CHECK-LABEL: @fsub_fsub_common_op_wrong_commute(
+; CHECK-NEXT: [[S:%.*]] = fsub float [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[S]], [[Y]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %s = fsub float %y, %x
+ %r = fsub reassoc nsz float %s, %y
+ ret float %r
+}
+
+; Negative test - fsub is not commutative.
+; (X - Y) - Y --> ?
+
+define float @fsub_fsub_wrong_common_op_wrong_commute(float %x, float %y) {
+; CHECK-LABEL: @fsub_fsub_wrong_common_op_wrong_commute(
+; CHECK-NEXT: [[S:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[S]], [[Y]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %s = fsub float %x, %y
+ %r = fsub reassoc nsz float %s, %y
+ ret float %r
+}
+
+; (Y + X) - Y --> X
+
+define float @fadd_fsub_common_op(float %x, float %y) {
+; CHECK-LABEL: @fadd_fsub_common_op(
+; CHECK-NEXT: [[A:%.*]] = fadd float [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[A]], [[Y]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %a = fadd float %y, %x
+ %r = fsub reassoc nsz float %a, %y
+ ret float %r
+}
+
+; (X + Y) - Y --> X
+
+define <2 x float> @fadd_fsub_common_op_commute_vec(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @fadd_fsub_common_op_commute_vec(
+; CHECK-NEXT: [[A:%.*]] = fadd <2 x float> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> [[A]], [[Y]]
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %a = fadd <2 x float> %x, %y
+ %r = fsub reassoc nsz <2 x float> %a, %y
+ ret <2 x float> %r
+}
+
+; Negative test - negated operand needed.
+; Y - (Y + X) --> -X
+
+define float @fadd_fsub_common_op_wrong_commute(float %x, float %y) {
+; CHECK-LABEL: @fadd_fsub_common_op_wrong_commute(
+; CHECK-NEXT: [[A:%.*]] = fadd float [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[Y]], [[A]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %a = fadd float %y, %x
+ %r = fsub reassoc nsz float %y, %a
+ ret float %r
+}
+
+; Negative test - negated operand needed.
+; Y - (X + Y) --> -X
+
+define float @fadd_fsub_common_op_wrong_commute_commute(float %x, float %y) {
+; CHECK-LABEL: @fadd_fsub_common_op_wrong_commute_commute(
+; CHECK-NEXT: [[A:%.*]] = fadd float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float [[Y]], [[A]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %a = fadd float %x, %y
+ %r = fsub reassoc nsz float %y, %a
+ ret float %r
+}
+
+; Y + (X - Y) --> X
+
+define <2 x float> @fsub_fadd_common_op_vec(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @fsub_fadd_common_op_vec(
+; CHECK-NEXT: [[S:%.*]] = fsub <2 x float> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz <2 x float> [[Y]], [[S]]
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %s = fsub <2 x float> %x, %y
+ %r = fadd reassoc nsz <2 x float> %y, %s
+ ret <2 x float> %r
+}
+
+; (X - Y) + Y --> X
+
+define float @fsub_fadd_common_op_commute(float %x, float %y) {
+; CHECK-LABEL: @fsub_fadd_common_op_commute(
+; CHECK-NEXT: [[S:%.*]] = fsub float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[S]], [[Y]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %s = fsub float %x, %y
+ %r = fadd reassoc nsz float %s, %y
+ ret float %r
+}
+
+; Negative test.
+; Y + (Y - X) --> ?
+
+define float @fsub_fadd_common_op_wrong_commute(float %x, float %y) {
+; CHECK-LABEL: @fsub_fadd_common_op_wrong_commute(
+; CHECK-NEXT: [[S:%.*]] = fsub float [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[Y]], [[S]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %s = fsub float %y, %x
+ %r = fadd reassoc nsz float %y, %s
+ ret float %r
+}
+
+; Negative test.
+; (Y - X) + Y --> ?
+
+define float @fsub_fadd_common_op_wrong_commute_commute(float %x, float %y) {
+; CHECK-LABEL: @fsub_fadd_common_op_wrong_commute_commute(
+; CHECK-NEXT: [[S:%.*]] = fsub float [[Y:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[S]], [[Y]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %s = fsub float %y, %x
+ %r = fadd reassoc nsz float %s, %y
+ ret float %r
+}
+
OpenPOWER on IntegriCloud