[libcxx-commits] [PATCH] D137599: [libunwind][PowerPC] Fix saving/restoring VSX registers on LE systems

Xing Xue via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 21 09:13:17 PST 2022


xingxue added a comment.

The compiler generated prologue/epilogue uses instructions `stvx`/`lvx` to save/restore vector registers onto/from the stack. On the other hand, libunwind currently uses `stxvd2x`/`lxvd2x` to save/restore VSX vector to/from unwinder's `context`. Since `stxvd2x`/`lxvd2x` stores/loads VSX vector as  2 `double` words into/from memory, these instructions essentially change the byte orders of the contents if the machine is in little-endian mode. As a result, VSX vectors saved by prologues are not correctly represented in the unwinder `context`. PowerPC ISA 3.0 (Power9) has added instructions `stxv`/`lxv` that stores/loads VSX vectors and matches the behavior of `stvx`/`lvx`. Unfortunately, since supporting of older PowerPCs such as Power8 and earlier are still needed, we cannot replace `stxvd2x`/`lxvd2x` with `stvx`/`lvx` yet. Checking if the build system has the GLIBC facility for detecting the CPU architecture, and detecting at run time and going a different path add a lot of complicity to the code base. IMHO, we can simply add instruction `xxswapd` to before `stxvd2x` and after `lxvd2x` for little-endian like in your patch as a workaround for now. `xxswapd` is not an expensive instruction so it is unlikely to affect the performance in a significant way, noting that saving and restoring context are only executed when raising an exception and jumping to the landing pad. It will be good though to have a comment stating that we should replace them with `stvx`/`lvx` once only Power9 and higher are supported for little-endian PowerPC (RHEL 9.0 already supports minimum Power9).  Thanks very much for working on this issue!

We probably can adapt test case `libcxxabi/test/vendor/ibm/vec_reg_restore.pass.cpp` to cover little-endian Linux on Power as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137599/new/

https://reviews.llvm.org/D137599



More information about the libcxx-commits mailing list