This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Optimize 'a ' as single char string too
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Toon Moene <toon at moene dot org>
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Tue, 13 Jul 2010 22:48:08 +0200
- Subject: Re: [PATCH] Optimize 'a ' as single char string too
- References: <20100713203346.GF20208@tyan-ft48-01.lab.bos.redhat.com> <4C3CCEA1.email@example.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Jul 13, 2010 at 10:37:53PM +0200, Toon Moene wrote:
> >subroutine foo (c)
> > character :: c
> > if (c .eq. 'a') call abort
> > if (c .eq. 'ab') call abort
> > if (c .eq. 'a ') call abort
> >end subroutine
> >only the first test is optimized into c == 'a' comparison, the other
> >two call _gfortran_compare_string.
> Strictly speaking, a single character (character string of length 1)
> can never be equal to 'ab', so that could be removed too - but
> that's probably a case for the Fortran Frontend ...
Sure, I've already noticed that too, but that's something for later.
There is a slight problem that gfc_build_compare_string returns < 0, 0, or >
0, so it would need to be told by an extra argument whether just
equality or unequality check is performed instead (in that case it
can try roughly compile time string_len_trim on the string literal
and if it is longer than the other operand, it is always unequal).