This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Optimize 'a ' as single char string too


On Tue, Jul 13, 2010 at 10:37:53PM +0200, Toon Moene wrote:
> >On:
> >
> >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).

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]