This is an archive of the discontinued LLVM Phabricator instance.

[libc++abi][LIT][AIX] Use Vector instructions available on Power7 in vec_reg_restore.pass.cpp
ClosedPublic

Authored by xingxue on Nov 24 2022, 6:43 AM.

Details

Summary

libc++abi LIT test case vec_reg_restore.pass.cpp for AIX uses instructions mtvsrd and mfvsrd that are only available on Power8 CPU and higher, and therefore, fails on Power7 which is supported by the current AIX Clang. This patch replaces mtvsrd/mfvsrd with vector instructions available on Power7.

Diff Detail

Event Timeline

xingxue created this revision.Nov 24 2022, 6:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2022, 6:43 AM
xingxue requested review of this revision.Nov 24 2022, 6:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2022, 6:43 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
ldionne accepted this revision as: Restricted Project.Nov 24 2022, 10:54 AM
ldionne added a subscriber: ldionne.

Getting libc++ out of the way. If it looks good to AIX folks, feel free to ship it.

Also, can someone on your side please take a look at the CI failures? They've been ongoing for some days now.

Getting libc++ out of the way. If it looks good to AIX folks, feel free to ship it.

Thanks!

Also, can someone on your side please take a look at the CI failures? They've been ongoing for some days now.

Will do.

nemanjai added inline comments.Nov 24 2022, 7:47 PM
libcxxabi/test/vendor/ibm/vec_reg_restore.pass.cpp
45

This test case can be significantly simplified by just materializing a value into the callee-saved registers you're looking to clobber. This implementation is potentially problematic because:

  • It is not immediately obvious what this is doing
  • I believe that the use of "r" asm constraint here for a memory location isn't what we want (I think "Z" or at least "b" would be needed here as the register cannot be r0).

I would recommend just something like this:

// Set vs63 to 16 bytes each with value 9
asm volatile("vspltisb 31, 9" : : : "v31");

// Set vs62 to 16 bytes each with value 12
asm volatile("vspltisb 30, 12" : : : "v30")
67–83

I understand that this was here in the original test case, but I find it odd that we are comparing just the first doubleword of each vector. Although it is unlikely, we would miss any corruption in the second doubleword of each vector.

87

Similarly here, we can simply set the vector registers to different values using vspltisb.

113–114

Rather than doing this, what I would recommend is that we populate 2 new vectors with expected values and then compare them against v31/v30 using vcmpequb..
You can use something like this for comparing the vectors:

#define cmp63(vec, res) { \
  vector unsigned char gbg; \
  asm volatile("vcmpequb. %[gbg], 31, %[veca];" \
               "mfocrf %[res], 2;" \
               "rlwinm %[res], %[res], 25, 31, 31" \
               : [res] "=r" (res), [gbg] "=v" (gbg) \
               : [veca] "v" (vec) \
               : "cr6" \
              ); \
}

#define cmp62(vec, res) { \
  vector unsigned char gbg; \
  asm volatile("vcmpequb. %[gbg], 30, %[veca];" \
               "mfocrf %[res], 2;" \
               "rlwinm %[res], %[res], 25, 31, 31" \
               : [res] "=r" (res), [gbg] "=v" (gbg) \
               : [veca] "v" (vec) \
               : "cr6" \
              ); \
}

The results for these two will be placed in variable you pass as the second operand to the macro and the value should be 1 if the vectors are equal.

xingxue updated this revision to Diff 478002.Nov 25 2022, 10:43 AM
xingxue edited the summary of this revision. (Show Details)

Addressed comments:

  • use instruction vspltisb to initialize RS63, RS62
  • set RS63, RS62 to 16 bytes each with value 0x01 and 0x02 respectively
  • compare RS63/RS62 against expected values using instruction vcmpequb
xingxue marked 4 inline comments as done.Nov 25 2022, 10:47 AM
xingxue added inline comments.
libcxxabi/test/vendor/ibm/vec_reg_restore.pass.cpp
45

Good idea, changed as suggested. Thanks!

67–83

Changed to comparing all 16 bytes as suggested, thanks!

87

Changed as suggested, thanks!

113–114

Good suggestion, changed. Thanks!

xingxue marked 4 inline comments as done.Nov 25 2022, 11:26 AM
nemanjai accepted this revision.Nov 28 2022, 10:27 AM

LGTM. Thanks for fixing this test case.

This revision is now accepted and ready to land.Nov 28 2022, 10:27 AM
This revision was landed with ongoing or failed builds.Nov 29 2022, 11:09 AM
This revision was automatically updated to reflect the committed changes.