APAR status
Closed as program error.
Error description
The compiler causes the program below to give incorrect with -O3 optimization but correct results with -O2 and -O3 -qstrict. This program initializes an array marking the locations of negative numbers in another array using the following loop: for (int i = 0; i < n; ++i ) { c[i] = (x[i] < 0.0) ? 1 : 0; } When compiling the program below with -O2 it produces correct results: $ xlc++_r -O2 -std=c++14 ./test.cpp -o rO2 $ ./rO2 -- x 0.500000 -0.500000 0.500000 -0.500000 -- c 0 1 0 1 $ As well when compiling the program with -O3 -qstrict it produces correct results: $ xlc++_r -O3 -qstrict -std=c++14 ./reproducer.cpp -o rO3-qstrict $ ./rO3-qstrict -- x 0.500000 -0.500000 0.500000 -0.500000 -- c 0 1 0 1 $ Using the -O3 produces the incorrect results: $ xlc++_r -O3 -std=c++14 ./reproducer.cpp -o rO3 $ ./rO3 -- x 0.500000 -0.500000 0.500000 -0.500000 -- c 0 0 1 1 Error: c[1] == 0 but x[1] == -0.500000 Error: c[2] == 1 but x[2] == 0.500000 $ ====TESTCASE: $ cat test.cpp #include <cstdio> #include <cstdlib> #include <cassert> int main(int argc, char** argv) { int n = (argc > 1) ? atoi(argv[1]) : 4; // set n with first arg int p = (argc > 2) ? atoi(argv[2]) : 1; // enable printing with second arg double* x = (double*)malloc(n*sizeof(double)); int* c = (int*)malloc((n+1)*sizeof(int)); // make list of alternating positive and negative numbers for (int i = 0; i < n; ++i) { x[i] = -1.0 * (i % 2) + 0.5; }; if (p) { printf(" -- x"); for (int i = 0; i < n; ++i ) { printf(" %f", x[i]); } printf("\n"); } // make list marking negative numbers with 1, positive with 0 // with -O3 and (n >= 4) c[1] is incorrectly set to 0 despite x[1] == -0.5 for (int i = 0; i < n; ++i ) { c[i] = (x[i] < 0.0) ? 1 : 0; } if (p) { printf(" -- c"); for (int i = 0; i < n; ++i ) { printf(" %i", c[i]); } printf("\n"); } for (int i = 0; i < n; ++i ) { if (c[i] == 0 && x[i] < 0.0) { printf("Error: c[%i] == 0 but x[%i] == %f\n", i, i, x[i]); } if (c[i] == 1 && x[i] >= 0.0) { printf("Error: c[%i] == 1 but x[%i] == %f\n", i, i, x[i]); } } free(x); free(c); return 0; } $
Local fix
adding -qstrict to compile line
Problem summary
USERS AFFECTED: users using -O3 optimization are affected PROBLEM DESCRIPTION: Compiler generates bad code at vectorization.
Problem conclusion
Fixed the length mismatch between scalar and vector elements when extracting from a vector.
Temporary fix
Comments
APAR Information
APAR number
LI82605
Reported component name
XL C/C++ LINUX
Reported component ID
5725C7310
Reported release
G11
Status
CLOSED PER
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt / Xsystem
Submitted date
2022-08-31
Closed date
2022-09-19
Last modified date
2022-09-19
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
LI82645
Fix information
Fixed component name
XL C/C++ LINUX
Fixed component ID
5725C7310
Applicable component levels
[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSXVZZ","label":"XL C\/C++ for Linux"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"G11","Line of Business":{"code":"LOB57","label":"Power"}}]
Document Information
Modified date:
19 September 2022