This is the mail archive of the gcc-bugs@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]

[Bug fortran/52861] (missed optimisation) missed transformation to memset with -O3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52861

--- Comment #7 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-07 15:25:37 UTC ---
Created attachment 27579
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27579
Proof-of-concept patch (works but has many regression-test failures)

(In reply to comment #5)
> Fixed on trunk, closing.

Well, not completely - only for the special case. I think there is more room
for improvement: Hoisting the memset out of the loop and using ARRAY_RANGE_REF
for the assignments.

 * * *

The attach patch contains a proof-of-concept implementation of ARRAY_RANGE_REF.

The problem is that one needs to strip off several operations on the LHS/RHS in
order to use ARRAY_RANGE_REF. For instance, for a literal, one gets *&"abcd"[1]
but the bare "abcd" is needed (note the ARRAY_REF "[1]"); but one needs to have
just the literal "abcd". For "var(2:0)" one not only needs to strip off the
ARRAY_REF, but one also needs to obtain the offset. While for "string(1)(:)"
and "string(1)(2:3)" the ARRAY_REF for the array has to be kept, but not for
the string part (except for the lower bound). The current version is rather
hacky :-(

Additionally, one runs into the problem that a pointer to a "char" and a
pointer to a "char[:]" aren't the same; many temporary vars have the wrong kind
of "char" type.

While the code works rather nicely for various small test cases, there are many
test-suite failures with the patch. The problem is simply that removing the
(sub)string ARRAY_REF while keeping the array ARRAY_REF is difficult. Fixing
the arguments to gfc_trans_string_copy is also not that simple.

Example for a failing test case:
  character(len=4, kind=1),pointer :: str(:)
  allocate(str(1))
  str(1) = 1_"abcd"     ! Fails
  str(1)(2:) = 1_"abcd" ! Works


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