This is an archive of the discontinued LLVM Phabricator instance.

[SLPVectorizer] Don't ignore scalar extraction instructions of aggregate value
ClosedPublic

Authored by Carrot on Dec 12 2017, 3:36 PM.

Details

Summary

For code like

struct S {

void* p;
void* q;

};

static S kS0;

S getS() {

return kS0;

}

LLVM generate following instructions for ppc

lxvx 0, 0, 3
mfvsrld 3, 0
mfvsrd 4, 0

Ideal result should be just

ld 3, 0(4)
ld 4, 8(4)

The problem is in SLPVectorizer, the vector build instructions (insertvalue for aggregate type) is passed to BoUpSLP.buildTree, it is treated as UserIgnoreList, so later in cost estimation, the cost of these instructions are not counted.
For aggregate value, later usage are more likely to be done in integer registers, either used as individual scalars or used as a whole for function call or return value. So for vectorization of aggregate value, the scalar extraction instructions are required in cost estimation.

Diff Detail

Repository
rL LLVM

Event Timeline

Carrot created this revision.Dec 12 2017, 3:36 PM
hfinkel accepted this revision.Dec 12 2017, 7:22 PM

The current code generation is also odd on x86 (for the same reason). Returning the aggregate forces the values to be placed in specific GPRs. That makes the vectorization not worthwhile. Can you please also add this test into the X86 directory (running for x86, obviously) as well?

There might be cases where this is not the right thing to do, but nothing comes to mind at the moment. LGTM.

lib/Transforms/Vectorize/SLPVectorizer.cpp
5715 ↗(On Diff #126637)

I'd say "scalar registers" instead of "integer registers" (they might, for example, be floating-point registers).

This revision is now accepted and ready to land.Dec 12 2017, 7:22 PM
Carrot updated this revision to Diff 126830.Dec 13 2017, 1:50 PM
Carrot marked an inline comment as done.

Will check in this patch with a new test case for x86.

This revision was automatically updated to reflect the committed changes.