+2017-11-16 Wilco Dijkstra <wdijkstr@arm.com>
+ Jackson Woodruff <jackson.woodruff@arm.com>
+
+ PR tree-optimization/71026
+ * match.pd: Canonicalize constant multiplies in division.
+
2017-11-16 Wilco Dijkstra <wdijkstr@arm.com>
* opts.c (default_options_table): Add OPT_fomit_frame_pointer entry.
(negate @0)))
(if (flag_reciprocal_math)
- /* Convert (A/B)/C to A/(B*C) */
+ /* Convert (A/B)/C to A/(B*C). */
(simplify
(rdiv (rdiv:s @0 @1) @2)
- (rdiv @0 (mult @1 @2)))
+ (rdiv @0 (mult @1 @2)))
+
+ /* Canonicalize x / (C1 * y) to (x * C2) / y. */
+ (simplify
+ (rdiv @0 (mult:s @1 REAL_CST@2))
+ (with
+ { tree tem = const_binop (RDIV_EXPR, type, build_one_cst (type), @2); }
+ (if (tem)
+ (rdiv (mult @0 { tem; } ) @1))))
/* Convert A/(B/C) to (A/B)*C */
(simplify
(if (tem)
(rdiv { tem; } @1)))))
-/* Convert C1/(X*C2) into (C1/C2)/X */
-(simplify
- (rdiv REAL_CST@0 (mult @1 REAL_CST@2))
- (if (flag_reciprocal_math)
- (with
- { tree tem = const_binop (RDIV_EXPR, type, @0, @2); }
- (if (tem)
- (rdiv { tem; } @1)))))
-
/* Simplify ~X & X as zero. */
(simplify
(bit_and:c (convert? @0) (convert? (bit_not @0)))
+2017-11-16 Wilco Dijkstra <wdijkstr@arm.com>
+ Jackson Woodruff <jackson.woodruff@arm.com>
+
+ PR tree-optimization/71026
+ * gcc.dg/cse_recip.c: New test.
+
2017-11-16 Wilco Dijkstra <wdijkstr@arm.com>
* gcc.target/aarch64/lr_free_2.c: Fix test.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fdump-tree-optimized-raw" } */
+
+void
+cse_recip (float x, float y, float *a)
+{
+ a[0] = y / (5 * x);
+ a[1] = y / (3 * x);
+ a[2] = y / x;
+}
+
+/* { dg-final { scan-tree-dump-times "rdiv_expr" 1 "optimized" } } */