public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/43247] New: Icorrect optimization while declaring array[1] @ 2010-03-03 14:37 ogoffart at kde dot org 2010-03-03 14:42 ` [Bug c++/43247] " thiago at kde dot org ` (9 more replies) 0 siblings, 10 replies; 15+ messages in thread From: ogoffart at kde dot org @ 2010-03-03 14:37 UTC (permalink / raw) To: gcc-bugs This code should print "WORKS!!!!" a couple of time. But with -O2, g++ optimize the condition away. It works with -O1 Tested with gcc 4.4.3 on linux x86_64 (Archlinux) #include <stdio.h> #include <string.h> #include <stdlib.h> struct QVectorTypedData { int array[1]; }; int main(int , char **) { QVectorTypedData *d; d = static_cast<QVectorTypedData *>(::malloc(sizeof(QVectorTypedData)+ (45-1) * sizeof(int))); memset(d->array, 0, 45 * sizeof(int)); int *array = d->array; int count = 0; for (int i = 0; i < 10; i++) { fprintf(stderr, "%d %d %d %d\n", i, (i>=3), (i<=8), (i>=3) && (i <= 8)); if (i >= 3 && i <= 8) { fprintf(stderr, "WORKS!!!\n"); } array[i] = 4; } return 0; } -- Summary: Icorrect optimization while declaring array[1] Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ogoffart at kde dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/43247] Icorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org @ 2010-03-03 14:42 ` thiago at kde dot org 2010-03-03 14:44 ` thiago at kde dot org ` (8 subsequent siblings) 9 siblings, 0 replies; 15+ messages in thread From: thiago at kde dot org @ 2010-03-03 14:42 UTC (permalink / raw) To: gcc-bugs ------- Comment #1 from thiago at kde dot org 2010-03-03 14:41 ------- Problem also happens on: gcc 4.4.3 on linux 32-bit gcc 4.4.1 on linux ARM (armel gnueabi) Also reproducible with -O1 -ftree-vrp. -- thiago at kde dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |thiago at kde dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/43247] Icorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org 2010-03-03 14:42 ` [Bug c++/43247] " thiago at kde dot org @ 2010-03-03 14:44 ` thiago at kde dot org 2010-03-03 16:08 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org ` (7 subsequent siblings) 9 siblings, 0 replies; 15+ messages in thread From: thiago at kde dot org @ 2010-03-03 14:44 UTC (permalink / raw) To: gcc-bugs ------- Comment #2 from thiago at kde dot org 2010-03-03 14:44 ------- Also: -O1 -ftree-vrp -fno-cprop-registers -fno-defer-pop -fno-guess-branch-probability -fno-if-conversion -fno-if-conversion2 -fno-ipa-pure-const -fno-ipa-reference -fno-merge-constants -fno-omit-frame-pointer -fno-split-wide-types -fno-tree-ch -fno-tree-copy-prop -fno-tree-copyrename -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-fre -fno-tree-sink -fno-tree-sra -fno-tree-ter However, if I add -fno-tree-ccp, the program starts to work as expected again. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Icorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org 2010-03-03 14:42 ` [Bug c++/43247] " thiago at kde dot org 2010-03-03 14:44 ` thiago at kde dot org @ 2010-03-03 16:08 ` rguenth at gcc dot gnu dot org 2010-03-15 15:03 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect " rguenth at gcc dot gnu dot org ` (6 subsequent siblings) 9 siblings, 0 replies; 15+ messages in thread From: rguenth at gcc dot gnu dot org @ 2010-03-03 16:08 UTC (permalink / raw) To: gcc-bugs ------- Comment #3 from rguenth at gcc dot gnu dot org 2010-03-03 16:08 ------- Confirmed. -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Component|c++ |tree-optimization Ever Confirmed|0 |1 Keywords| |wrong-code Known to fail| |4.3.0 4.3.4 4.4.3 Known to work| |4.2.4 4.5.0 Last reconfirmed|0000-00-00 00:00:00 |2010-03-03 16:08:00 date| | Summary|Icorrect optimization while |[4.3/4.4 Regression] |declaring array[1] |Icorrect optimization while | |declaring array[1] Target Milestone|--- |4.3.5 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org ` (2 preceding siblings ...) 2010-03-03 16:08 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org @ 2010-03-15 15:03 ` rguenth at gcc dot gnu dot org 2010-03-26 18:46 ` pinskia at gcc dot gnu dot org ` (5 subsequent siblings) 9 siblings, 0 replies; 15+ messages in thread From: rguenth at gcc dot gnu dot org @ 2010-03-15 15:03 UTC (permalink / raw) To: gcc-bugs -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org ` (3 preceding siblings ...) 2010-03-15 15:03 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect " rguenth at gcc dot gnu dot org @ 2010-03-26 18:46 ` pinskia at gcc dot gnu dot org 2010-03-26 18:54 ` hjl dot tools at gmail dot com ` (4 subsequent siblings) 9 siblings, 0 replies; 15+ messages in thread From: pinskia at gcc dot gnu dot org @ 2010-03-26 18:46 UTC (permalink / raw) To: gcc-bugs ------- Comment #4 from pinskia at gcc dot gnu dot org 2010-03-26 18:46 ------- *** Bug 43537 has been marked as a duplicate of this bug. *** -- pinskia at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |juha dot kallioinen at nokia | |dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org ` (4 preceding siblings ...) 2010-03-26 18:46 ` pinskia at gcc dot gnu dot org @ 2010-03-26 18:54 ` hjl dot tools at gmail dot com 2010-03-26 21:46 ` thiago at kde dot org ` (3 subsequent siblings) 9 siblings, 0 replies; 15+ messages in thread From: hjl dot tools at gmail dot com @ 2010-03-26 18:54 UTC (permalink / raw) To: gcc-bugs ------- Comment #5 from hjl dot tools at gmail dot com 2010-03-26 18:54 ------- This is fixed by revision 151360: http://gcc.gnu.org/ml/gcc-cvs/2009-09/msg00106.html and was introduced by revision 118729: http://gcc.gnu.org/ml/gcc-cvs/2006-11/msg00380.html -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org ` (5 preceding siblings ...) 2010-03-26 18:54 ` hjl dot tools at gmail dot com @ 2010-03-26 21:46 ` thiago at kde dot org 2010-03-27 10:46 ` rguenth at gcc dot gnu dot org ` (2 subsequent siblings) 9 siblings, 0 replies; 15+ messages in thread From: thiago at kde dot org @ 2010-03-26 21:46 UTC (permalink / raw) To: gcc-bugs ------- Comment #6 from thiago at kde dot org 2010-03-26 21:46 ------- Is this fix going to be backported to the 4.4.x line? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org ` (6 preceding siblings ...) 2010-03-26 21:46 ` thiago at kde dot org @ 2010-03-27 10:46 ` rguenth at gcc dot gnu dot org 2010-03-27 14:25 ` hjl dot tools at gmail dot com 2010-05-22 18:35 ` rguenth at gcc dot gnu dot org 9 siblings, 0 replies; 15+ messages in thread From: rguenth at gcc dot gnu dot org @ 2010-03-27 10:46 UTC (permalink / raw) To: gcc-bugs ------- Comment #7 from rguenth at gcc dot gnu dot org 2010-03-27 10:45 ------- I very much doubt that the cited revision fixed anything here. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org ` (7 preceding siblings ...) 2010-03-27 10:46 ` rguenth at gcc dot gnu dot org @ 2010-03-27 14:25 ` hjl dot tools at gmail dot com 2010-05-22 18:35 ` rguenth at gcc dot gnu dot org 9 siblings, 0 replies; 15+ messages in thread From: hjl dot tools at gmail dot com @ 2010-03-27 14:25 UTC (permalink / raw) To: gcc-bugs ------- Comment #8 from hjl dot tools at gmail dot com 2010-03-27 14:24 ------- (In reply to comment #7) > I very much doubt that the cited revision fixed anything here. > If it is true, that only means that the bug is latent on trunk. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org ` (8 preceding siblings ...) 2010-03-27 14:25 ` hjl dot tools at gmail dot com @ 2010-05-22 18:35 ` rguenth at gcc dot gnu dot org 9 siblings, 0 replies; 15+ messages in thread From: rguenth at gcc dot gnu dot org @ 2010-05-22 18:35 UTC (permalink / raw) To: gcc-bugs ------- Comment #9 from rguenth at gcc dot gnu dot org 2010-05-22 18:13 ------- GCC 4.3.5 is being released, adjusting target milestone. -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|4.3.5 |4.3.6 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 ^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <bug-43247-4@http.gcc.gnu.org/bugzilla/>]
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] [not found] <bug-43247-4@http.gcc.gnu.org/bugzilla/> @ 2010-12-22 10:35 ` thiago at kde dot org 2010-12-22 17:49 ` pinskia at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 15+ messages in thread From: thiago at kde dot org @ 2010-12-22 10:35 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 --- Comment #10 from Thiago Macieira <thiago at kde dot org> 2010-12-22 10:35:23 UTC --- This is still not fixed. I can reproduce now with a different testcase, in 4.5.1. However, this time, the same code works fine in 4.4. The reason is again accessing an array out-of-bounds for elements that we know to be there. Pay attention to the way operator== is implemented in the following code. If I compile it with -O1, it prints "true" as it should. If I compile it with -O2, it prints "false". If I compile it with -O1 -finline-small-functions -finline -findirect-inlining -fstrict-overflow and compare the disassembly with -O2 and a suitable list of -fno-*, the code is exactly identical, except for some instructions that should perform the copy of half of m1's data into m3. So in the end the comparison fails due to comparing to garbage. === code === #include <stdio.h> template <int N, int M, typename T> class QGenericMatrix { public: QGenericMatrix(); QGenericMatrix(const QGenericMatrix<N, M, T>& other); explicit QGenericMatrix(const T *values); bool operator==(const QGenericMatrix<N, M, T>& other) const; private: T m[N][M]; // Column-major order to match OpenGL. QGenericMatrix(int) {} // Construct without initializing identity matrix }; template <int N, int M, typename T> QGenericMatrix<N, M, T>::QGenericMatrix(const QGenericMatrix<N, M, T>& other) { for (int col = 0; col < N; ++col) for (int row = 0; row < M; ++row) m[col][row] = other.m[col][row]; } template <int N, int M, typename T> QGenericMatrix<N, M, T>::QGenericMatrix(const T *values) { for (int col = 0; col < N; ++col) for (int row = 0; row < M; ++row) m[col][row] = values[row * N + col]; } template <int N, int M, typename T> bool QGenericMatrix<N, M, T>::operator==(const QGenericMatrix<N, M, T>& other) const { for (int index = 0; index < N * M; ++index) { if (m[0][index] != other.m[0][index]) return false; } return true; } typedef double qreal; typedef QGenericMatrix<2, 2, qreal> QMatrix2x2; int main(int , char**) { qreal m1Data[] = {0.0, 0.0, 0.0, 0.0}; QMatrix2x2 m1(m1Data); QMatrix2x2 m3 = m1; puts((m1 == m3) ? "true" : "false"); } === code === common args: -fno-exceptions -fno-rtti -fverbose-asm -march=core2 -mfpmath=sse (though x87 math also shows the same problem) prints "true" with: -O1 -finline-small-functions -finline -findirect-inlining -fstrict-overflow prints "false" with: -O2 -fno-align-functions -fno-align-jumps -fno-align-labels -fno-caller-saves -fno-tree-switch-conversion -fno-tree-vrp -fno-crossjumping -fno-cse-follow-jumps -fno-expensive-optimizations -fno-gcse -fno-ipa-cp -fno-ipa-sra -fno-optimize-register-move -fno-optimize-sibling-calls -fno-peephole2 -fno-regmove -fno-reorder-blocks -fno-reorder-functions -fno-rerun-cse-after-loop -fno-schedule-insns2 -fno-strict-aliasing -fno-strict-aliasing -fno-thread-jumps -fno-tree-builtin-call-dce -fno-tree-pre ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] [not found] <bug-43247-4@http.gcc.gnu.org/bugzilla/> 2010-12-22 10:35 ` thiago at kde dot org @ 2010-12-22 17:49 ` pinskia at gcc dot gnu.org 2010-12-22 19:55 ` thiago at kde dot org 2011-06-27 14:31 ` rguenth at gcc dot gnu.org 3 siblings, 0 replies; 15+ messages in thread From: pinskia at gcc dot gnu.org @ 2010-12-22 17:49 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Known to work| | Known to fail| | --- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-12-22 17:48:55 UTC --- >The reason is again accessing an array out-of-bounds for elements that we know to be there. No that is undefined and different from the original testcase. ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] [not found] <bug-43247-4@http.gcc.gnu.org/bugzilla/> 2010-12-22 10:35 ` thiago at kde dot org 2010-12-22 17:49 ` pinskia at gcc dot gnu.org @ 2010-12-22 19:55 ` thiago at kde dot org 2011-06-27 14:31 ` rguenth at gcc dot gnu.org 3 siblings, 0 replies; 15+ messages in thread From: thiago at kde dot org @ 2010-12-22 19:55 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 --- Comment #12 from Thiago Macieira <thiago at kde dot org> 2010-12-22 19:55:38 UTC --- (In reply to comment #11) > >The reason is again accessing an array out-of-bounds for elements that we know to be there. > > No that is undefined and different from the original testcase. Ok. Shall I open a new report with the new information? ^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect optimization while declaring array[1] [not found] <bug-43247-4@http.gcc.gnu.org/bugzilla/> ` (2 preceding siblings ...) 2010-12-22 19:55 ` thiago at kde dot org @ 2011-06-27 14:31 ` rguenth at gcc dot gnu.org 3 siblings, 0 replies; 15+ messages in thread From: rguenth at gcc dot gnu.org @ 2011-06-27 14:31 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43247 Richard Guenther <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|4.3.6 |4.4.7 --- Comment #13 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-06-27 12:14:08 UTC --- 4.3 branch is being closed, moving to 4.4.7 target. ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2011-06-27 14:31 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2010-03-03 14:37 [Bug c++/43247] New: Icorrect optimization while declaring array[1] ogoffart at kde dot org 2010-03-03 14:42 ` [Bug c++/43247] " thiago at kde dot org 2010-03-03 14:44 ` thiago at kde dot org 2010-03-03 16:08 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org 2010-03-15 15:03 ` [Bug tree-optimization/43247] [4.3/4.4 Regression] Incorrect " rguenth at gcc dot gnu dot org 2010-03-26 18:46 ` pinskia at gcc dot gnu dot org 2010-03-26 18:54 ` hjl dot tools at gmail dot com 2010-03-26 21:46 ` thiago at kde dot org 2010-03-27 10:46 ` rguenth at gcc dot gnu dot org 2010-03-27 14:25 ` hjl dot tools at gmail dot com 2010-05-22 18:35 ` rguenth at gcc dot gnu dot org [not found] <bug-43247-4@http.gcc.gnu.org/bugzilla/> 2010-12-22 10:35 ` thiago at kde dot org 2010-12-22 17:49 ` pinskia at gcc dot gnu.org 2010-12-22 19:55 ` thiago at kde dot org 2011-06-27 14:31 ` rguenth at gcc dot gnu.org
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).