use lvx instead of lxvd2x and xxswapd when address is assumed to be aligned
| Bugzilla Link | 30730 |
| Resolution | FIXED |
| Resolved on | May 24, 2017 10:42 |
| Version | trunk |
| OS | Linux |
| CC | @weiguozhi,@echristo,@hfinkel,@lei137,@nemanjai |
Extended Description
Power9 has a little endian load here that it can use for unaligned addresses, but for power8 this is still important.
#include <altivec.h>
struct S { vector int v; vector int f() const; };
vector int S::f() const { return v; }
AltiVec code:
.text
.abiversion 2
.file "aligned_load.cc"
.globl _ZNK1S1fEv
.p2align 4
.type _ZNK1S1fEv,@function
_ZNK1S1fEv: # @_ZNK1S1fEv .Lfunc_begin0:
BB#0:
lvx 2, 0, 3
blr
.long 0
.quad 0
.Lfunc_end0: .size _ZNK1S1fEv, .Lfunc_end0-.Lfunc_begin0
VSX code
.text
.abiversion 2
.file "aligned_load.cc"
.globl _ZNK1S1fEv
.p2align 4
.type _ZNK1S1fEv,@function
_ZNK1S1fEv: # @_ZNK1S1fEv .Lfunc_begin0:
BB#0:
lxvd2x 0, 0, 3
xxswapd 34, 0
# kill: %V2<def> %V2<kill> %VSH2<kill>
blr
.long 0
.quad 0
.Lfunc_end0: .size _ZNK1S1fEv, .Lfunc_end0-.Lfunc_begin0
Committed revision: rL301892
Tim is fixing a bunch of internal and external code and then we'll go ahead and put this back in.
Reverted a bit ago, the patch was fine, but uncovered a lot of code that was depending on the 8byte aligned behavior when they said they had 16-byte aligned code.
So what's the plan?
Reverted a bit ago, the patch was fine, but uncovered a lot of code that was depending on the 8byte aligned behavior when they said they had 16-byte aligned code.
Fixed in review: https://reviews.llvm.org/D26861 Committed revision 287679.
We can probably fix this in a couple of ways:
- Don't expand a load to PPCISD::LXVD2X + PPCISD::XXSWAPD when the load is aligned and the type is a vector with elements up to 4 bytes
- Pick it up in the PPCMIPeephole.cpp and check for alignment and the target register of the swap being in the upper half of the VSX registers
- Pick it up in PPCVSXSwapRemoval.cpp and convert the LXVD2X and subsequent XXSWAPD into an LVX under the same conditions
I have not investigated the latter two but I don't imagine they're overly difficult. The first one is easy but it has the disadvantage that we can still not do anything if the type is MVT::v2i64 or MVT::v2f64.
Perhaps Eric and Hal can comment on whether you guys feel this is worthwhile and which approach you would prefer.
Sounds like the first option might be the best.
This is a good thing to do.
Because swap removal in LLVM is still relatively primitive, having mixed LVX and LXVD2X loads may inhibit swap removal that otherwise would take place. You may need to update the algorithm to be aware of the non-swapping loads. It may be beneficial to introduce a swap following an LVX or prior to an STVX in order to remove multiple swaps associated with LXVD2X or STXVD2X.
In general you should make the decision to create an LVX outside of swap removal, as many expressions are not subject to swap removal for other reasons (passing vectors across function boundaries, etc.). Thus doing this inside swap removal would miss opportunities, including the one that Eric used as an example.
- Bill for his expertise on swap removal.
We can probably fix this in a couple of ways:
- Don't expand a load to PPCISD::LXVD2X + PPCISD::XXSWAPD when the load is aligned and the type is a vector with elements up to 4 bytes
- Pick it up in the PPCMIPeephole.cpp and check for alignment and the target register of the swap being in the upper half of the VSX registers
- Pick it up in PPCVSXSwapRemoval.cpp and convert the LXVD2X and subsequent XXSWAPD into an LVX under the same conditions
I have not investigated the latter two but I don't imagine they're overly difficult. The first one is easy but it has the disadvantage that we can still not do anything if the type is MVT::v2i64 or MVT::v2f64.
Perhaps Eric and Hal can comment on whether you guys feel this is worthwhile and which approach you would prefer.
assigned to @lei137