[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-07 Thread ebotcazou at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 Eric Botcazou changed: What|Removed |Added CC||ebotcazou at gcc dot gnu.org --- Comment

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-06 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #19 from mimamer at gmail dot com --- One last comment on strict aliasing rules: It is ironic that these rules are supposed to make programs faster, but those developers that really care about speed are prevented from implementing even

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #18 from mimamer at gmail dot com --- Ah? I didn't figure that was allowed per strict aliasing rules. But it still doesn't solve one problem: inline T *dequeue() { node *head = anchor.next; anchor.next = head->next; head->

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #17 from Andrew Pinski --- (In reply to mimamer from comment #16) > Ah ok, but that doesn't solve my problem as I will eventually need to cast a > node pointer back to T (either at the caller or the callee side). So there > _is_ no ef

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #16 from mimamer at gmail dot com --- Ah ok, but that doesn't solve my problem as I will eventually need to cast a node pointer back to T (either at the caller or the callee side). So there _is_ no efficient solution with strict aliasi

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #15 from Andrew Pinski --- template class list2 { public: struct node { node*next; node*prev; }; nodeanchor; public: /* API */ } struct Obj : list2::node { /* obj-specific element

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #14 from mimamer at gmail dot com --- Can you explain what you mean by "use type node inside the struct node"? Because I still cannot see an (efficient) way for solving this problem.

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 Andrew Pinski changed: What|Removed |Added Status|WAITING |RESOLVED Resolution|---

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #12 from Andrew Pinski --- (In reply to mimamer from comment #11) > In short form, > > template class list2 > { > public: > struct node { > T *next; > T *prev; > }; > > nod

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #11 from mimamer at gmail dot com --- In short form, template class list2 { public: struct node { T*next; T*prev; }; nodeanchor; public: /* API */ } struct Obj : list2::node { /*

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 Andrew Pinski changed: What|Removed |Added Status|UNCONFIRMED |WAITING Last reconfirmed|

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #9 from mimamer at gmail dot com --- Now that I have read enough about aliasing rules I realize that they are considerably fucked up and that their is no way to efficiently downcast without violating strict aliasing rules. In explanati

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #8 from mimamer at gmail dot com --- As concerns -fno-strict-aliasing, I have to put it before -O2. Sorry for the mixup.

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #7 from mimamer at gmail dot com --- Violation of aliasing or not, the problem arises prior to the downcasting from list2::node* to T*: T *head = anchor.next; anchor.next = head->next; head->next->prev = (T *)&anchor; // w

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #6 from mimamer at gmail dot com --- Btw, C++ doesn't give me any aliasing warnings even with -Wstrict-aliasing=1.

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #5 from mimamer at gmail dot com --- T is derived from list2::node, and yes, I'm "up"casting from node to T. There is no other way around it in the implementation, and if this causes a problem with aliasing then I don't know what it's

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #4 from mimamer at gmail dot com --- Indeed, this is alias-related. Two questions: (1) What is a concrete solution for this problem when -fstrict-aliasing is being used? How should I change my code? (Sorry, I am no expert on this.) (

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #3 from Andrew Pinski --- This seems alias related. Can you make sure you are not violating c/c++ alias rules. Mainly make sure T and typeof(anchor) can alias.

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #2 from mimamer at gmail dot com --- Turns out the problems arise in different places but only in the list2::dequeue() function: inline T *dequeue() { //asm volatile("":::"memory"); T *head = anchor.next; anchor.next = hea

[Bug c++/61421] Invalid -O2 optimization breaks program

2014-06-05 Thread mimamer at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61421 --- Comment #1 from mimamer at gmail dot com --- A minimalistic version that breaks with all -O2 flags set: Starting from an empty main_list: Node *node; //asm volatile("":::"memory"); while ( (node = main_list.dequeue()) != main_list.end() )