- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/*
Title: Incorrect -O2 and -O3 Optimization for Cascading if-else
Summary: Incorrect if-else optimization options for -O2 and -O3. -O1 is working correctly.
I used the same source to compile under -O1, and -O2/-O3. They give out different
answers. I have used gcc/g++ to compile and verify that -O2/-O3 is not working.
Compiler version: icpc (ICC) 12.0.4 20110427 (Non-commercial version for Linux)
Environment: Fedora 10 64bit
Hardware: Intel Core2 Duo CPU E8500 @ 3.16GHz
Reproduce procedure: save this text into a file name test1.cpp and compile it.
icpc -O1 test1.cpp && ./a.out
126
icpc -O2 test1.cpp && ./a.out
Error, should never reach here for x=1, y=3
....
124
icpc -O3 test1.cpp && ./a.out
Error, should never reach here for x=1, y=3
....
124
*/
#include
int main (int argc, char* argv[]) {
int moveCount = 0, g= 0;
int start = 27;
for (int i = start; i < 90; i ++) {
int x = i % 9, y = i / 9;
if (y == 4 || y == 3) {
if (x % 2 == 0) moveCount = 1;
if (x % 2 == 1) moveCount = 0;
} else if ((y >= 5) && (y <= 8) && (x != 0) && (x != 8)) {
moveCount = 3;
} else if (x == 0 || x == 8 || y == 9) {
moveCount = 3;
if (x == 0 || x == 8) moveCount --;
if (y == 9) moveCount --;
} else {
printf ("Error, should never reach here for x=%d, y=%d\\n", x, y);
}
g+= moveCount;
}
printf ("%d\\n", g);
}
Title: Incorrect -O2 and -O3 Optimization for Cascading if-else
Summary: Incorrect if-else optimization options for -O2 and -O3. -O1 is working correctly.
I used the same source to compile under -O1, and -O2/-O3. They give out different
answers. I have used gcc/g++ to compile and verify that -O2/-O3 is not working.
Compiler version: icpc (ICC) 12.0.4 20110427 (Non-commercial version for Linux)
Environment: Fedora 10 64bit
Hardware: Intel Core2 Duo CPU E8500 @ 3.16GHz
Reproduce procedure: save this text into a file name test1.cpp and compile it.
icpc -O1 test1.cpp && ./a.out
126
icpc -O2 test1.cpp && ./a.out
Error, should never reach here for x=1, y=3
....
124
icpc -O3 test1.cpp && ./a.out
Error, should never reach here for x=1, y=3
....
124
*/
#include
int main (int argc, char* argv[]) {
int moveCount = 0, g= 0;
int start = 27;
for (int i = start; i < 90; i ++) {
int x = i % 9, y = i / 9;
if (y == 4 || y == 3) {
if (x % 2 == 0) moveCount = 1;
if (x % 2 == 1) moveCount = 0;
} else if ((y >= 5) && (y <= 8) && (x != 0) && (x != 8)) {
moveCount = 3;
} else if (x == 0 || x == 8 || y == 9) {
moveCount = 3;
if (x == 0 || x == 8) moveCount --;
if (y == 9) moveCount --;
} else {
printf ("Error, should never reach here for x=%d, y=%d\\n", x, y);
}
g+= moveCount;
}
printf ("%d\\n", g);
}
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the problem report. We will investigate and get back to you.
--mark
--mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I reproduced the problem and filed a report on this issue. We will let you know when the issue is resolved.
Thanks,
--mark
Thanks,
--mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The development team believe they have resolved this issue. I will let you know when a compiler containing the fix becomes available.
Thanks,
--mark
Thanks,
--mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This issue has been resolved in Intel compiler version 12.0 build 20110719 and higher.
$ icpc -V -O3 test1.cpp && ./a.out
Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.0.5.220 Build 20110719
Copyright (C) 1985-2011 Intel Corporation. All rights reserved.
Edison Design Group C/C++ Front End, version 4.1 (Jul 19 2011 18:23:00)
Copyright 1988-2009 Edison Design Group, Inc.
GNU ld (Linux/GNU Binutils) 2.21.51.0.9.20110507
126
Thanks,
--mark
$ icpc -V -O3 test1.cpp && ./a.out
Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.0.5.220 Build 20110719
Copyright (C) 1985-2011 Intel Corporation. All rights reserved.
Edison Design Group C/C++ Front End, version 4.1 (Jul 19 2011 18:23:00)
Copyright 1988-2009 Edison Design Group, Inc.
GNU ld (Linux/GNU Binutils) 2.21.51.0.9.20110507
126
Thanks,
--mark
Program reports incorrect results due to HLO Early Predicates Optimization
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page