]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
max(INT_MIN, x) -> x
authorMarc Glisse <marc.glisse@inria.fr>
Thu, 21 Apr 2016 09:32:32 +0000 (11:32 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Thu, 21 Apr 2016 09:32:32 +0000 (09:32 +0000)
2016-04-21  Marc Glisse  <marc.glisse@inria.fr>

gcc/
* match.pd (min(int_max, x), max(int_min, x)): New transformations.

gcc/testsuite/
* gcc.dg/tree-ssa/minmax-1.c: New testcase.

From-SVN: r235323

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/minmax-1.c [new file with mode: 0644]

index d2a345cf7f5be57d2a613fdcd90e90aeb5ac5dfb..26d1861456f623aa80163401233a28284ec6bbe7 100644 (file)
@@ -1,3 +1,7 @@
+2016-04-21  Marc Glisse  <marc.glisse@inria.fr>
+
+       * match.pd (min(int_max, x), max(int_min, x)): New transformations.
+
 2016-04-20  Jan Hubicka  <jh@suse.cz>
 
        * ipa-inline.c (can_inline_edge_p): Pass caller info to
index 75aa6013b2e2d2c26fb8d11cec7eecc2d91a30d6..38193216aee1277795f8b2632da603e6503e2a2c 100644 (file)
@@ -1192,16 +1192,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  @1)
 (simplify
  (min @0 @1)
- (if (INTEGRAL_TYPE_P (type)
-      && TYPE_MIN_VALUE (type)
-      && operand_equal_p (@1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST))
-  @1))
+ (switch
+  (if (INTEGRAL_TYPE_P (type)
+       && TYPE_MIN_VALUE (type)
+       && operand_equal_p (@1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST))
+   @1)
+  (if (INTEGRAL_TYPE_P (type)
+       && TYPE_MAX_VALUE (type)
+       && operand_equal_p (@1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST))
+   @0)))
 (simplify
  (max @0 @1)
- (if (INTEGRAL_TYPE_P (type)
-      && TYPE_MAX_VALUE (type)
-      && operand_equal_p (@1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST))
-  @1))
+ (switch
+  (if (INTEGRAL_TYPE_P (type)
+       && TYPE_MAX_VALUE (type)
+       && operand_equal_p (@1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST))
+   @1)
+  (if (INTEGRAL_TYPE_P (type)
+       && TYPE_MIN_VALUE (type)
+       && operand_equal_p (@1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST))
+   @0)))
 (for minmax (FMIN FMAX)
  /* If either argument is NaN, return the other one.  Avoid the
     transformation if we get (and honor) a signalling NaN.  */
index eb47876726e4ebd407c3946408c455e2b2e8f1dd..98db7d0577c4c6bc92f59d41afb2e3fe7a8f828f 100644 (file)
@@ -1,3 +1,7 @@
+2016-04-21  Marc Glisse  <marc.glisse@inria.fr>
+
+       * gcc.dg/tree-ssa/minmax-1.c: New testcase.
+
 2016-04-20  Jan Hubicka  <jh@suse.cz>
 
        PR ipa/70018
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-1.c b/gcc/testsuite/gcc.dg/tree-ssa/minmax-1.c
new file mode 100644 (file)
index 0000000..dfd7ed2
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+static int min(int a,int b){return (a<b)?a:b;}
+static int max(int a,int b){return (a<b)?b:a;}
+int f(int x){return max(x,-__INT_MAX__-1);}
+int g(int x){return min(x,__INT_MAX__);}
+
+/* { dg-final { scan-tree-dump-times "return x_\[0-9\]+.D.;" 2 "optimized" } } */