This is an archive of the discontinued LLVM Phabricator instance.

Gather and Scatter intrinsics.
Needs ReviewPublic

Authored by delena on Feb 5 2015, 5:43 AM.

Details

Summary

Gather and Scatter are new introduced intrinsics, comming after recently implemented masked load and store.
This is the first patch for Gather and Scatter intrinsics. A'm asking to review the syntax (we discussed in mails), parsing and verification.

Gather and Scatter intrinsics allow to perform multiple memory accesses (read/write) in one vector instruction.
The intrinsics are not target specific and will have the following syntax:
Gather:
declare <16 x i32> @llvm.masked.gather.v16i32(<16 x i32*> <vector of ptrs>, i32 <alignment>, <16 x i1> <mask>, <16 x i32> <passthru>)
declare <8 x float> @llvm.masked.gather.v8f32(<8 x float*><vector of ptrs>, i32 <alignment>, <8 x i1> <mask>, <8 x float><passthru>)

Scatter:
declare void @llvm.masked.scatter.v8i32(<8 x i32><vector value to be stored> , <8 x i32*><vector of ptrs> , i32 <alignment>, <8 x i1> <mask>)
declare void @llvm.masked.scatter.v16i32(<16 x i32> <vector value to be stored> , <16 x i32*> <vector of ptrs>, i32 <alignment>, <16 x i1><mask> )

Vector of ptrs - a set of source/destination addresses, to load/store the value.
Mask - switches on/off vector lanes to prevent memory access for switched-off lanes
vector of ptrs, value and mask should have the same vector width.

These are code examples where gather / scatter should be used and will allow function vectorization
;void foo1(int * restrict A, int * restrict B, int * restrict C) {
; for (int i=0; i<SIZE; i++) {
; A[i] = B[C[i]];
; }
;}

;void foo3(int * restrict A, int * restrict B) {
; for (int i=0; i<SIZE; i++) {
; A[B[i]] = i+5;
; }
;}

Diff Detail

Repository
rL LLVM

Event Timeline

delena updated this revision to Diff 19399.Feb 5 2015, 5:43 AM
delena retitled this revision from to Gather and Scatter intrinsics..
delena updated this object.
delena edited the test plan for this revision. (Show Details)
delena added reviewers: hfinkel, anemet, nadav, reames.
delena set the repository for this revision to rL LLVM.
delena added a subscriber: Unknown Object (MLST).
hfinkel edited edge metadata.Feb 6 2015, 2:00 PM

This needs LangRef updates for the intrinsics. Otherwise, I see no fundamental problems here.

lib/IR/Verifier.cpp
2568

Line too long?

2571

This one too.

Hi Hal, thank you for the review.
I'll update documentation after all other patches, when the intrinsics will really work.

reames removed a reviewer: reames.May 5 2015, 3:15 PM