Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
4 Views

Incorrect -O2 and -O3 Optimization for Cascading if-else

/*
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);
}

0 Kudos
4 Replies
Highlighted
Employee
4 Views

Thanks for the problem report. We will investigate and get back to you.

--mark
0 Kudos
Highlighted
Employee
4 Views

I reproduced the problem and filed a report on this issue. We will let you know when the issue is resolved.

Thanks,
--mark
0 Kudos
Highlighted
Employee
4 Views

The development team believe they have resolved this issue. I will let you know when a compiler containing the fix becomes available.

Thanks,
--mark
0 Kudos
Highlighted
Employee
4 Views

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
Program reports incorrect results due to HLO Early Predicates Optimization
0 Kudos