3

We are experiencing bad code generation for a source file using IBM XL C/C++ at -O3 on PowerPC platforms. Its surfaces as a hang and it appears a particular loop is not broken.

The problem only surfaces under XL C/C++. Our testing regime indicates the source file is clean of undefined behavior, memory errors and other errata. We also don't receive strict/nostrict warnings from the compiler for the source file.

We want to compile the source file at -O2 instead of -O3. We want to add instrumentation, like a pragma, to the source file so it can be guarded appropriately for the compiler. The instrumentation allows others to wire-in other build systems like Cmake and Autotools and things will "just work" for them. (The necessary information is available in the source and not our makefile).

The IBM manual for the compiler is located at IBM XL C/C++ for AIX, V13.1, but damn if I can find the option.

What is the IBM XL C/C++ equivalent to #pragma GCC optimize? How do we instrument the source code to tell XL C/C++ to use -O2 instead of -O3?

jww
  • 97,681
  • 90
  • 411
  • 885

1 Answers1

4

An IBM XL C/C++ for AIX V13.1 option that you could use to compile that one source file at -O2 is #pragma options optimize=2. Info about it can be found online here or in the PDF here. If you want to override -O3 that has already been specified on the command line, and control it at a function level, you may use #pragma option_override(<your function name>, "opt(level, 2)"). Info about it can be found online here or in the PDF here. You can also achieve the same thing by modifying your Makefile so that one source file gets compiled at -O2 instead of -O3.

Also, are you sure the error message you reported starting with tea.cpp:27:26 came from IBM XL C/C++ for AIX V13.1? It doesn't look like it's in the format of that product's diagnostic messages.

We will continue to monitor for your comments on Stack Overflow (tagging with xlc helps us find it), but you may find you can get a faster response time if you post your questions on our forum at http://ibm.biz/xl-power-compilers-forum, which the IBM compiler development team monitors more actively.

Nicole Trudeau
  • 678
  • 3
  • 8
  • 1
    Thanks @trudeaun. I think you are right about compiler diagnostic. It looks like a GCC message. Regarding `-O2`, we found the sore spot. It was cleared at [Issue 503](https://github.com/weidai11/cryptopp/issues/503). I guess that's the *"As If"* rule C++ rule - compiler writers are allowed to turn a functioning program into a non-functioning one :) – jww Sep 19 '17 at 05:17
  • 1
    Regarding Stack Overflow versus IBM Forums, thank you for monitoring. I don't have a Discuss account and I won't join yet another social network, so I can't use the venue. It would be nice if IBM accepted Google, Facebook, etc. But I understand most companies want to be the service provider to collect the information; and they don't want to be the relying party who has to give up the information. – jww Sep 19 '17 at 05:22
  • 1
    Thanks again @trudeaun. I see what happened with the manual reference. The information you pointed out is in the manual. However, I worked it from the other end: I found `option_override` in the manual on page 441, then I went looking for optimization options around pages 441-445. The problem is, `"opt(level, 2)"` is not discussed in that area of the manual. Other optimizations are, like `unroll` and `nounroll`, but not `"opt(level, 2)"`. I guess I am still learning to use the manual. – jww Sep 19 '17 at 05:42
  • Thanks @jww. IBM Compilers does have a [Facebook account](https://www.facebook.com/IBMcompilers/) if you prefer to communicate that way, but Stack Overflow would be better for others who might run into these same issues later on since the responses are public and can be searched. – Nicole Trudeau Sep 19 '17 at 14:43
  • I've got another source file being miscompiled. Its a Chinese hash function named [`sm3.cpp`](https://github.com/weidai11/cryptopp/blob/master/sm3.cpp). I isolated it with `-O2` in the makefile. I then restored the makefile and added `#pragma options optimize=2`. This is necessary because some people use other build systems (and not our makefile). However, the miscompile is still present. I don't know which of the 12 functions is the problem, so I can't use `#pragma option_override`. Any ideas how to proceed? – jww Dec 31 '17 at 00:23
  • Now open in our bug tracker: [Issue 533, XLC and SM3 failed self tests at -O3](https://github.com/weidai11/cryptopp/issues/553). – jww Dec 31 '17 at 00:40
  • @jww Sorry to hear that you are still having issues. Let's rule out any misuse of the pragma. Some XL pragmas are ignored if there is any code appearing before them, and we would need to double check if this is one of them, but do you have any code appearing in `sm3.cpp` before the `#pragma options optimize=2`? This includes any declarations, including from expanding #include directives. – Nicole Trudeau Jan 02 '18 at 15:15
  • @jww Could you try compiling `sm3.cpp` with `-O2 -qhot=level=0`? If you experience bad code gen, your pass/fail behaviour is likely with the `-qhot=level=0` option being off/on rather than `-O2` vs `-O3`. I will post some more details about why this occurs in a separate comment. – Nicole Trudeau Jan 02 '18 at 19:37
  • @jww You are looking for a way to compile all files with -O3 except sm3.cpp but can't alter your Makefile to just compile sm3.cpp with "-O3 -qnohot" due to some people using other build systems and not your Makefile. You may try using `#pragma novector` in `sm3.cpp` to see if it is accepted to disable `-qhot=level=0` at a source level. It is not supported for nested loops, though. – Nicole Trudeau Jan 02 '18 at 19:37
  • @jww Some more details about `-qhot`: `-O2` implies `-O2 -qnohot` `-O3` implies `-O3 -qhot=level=0` Compiling with `-O3` and adding `#pragma options optimize=2` to `sm3.cpp` will change `-O3` to `-O2`, but the implied `-qhot=level=0` from compiling with `-O3` on the command line/in the Makefile will still be applied. For more info about `-qhot`, please see [Knowledge Center](https://www.ibm.com/support/knowledgecenter/SSGH3R_13.1.0/com.ibm.xlcpp131.aix.doc/compiler_ref/opt_hot.html) – Nicole Trudeau Jan 02 '18 at 19:38