[PATCH][PING][PR 81376] Remove unnecessary float casts in comparisons
Richard Biener
richard.guenther@gmail.com
Mon Oct 9 13:28:00 GMT 2017
On Mon, Oct 9, 2017 at 11:12 AM, Yuri Gribov <tetra2005@gmail.com> wrote:
> Hi all,
>
> This patch gets rid of float casts in comparisons when all values of
> casted integral type are exactly representable by the float type
> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81376).
>
> Bootstrapped and regtested on x64_64. Ok to commit?
+bool format_helper::can_represent_integral_type_p (tree type) const
+{
+ gcc_assert (! decimal_p () && INTEGRAL_TYPE_P (type) && "NYI");
"NYI"?
+ /* Determine the largest type. */
+
excess vertical space
+ signop sign1 = TYPE_SIGN (type1),
+ sign2 = TYPE_SIGN (type2);
+ int prec1 = TYPE_PRECISION (type1),
+ prec2 = TYPE_PRECISION (type2);
+
+ bool type1_largest_p = (sign1 == sign2 && prec2 <= prec1)
+ || (sign1 == SIGNED && sign2 == UNSIGNED && prec2 < prec1);
+ bool type2_largest_p = (sign1 == sign2 && prec1 <= prec2)
+ || (sign1 == UNSIGNED && sign2 == SIGNED && prec1 < prec2);
+ }
+ (switch
I dislike too many temporaries, isn't
(if (TYPE_PRECISION (type1) > TYPE_PRECISION (type2))
(cmp @1 (convert @2)
(if (TYPE_PRECISION (type2) > TYPE_PRECISION (type1))
(cmp (convert @1) @2)
(if (TYPE_SIGN (type1) == TYPE_SIGN (type2))
(cmp @1 @2)))))
easier to follow? Note the if-else cascade, note the (convert ..)s do not
need an explicit type.
I wonder if we anywhere "canonicalize" non-simple comparison operators
(unle, ltgt, etc.) for comparisons involving integer-to-float
converted operands.
Thanks,
Richard.
> -Y
More information about the Gcc-patches
mailing list