(convert @c0))))))))
#endif
+/* These was part of minmax phiopt. */
+/* Optimize (a CMP b) ? minmax<a, c> : minmax<b, c>
+ to minmax<min/max<a, b>, c> */
+(for minmax (min max)
+ (for cmp (lt le gt ge)
+ (simplify
+ (cond (cmp @1 @3) (minmax:c @1 @4) (minmax:c @2 @4))
+ (with
+ {
+ tree_code code = minmax_from_comparison (cmp, @1, @2, @1, @3);
+ }
+ (if (code == MIN_EXPR)
+ (minmax (min @1 @2) @4)
+ (if (code == MAX_EXPR)
+ (minmax (max @1 @2) @4)))))))
+
/* X != C1 ? -X : C2 simplifies to -X when -C1 == C2. */
(simplify
(cond (ne @0 INTEGER_CST@1) (negate@3 @0) INTEGER_CST@2)
/* { dg-do run } */
-/* { dg-options "-O -fdump-tree-phiopt -g" } */
+/* { dg-options "-O -fdump-tree-phiopt -fdump-tree-optimized -g" } */
#include <stdint.h>
return 0;
}
-/* { dg-final { scan-tree-dump-times "MIN_EXPR" 3 "phiopt1" } } */
+/* After phiopt1, there really should be only 3 MIN_EXPR in the IR (including debug statements).
+ But the way phiopt does not cleanup the CFG all the time, the PHI might still reference the
+ alternative bb's moved statement.
+ Note in the end, we do dce the statement and other debug statements to end up with only 2 MIN_EXPR.
+ So check that too. */
+/* { dg-final { scan-tree-dump-times "MIN_EXPR" 4 "phiopt1" } } */
+/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR" 0 "phiopt1" } } */
/* { dg-do run } */
-/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt" } */
+/* Note both PHI-OPT and the loop if conversion pass converts the inner if to be branchless using min/max. */
+/* { dg-options "-O2 -fsplit-paths -fdump-tree-split-paths-details --param max-jump-thread-duplication-stmts=20 -fno-ssa-phiopt -fno-tree-loop-if-convert" } */
#include <stdio.h>
#include <stdlib.h>