The original patch adding the "min|max(a+|-c,b+|-c) -> min|max(a,b)+|-c" pattern
missed integral type checks and caused some powerpc tests to fail.
PR tree-optimization/125214
gcc/ChangeLog:
* match.pd (min|max(a+|-c,b+|-c)): Add integral type check.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr125214.c: New test.
Signed-off-by: Pengxuan Zheng <pengxuan.zheng@oss.qualcomm.com>
(for minmax (min max)
(simplify
(minmax:c (plus:cs @0 @2) (plus:s @1 @2))
- (if (TYPE_OVERFLOW_UNDEFINED (type)
+ (if (INTEGRAL_TYPE_P (type)
+ && TYPE_OVERFLOW_UNDEFINED (type)
&& !TYPE_OVERFLOW_SANITIZED (type))
(plus (minmax @0 @1) @2))))
(for minmax (min max)
(simplify
(minmax:c (minus:s @0 @2) (minus:s @1 @2))
- (if (TYPE_OVERFLOW_UNDEFINED (type)
+ (if (INTEGRAL_TYPE_P (type)
+ && TYPE_OVERFLOW_UNDEFINED (type)
&& !TYPE_OVERFLOW_SANITIZED (type))
(minus (minmax @0 @1) @2))))
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fdump-tree-forwprop1-raw" } */
+
+/* "min|max(a+|-c,b+|-c) -> min|max(a,b)+|-c" folding should NOT happen for
+ non-integral types. */
+
+double
+f (double a, double b, double c)
+{
+ return __builtin_fmax (a + c, b + c);
+}
+
+/* { dg-final { scan-tree-dump-times "plus_expr" 2 "forwprop1" } } */