* [PATCH] Improve compare with min/max simplification for bools
@ 2015-07-28 12:00 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2015-07-28 12:00 UTC (permalink / raw)
To: gcc-patches
For types with just two values max - 1 is equal to min and thus
we fail to optimize some cases of comparisons. With fold-const.c
bool < 0 needed the abs(x) < 0 simplification to trigger it
(same issue with mis-ordered if / else-ifs).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2015-07-28 Richard Biener <rguenther@suse.de>
* match.pd: Re-order two cases in comparison with max/min
value simplification to make it apply for bools.
Index: gcc/match.pd
===================================================================
--- gcc/match.pd (revision 226306)
+++ gcc/match.pd (working copy)
@@ -1856,12 +1856,6 @@ (define_operator_list CBRT BUILT_IN_CBRT
{ constant_boolean_node (true, type); })
(if (cmp == LT_EXPR)
(ne @2 @1))))
- (if (wi::eq_p (@1, max - 1))
- (switch
- (if (cmp == GT_EXPR)
- (eq @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))
- (if (cmp == LE_EXPR)
- (ne @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))))
(if (wi::eq_p (@1, min))
(switch
(if (cmp == LT_EXPR)
@@ -1872,6 +1866,12 @@ (define_operator_list CBRT BUILT_IN_CBRT
{ constant_boolean_node (true, type); })
(if (cmp == GT_EXPR)
(ne @2 @1))))
+ (if (wi::eq_p (@1, max - 1))
+ (switch
+ (if (cmp == GT_EXPR)
+ (eq @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))
+ (if (cmp == LE_EXPR)
+ (ne @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))))
(if (wi::eq_p (@1, min + 1))
(switch
(if (cmp == GE_EXPR)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-07-28 11:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-28 12:00 [PATCH] Improve compare with min/max simplification for bools Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).