[Bug rtl-optimization/77664] Missed optimization: signed int >= 0 && < unsigned short

2016-09-21 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77664

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
Well, IMHO we want to do it not just when you have a >= 0 & a < x
where x is known to have the MSB (from range info) in the comparison type
clear, but also if there is && or the conditions are possibly appart, say
if (a >= 0 && d && e != 21 && f && a < b) etc.
So, I'd think that tree-ssa-reassoc.c would be a better place to optimize this.

So, init_range_entry would need to be taught to handle
GT_EXPR/GE_EXPR/LT_EXPR/LE_EXPR with non-INTEGER_CST second argument by
creating an entry with "symbolic" high and constant low, range_entry_cmp to
sort those last and then deal with it when merging ranges.

[Bug rtl-optimization/77664] Missed optimization: signed int >= 0 && < unsigned short

2016-09-21 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77664

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||easyhack,
   ||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-09-21
 Ever confirmed|0   |1
   Severity|normal  |enhancement

--- Comment #1 from Andrew Pinski  ---
Confirmed, The general optimization is the following:
(si >= 0) & si < (int)ushorteri
->
((unsigned)si) < (unsigned)ushorteri

Or in almost match.pd syntax (but needs some changes to get to the correct
format and it needs to handle le/gt instead of just ge/lt):
(simplify
 (bit_and (ge @0 integer_zerop)
  (lt @0 (convert @2)))
 (if (signed_type(@0)
  && unsigned_type(@2)
  && sizeof(@0) >= sizeof(@2))
   (lt { build_convert(unsignedtypeof(@0), @0); }
   { build_convert(unsignedtypeof(@0), @2); }))