Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang 15 fails to compile program using smmintrin.h on ppc64el #64664

Closed
madscientist159 opened this issue Aug 14, 2023 · 5 comments · Fixed by #67299
Closed

clang 15 fails to compile program using smmintrin.h on ppc64el #64664

madscientist159 opened this issue Aug 14, 2023 · 5 comments · Fixed by #67299
Assignees
Labels
backend:PowerPC clang:headers Headers provided by Clang, e.g. for intrinsics

Comments

@madscientist159
Copy link

Updating Clang to version 15 yields new compilation errors on an existing program that includes the smmintrin.h compatibility header. These errors originate from within Clang's own internal header files, not from the application itself.

/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:71:25: error: use of undeclared identifier '__builtin_mffs'
    __fpscr_save.__fr = __builtin_mffs();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:74:5: error: use of undeclared identifier '__builtin_mtfsf'
    __builtin_mtfsf(0b00000011, __fpscr_save.__fr);
    ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:86:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
    __fpscr_save.__fr = __builtin_mffsl();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:89:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
    __builtin_set_fpscr_rn(0b00);
    ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:105:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
    __builtin_set_fpscr_rn(__fpscr_save.__fpscr);
    ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:131:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
    __fpscr_save.__fr = __builtin_mffsl();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
    __fpscr_save.__fr = __builtin_mffsl();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:133:5: error: use of undeclared identifier '__builtin_mtfsf'
    __builtin_mtfsf(0b00000011, __fpscr_save.__fr);
    ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:162:25: error: use of undeclared identifier '__builtin_mffs'
    __fpscr_save.__fr = __builtin_mffs();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:165:5: error: use of undeclared identifier '__builtin_mtfsf'
    __builtin_mtfsf(0b00000011, __fpscr_save.__fr);
    ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:177:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
    __fpscr_save.__fr = __builtin_mffsl();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
    __fpscr_save.__fr = __builtin_mffsl();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:180:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
    __builtin_set_fpscr_rn(0b00);
    ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:196:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
    __builtin_set_fpscr_rn(__fpscr_save.__fpscr);
    ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:222:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
    __fpscr_save.__fr = __builtin_mffsl();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
    __fpscr_save.__fr = __builtin_mffsl();
                        ^
/usr/lib/llvm-15/lib/clang/15.0.7/include/ppc_wrappers/smmintrin.h:224:5: error: use of undeclared identifier '__builtin_mtfsf'
    __builtin_mtfsf(0b00000011, __fpscr_save.__fr);

This issue may have been introduced in this patch series:
https://reviews.llvm.org/D119407

@EugeneZelenko EugeneZelenko added backend:PowerPC clang:headers Headers provided by Clang, e.g. for intrinsics and removed new issue labels Aug 14, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 14, 2023

@llvm/issue-subscribers-backend-powerpc

@EugeneZelenko
Copy link
Contributor

Could you please try 17 or main branch? https://godbolt.org should be helpful.

@madscientist159
Copy link
Author

madscientist159 commented Aug 14, 2023

I can try in a few days, the application is quite large so would need to ensure the rest of it builds enough with 17 to get to the same point.

That said, I highly doubt 17 or main are fixed, since the builtins are not present in clang/include/clang/Basic/BuiltinsPPC.def and the offending calls are still present in clang/lib/Headers/ppc_wrappers/smmintrin.h

@ecnelises ecnelises self-assigned this Aug 14, 2023
@nemanjai
Copy link
Member

I can confirm that this is NOT fixed in trunk. It "works" with C, but not with C++. Namely, it compiles in C files as long as one does not use the builtins that haven't been implemented. Presumably a call to a function such as _mm_round_pd will emit calls to bogus functions such as __builtin_mffs on CPU's prior to Power9.

The frustrating thing is that I think we have previously had a similar issue where these wrappers don't work on C++ and we've clearly either not fixed them all or we've introduced new ones. We need to add C++ test cases for all of these wrappers on top of the C tests that we have (and we should test with -mcpu=pwr9/-mcpu=pwr8).

A simple test case that shows the offending builtins just in this file:

#include <smmintrin.h>

int main(int argc, const char **argv) {
  return 3;
}

Compilation:

$ clang++ -S t.cpp -DNO_WARN_X86_INTRINSICS
In file included from t.cpp:1:
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:71:25: error: use of undeclared identifier '__builtin_mffs'
   71 |     __fpscr_save.__fr = __builtin_mffs();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:74:5: error: use of undeclared identifier '__builtin_mtfsf'
   74 |     __builtin_mtfsf(0b00000011, __fpscr_save.__fr);
      |     ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:86:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
   86 |     __fpscr_save.__fr = __builtin_mffsl();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:89:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
   89 |     __builtin_set_fpscr_rn(0b00);
      |     ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:105:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
  105 |     __builtin_set_fpscr_rn(__fpscr_save.__fpscr);
      |     ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:131:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
  131 |     __fpscr_save.__fr = __builtin_mffsl();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
   86 |     __fpscr_save.__fr = __builtin_mffsl();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:133:5: error: use of undeclared identifier '__builtin_mtfsf'
  133 |     __builtin_mtfsf(0b00000011, __fpscr_save.__fr);
      |     ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:162:25: error: use of undeclared identifier '__builtin_mffs'
  162 |     __fpscr_save.__fr = __builtin_mffs();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:165:5: error: use of undeclared identifier '__builtin_mtfsf'
  165 |     __builtin_mtfsf(0b00000011, __fpscr_save.__fr);
      |     ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:177:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
  177 |     __fpscr_save.__fr = __builtin_mffsl();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
   86 |     __fpscr_save.__fr = __builtin_mffsl();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:180:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
  180 |     __builtin_set_fpscr_rn(0b00);
      |     ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:196:5: error: use of undeclared identifier '__builtin_set_fpscr_rn'
  196 |     __builtin_set_fpscr_rn(__fpscr_save.__fpscr);
      |     ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:222:25: error: use of undeclared identifier '__builtin_mffsl'; did you mean '__builtin_infl'?
  222 |     __fpscr_save.__fr = __builtin_mffsl();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:86:25: note: '__builtin_infl' declared here
   86 |     __fpscr_save.__fr = __builtin_mffsl();
      |                         ^
/home/ubuntu/nemanjai/llvm/trunk1/build/lib/clang/18/include/ppc_wrappers/smmintrin.h:224:5: error: use of undeclared identifier '__builtin_mtfsf'
  224 |     __builtin_mtfsf(0b00000011, __fpscr_save.__fr);
      |     ^
14 errors generated.

@ecnelises
Copy link
Member

ecnelises added a commit to ecnelises/llvm-project that referenced this issue Oct 10, 2023
smmintrin.h uses __builtin_mffs, __builtin_mffsl, __builtin_mtfsf and
__builtin_set_fpscr_rn. This patch replaces the uses with ppc prefix and
implement the missing ones.

This fixes issue llvm#64664.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:PowerPC clang:headers Headers provided by Clang, e.g. for intrinsics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants