This is an archive of the discontinued LLVM Phabricator instance.

Load Widened by GVN not Vectorized by SLPVectorizer
Needs ReviewPublic

Authored by karthikthecool on Dec 15 2014, 4:45 AM.

Details

Summary

Hi All,
I needed few inputs regarding a patch on which i'm currently working. For a code such as -

int a[4],b[4],c[4],d[4];
void fn() {

c[0] = a[0]*b[0]+d[0];
c[1] = a[1]*b[1]+d[1];
c[2] = a[2]*b[2]+d[2];
c[3] = a[3]*b[3]+d[3];

}
The current llvm trunc code doesn't vectorize this in 64bit machines as GVN which runs before SLP vectorizer widens the load to 64 bit load and the resulting pattern is not matched by SLP.

I though of 2 approaches to solve the problem-

  1. Add pattern matching capability in SLPVectorizer to recognize the widned load. [Need some input if we have to follow this approach]
    • I'm able to match the pattern such as trunc 32 bit -> load and trunc 32-> lshr->load.

But i'm stuck as i'm not sure how to split the widned 64 bit load to 2 32 bit load to vectorize the same.
I tried Builder.CreateLoad but in a code like -

load i64* bitcast (i32* getelementptr inbounds ([4 x i32]* @a, i64 0, i64 2) to i64*), align 8

I'm unable to get the "getelementptr" info out of the widened load to construct the new load as

load i32* getelementptr inbounds ([4 x i32]* @a, i32 0, i32 2), align 4, !tbaa !1 and 
load i32* getelementptr inbounds ([4 x i32]* @a, i32 0, i32 3), align 4, !tbaa !1

which can be pushed into Operands while creating buildTree_rec.

  1. Run GVN with load widnening only after vectorization to prevent GVN from combining loads before vectorization. [This patch].

Although 1st approach looks more appropriate to me i'm unable to split the widned load to generate the vectorized code. Any inputs in this regard would be of great help.

Please let me know if we should go ahead with approach 1 or 2. If 1 few inputs on how to split the widned load would be of great help.

Thanks and Regards
Karthik Bhat

Diff Detail

Repository
rL LLVM

Event Timeline

karthikthecool retitled this revision from to Load Widened by GVN not Vectorized by SLPVectorizer.
karthikthecool updated this object.
karthikthecool edited the test plan for this revision. (Show Details)
karthikthecool set the repository for this revision to rL LLVM.
karthikthecool added a subscriber: Unknown Object (MLST).