[patch tree-optimization]: Try to do type sinking on comparisons

Kai Tietz ktietz@redhat.com
Tue Jun 28 10:53:00 GMT 2011

----- Original Message -----
From: "Richard Guenther" <richard.guenther@gmail.com>
To: "Kai Tietz" <ktietz@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Sent: Tuesday, June 28, 2011 10:45:20 AM
Subject: Re: [patch tree-optimization]: Try to do type sinking on comparisons

On Mon, Jun 27, 2011 at 8:52 PM, Kai Tietz <ktietz@redhat.com> wrote:
> Hello,
> this patch tries to sink conversions for comparisons patterns:
> a) (type) X cmp (type) Y => x cmp y.
> b) (type) X cmp CST => x cmp ((type-x) CST).
> c) CST cmp (type) X => ((type-x) CST) cmp x.
> This patch just allows type sinking for the case that type-precision of type is wider or equal to type-precision of type-x. Or if type and type-x have same signess and CST fits into type-x. For cmp operation is == or !=, we allow also that type and type-x have different signess, as long as CST fits into type-x without truncation.
> ChangeLog
> 2011-06-27  Kai Tietz  <ktietz@redhat.com>
>        * tree-ssa-forwprop.c (forward_propagate_into_comparision):
>        Sink types within comparison operands, if suitable.
> Bootstrapped and regression tested for x86_64-pc-linux-gnu. Ok for apply?

Hmm, why does fold_widened_comparison and fold_sign_changed_comparison
not handle these cases?  We already dispatch to fold in this function,
so this is a case where we'd want fold to be improved.  You didn't add
testcases - do you have some that are not handled by fold already?


> Regards,
> Kai

Well, I noticed this kind of patterns in case for boolification of comparisons.  They seem to appear if one of the comparison operands itself has type-promotion and has non-trivial tree.
Nevertheless I am about to rework this patch a bit, as it has some issues about type-truncation, if outer type has smaller precision then inner type. I think for now
it would be ok to do operations only for case that inner type has smaller or equal precision then outer type, and inner and outer type are of integer kind.
In the other case we might want to transform such integer-comparisons from ((char) a:int) cmp CST to (a:int & (char) ~0) cmp (char) CST. So we are truncation proper for comparison.

Nevertheless the more interesting part is, if inner type has smaller or equal precision to outer type.


More information about the Gcc-patches mailing list