Skip to content

Commit 3460cc2

Browse files
committed
[VP] Propagate align parameter attr on VP load/store to ISel
This patch fixes a case where the 'align' parameter attribute on the pointer operands to llvm.vp.load and llvm.vp.store was being dropped during the conversion to the SelectionDAG. The default alignment equal to the ABI type alignment of the vector type was kept. It also updates the documentation to reflect the fact that the parameter attribute is now properly supported. Reviewed By: simoll Differential Revision: https://reviews.llvm.org/D114422
1 parent f72ae5c commit 3460cc2

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

llvm/docs/LangRef.rst

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19642,28 +19642,30 @@ vector of boolean values with the same number of elements as the return type.
1964219642
The third is the explicit vector length of the operation. The return type and
1964319643
underlying type of the base pointer are the same vector types.
1964419644

19645+
The :ref:`align <attr_align>` parameter attribute can be provided for the first
19646+
operand.
19647+
1964519648
Semantics:
1964619649
""""""""""
1964719650

1964819651
The '``llvm.vp.load``' intrinsic reads a vector from memory in the same way as
1964919652
the '``llvm.masked.load``' intrinsic, where the mask is taken from the
19650-
combination of the '``mask``' and '``evl``' operands in the usual VP way. Of
19651-
the '``llvm.masked.load``' operands not set by '``llvm.vp.load``': the
19652-
'``passthru``' operand is implicitly ``undef``; the '``alignment``' operand is
19653-
taken as the ABI alignment of the return type as specified by the
19654-
:ref:`datalayout string<langref_datalayout>`.
19653+
combination of the '``mask``' and '``evl``' operands in the usual VP way.
19654+
Certain '``llvm.masked.load``' operands do not have corresponding operands in
19655+
'``llvm.vp.load``': the '``passthru``' operand is implicitly ``undef``; the
19656+
'``alignment``' operand is taken as the ``align`` parameter attribute, if
19657+
provided. The default alignment is taken as the ABI alignment of the return
19658+
type as specified by the :ref:`datalayout string<langref_datalayout>`.
1965519659

1965619660
Examples:
1965719661
"""""""""
1965819662

1965919663
.. code-block:: text
1966019664

19661-
%r = call <8 x i8> @llvm.vp.load.v8i8.p0v8i8(<8 x i8>* %ptr, <8 x i1> %mask, i32 %evl)
19665+
%r = call <8 x i8> @llvm.vp.load.v8i8.p0v8i8(<8 x i8>* align 2 %ptr, <8 x i1> %mask, i32 %evl)
1966219666
;; For all lanes below %evl, %r is lane-wise equivalent to %also.r
19663-
;; Note that since the alignment is ultimately up to the data layout
19664-
;; string, 8 (the default) is used as an example.
1966519667

19666-
%also.r = call <8 x i8> @llvm.masked.load.v8i8.p0v8i8(<8 x i8>* %ptr, i32 8, <8 x i1> %mask, <8 x i8> undef)
19668+
%also.r = call <8 x i8> @llvm.masked.load.v8i8.p0v8i8(<8 x i8>* %ptr, i32 2, <8 x i1> %mask, <8 x i8> undef)
1966719669

1966819670

1966919671
.. _int_vp_store:
@@ -19697,28 +19699,30 @@ the value operand. The third operand is a vector of boolean values with the
1969719699
same number of elements as the return type. The fourth is the explicit vector
1969819700
length of the operation.
1969919701

19702+
The :ref:`align <attr_align>` parameter attribute can be provided for the
19703+
second operand.
19704+
1970019705
Semantics:
1970119706
""""""""""
1970219707

1970319708
The '``llvm.vp.store``' intrinsic reads a vector from memory in the same way as
1970419709
the '``llvm.masked.store``' intrinsic, where the mask is taken from the
1970519710
combination of the '``mask``' and '``evl``' operands in the usual VP way. The
19706-
'``alignment``' operand of the '``llvm.masked.store``' intrinsic is not set by
19707-
'``llvm.vp.store``': it is taken as the ABI alignment of the type of the
19711+
alignment of the operation (corresponding to the '``alignment``' operand of
19712+
'``llvm.masked.store``') is specified by the ``align`` parameter attribute (see
19713+
above). If it is not provided then the ABI alignment of the type of the
1970819714
'``value``' operand as specified by the :ref:`datalayout
19709-
string<langref_datalayout>`.
19715+
string<langref_datalayout>` is used instead.
1971019716

1971119717
Examples:
1971219718
"""""""""
1971319719

