public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/10823: 3.3 - wrong code after first cse pass
@ 2003-05-16 16:56 gawrilow
  0 siblings, 0 replies; only message in thread
From: gawrilow @ 2003-05-16 16:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10823
>Category:       optimization
>Synopsis:       3.3 - wrong code after first cse pass
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri May 16 16:56:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Ewgenij Gawrilow
>Release:        3.3
>Organization:
>Environment:
RedHat 7.3 on an Athlon PC

../gcc-3.3/configure --enable-languages=c++ --enable-shared --with-cpu=athlon --enable-version-specific-runtime-libs --with-gxx-include-dir=/usr/site-local/share/include/c++/3.3 --prefix=/usr/site-local/share --exec-prefix=/usr/site-local
>Description:
The first cse pass garbles the class LV constructor code inlined into the fetch() function.  Compare the insn 405, 406 in the 08.null and 09.cse dumps.  The _start field of the target is copied from the _size field of the source, which is obviuosly wrong.

I hope, this time the test case is sufficiently short.  The original program that crashed due to this bug has over 80K lines after cpp.  Further reducing makes the bug disappear, especially removing the explicitly defined copy constructor of class Gen (if this helps...)

The parts embraced in #ifdef DEMO are useful only for the bug demonstration, e.g. in a test suite, and can be safely ignored when debugging.

BTW, as I analyzed the assembler output, some other optimization deficiences have been revealed. If you mean, I should submit them as separate bugs, or they are no bugs at all, please let me know. Here they are:

1. The placement operator new is not required to check his argument for being non-null. Neither the constructors are. Nevertheless, gcc emits a test and a branch.

2. Even if this test would be required, it should have been eliminated by the previous optimization pass (null pointer elimination), as the same pointer is used to access the 'exists' field prior to the test.  Or, alternatively, the null pointer elimination should be repeated after cse, if this failure is caused by the expressions looking too different at the beginning.

3. The constructor argument in the placement new expression is a temporary object returned by the inlined function get(). It would be much better for the run-time efficiency if the target address (area) would be passed directly to get(). Currently the temporary object is created separately and then copied into the area.  I think, the Standard allows to eliminate such temporaries together with copy constructor calls, doesn't it?
>How-To-Repeat:
Compile the attached program with additional -DDEMO option, then run it.  If compiled with -O1, it produces the correct output string '0 3 0 3'.  When compiled with -O2 or higher, the output will be '0 3 3 3'.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="minkowski_test.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="minkowski_test.cc"

I2luY2x1ZGUgPG5ldz4KCmNsYXNzIEdlbiB7CnByb3RlY3RlZDoKICAgR2VuKCkgeyB9CiAgIEdl
bihjb25zdCBHZW4mKSB7IH0KfTsKCmNsYXNzIFNlcSA6IHB1YmxpYyBHZW4gewpwcm90ZWN0ZWQ6
CiAgIGludCBfc3RhcnQsIF9zaXplOwpwdWJsaWM6CiAgIFNlcShpbnQgc3RhcnRfYXJnLCBpbnQg
c2l6ZV9hcmcpCiAgICAgIDogX3N0YXJ0KHN0YXJ0X2FyZyksIF9zaXplKHNpemVfYXJnKSB7IH0K
CiAgIGludCBzdGFydCgpIGNvbnN0IHsgcmV0dXJuIF9zdGFydDsgfQogICBpbnQgc2l6ZSgpIGNv
bnN0IHsgcmV0dXJuIF9zaXplOyB9Cn07CgpjbGFzcyBNYXRyaXggewpwcm90ZWN0ZWQ6CiAgIGlu
dCBkaW1yLCBkaW1jOwpwdWJsaWM6CiNpZmRlZiBERU1PCiAgIE1hdHJpeChpbnQgciwgaW50IGMp
IDogZGltcihyKSwgZGltYyhjKSB7IH0KI2VuZGlmCiAgIGludCBjb2xzKCkgY29uc3QgeyByZXR1
cm4gZGltYzsgfQp9OwoKY2xhc3MgUlYgewpwcm90ZWN0ZWQ6CiAgIGNvbnN0IGludCogczE7CiAg
IFNlcSBzMjsKcHVibGljOgogICBSVihjb25zdCBpbnQmIGFyZzEsIGNvbnN0IFNlcSYgYXJnMikg
OiBzMSgmYXJnMSksIHMyKGFyZzIpIHsgfQojaWZkZWYgREVNTwogICBjb25zdCBTZXE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PGlvc3RyZWFtPgoKaW50IG1haW4oKSB7CiAg
IE1hdHJpeCBNKDMsMyk7CiAgIFRvcCBUKE0pOwogICBjb25zdCBMViYgbD1ULmZldGNoKCk7CiAg
IHN0ZDo6Y291dCA8PCBsLnNlcTEoKS5zdGFydCgpIDw8ICcgJwoJICAgICA8PCBsLnNlcTEoKS5z
aXplKCkgPDwgJyAnCgkgICAgIDw8IGwuc2VxMigpLnN0YXJ0KCkgPDwgJyAnCgkgICAgIDw8IGwu
c2VxMigpLnNpemUoKSA8PCBzdGQ6OmVuZGw7CiAgIHJldHVybiAwOwp9CiNlbmRpZiAvLyBERU1P
Cg==


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-05-16 16:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-16 16:56 optimization/10823: 3.3 - wrong code after first cse pass gawrilow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).