1971419720
.. code-block:: text
1971519721

19716-
call void @llvm.vp.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* %ptr, <8 x i1> %mask, i32 %evl)
19722+
call void @llvm.vp.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* align 4 %ptr, <8 x i1> %mask, i32 %evl)
1971719723
;; For all lanes below %evl, the call above is lane-wise equivalent to the call below.
19718-
;; Note that since the alignment is ultimately up to the data layout
19719-
;; string, 8 (the default) is used as an example.
1972019724

19721-
call void @llvm.masked.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* %ptr, i32 8, <8 x i1> %mask)
19725+
call void @llvm.masked.store.v8i8.p0v8i8(<8 x i8> %val, <8 x i8>* %ptr, i32 4, <8 x i1> %mask)
1972219726

1972319727

1972419728
.. _int_vp_gather:

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7317,16 +7317,18 @@ static unsigned getISDForVPIntrinsic(const VPIntrinsic &VPIntrin) {
73177317

73187318
void SelectionDAGBuilder::visitVPLoadGather(const VPIntrinsic &VPIntrin, EVT VT,
73197319
SmallVector<SDValue, 7> &OpValues,
7320-
bool isGather) {
7320+
bool IsGather) {
73217321
SDLoc DL = getCurSDLoc();
73227322
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
73237323
Value *PtrOperand = VPIntrin.getArgOperand(0);
7324-
MaybeAlign Alignment = DAG.getEVTAlign(VT);
7324+
MaybeAlign Alignment = VPIntrin.getPointerAlignment();
7325+
if (!Alignment)
7326+
Alignment = DAG.getEVTAlign(VT);
73257327
AAMDNodes AAInfo = VPIntrin.getAAMetadata();
73267328
const MDNode *Ranges = VPIntrin.getMetadata(LLVMContext::MD_range);
73277329
SDValue LD;
73287330
bool AddToChain = true;
7329-
if (!isGather) {
7331+
if (!IsGather) {
73307332
// Do not serialize variable-length loads of constant memory with
73317333
// anything.
73327334
MemoryLocation ML;
@@ -7380,15 +7382,17 @@ void SelectionDAGBuilder::visitVPLoadGather(const VPIntrinsic &VPIntrin, EVT VT,
73807382

73817383
void SelectionDAGBuilder::visitVPStoreScatter(const VPIntrinsic &VPIntrin,
73827384
SmallVector<SDValue, 7> &OpValues,
7383-
bool isScatter) {
7385+
bool IsScatter) {
73847386
SDLoc DL = getCurSDLoc();
73857387
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
73867388
Value *PtrOperand = VPIntrin.getArgOperand(1);
73877389
EVT VT = OpValues[0].getValueType();
7388-
MaybeAlign Alignment = DAG.getEVTAlign(VT);
7390+
MaybeAlign Alignment = VPIntrin.getPointerAlignment();
7391+
if (!Alignment)
7392+
Alignment = DAG.getEVTAlign(VT);
73897393
AAMDNodes AAInfo = VPIntrin.getAAMetadata();
73907394
SDValue ST;
7391-
if (!isScatter) {
7395+
if (!IsScatter) {
73927396
MachineMemOperand *MMO = DAG.getMachineFunction().getMachineMemOperand(
73937397
MachinePointerInfo(PtrOperand), MachineMemOperand::MOStore,
73947398
VT.getStoreSize().getKnownMinSize(), *Alignment, AAInfo);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,9 @@ class SelectionDAGBuilder {
568568
void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
569569
void visitConstrainedFPIntrinsic(const ConstrainedFPIntrinsic &FPI);
570570
void visitVPLoadGather(const VPIntrinsic &VPIntrin, EVT VT,
571-
SmallVector<SDValue, 7> &OpValues, bool isGather);
571+
SmallVector<SDValue, 7> &OpValues, bool IsGather);
572572
void visitVPStoreScatter(const VPIntrinsic &VPIntrin,
573-
SmallVector<SDValue, 7> &OpValues, bool isScatter);
573+
SmallVector<SDValue, 7> &OpValues, bool IsScatter);
574574
void visitVectorPredicationIntrinsic(const VPIntrinsic &VPIntrin);
575575

576576
void visitVAStart(const CallInst &I);

0 commit comments

Comments
 (0)