Skip to content

Commit 6213f1d

Browse files
committed
[IR] Make VPIntrinsic::getDeclarationForParams() opaque pointer compatible
The vp.load and vp.gather intrinsics require the intrinsic return type to determine the correct function signature. With opaque pointers, it cannot be derived from the parameter pointee types. Differential Revision: https://reviews.llvm.org/D115632
1 parent d733f2c commit 6213f1d

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ class DbgLabelInst : public DbgInfoIntrinsic {
390390
class VPIntrinsic : public IntrinsicInst {
391391
public:
392392
/// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
393-
/// \p Params.
393+
/// \p Params. Additionally, the load and gather intrinsics require
394+
/// \p ReturnType to be specified.
394395
static Function *getDeclarationForParams(Module *M, Intrinsic::ID,
396+
Type *ReturnType,
395397
ArrayRef<Value *> Params);
396398

397399
static Optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ bool VPIntrinsic::canIgnoreVectorLengthParam() const {
468468
}
469469

470470
Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
471+
Type *ReturnType,
471472
ArrayRef<Value *> Params) {
472473
assert(isVPIntrinsic(VPID) && "not a VP intrinsic");
473474
Function *VPFunc;
@@ -486,22 +487,15 @@ Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
486487
break;
487488
case Intrinsic::vp_load:
488489
VPFunc = Intrinsic::getDeclaration(
489-
M, VPID,
490-
{Params[0]->getType()->getPointerElementType(), Params[0]->getType()});
490+
M, VPID, {ReturnType, Params[0]->getType()});
491491
break;
492492
case Intrinsic::vp_gather:
493493
VPFunc = Intrinsic::getDeclaration(
494-
M, VPID,
495-
{VectorType::get(cast<VectorType>(Params[0]->getType())
496-
->getElementType()
497-
->getPointerElementType(),
498-
cast<VectorType>(Params[0]->getType())),
499-
Params[0]->getType()});
494+
M, VPID, {ReturnType, Params[0]->getType()});
500495
break;
501496
case Intrinsic::vp_store:
502497
VPFunc = Intrinsic::getDeclaration(
503-
M, VPID,
504-
{Params[1]->getType()->getPointerElementType(), Params[1]->getType()});
498+
M, VPID, {Params[0]->getType(), Params[1]->getType()});
505499
break;
506500
case Intrinsic::vp_scatter:
507501
VPFunc = Intrinsic::getDeclaration(

llvm/unittests/IR/VPIntrinsicTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ TEST_F(VPIntrinsicTest, VPIntrinsicDeclarationForParams) {
272272

273273
ASSERT_NE(F.getIntrinsicID(), Intrinsic::not_intrinsic);
274274
auto *NewDecl = VPIntrinsic::getDeclarationForParams(
275-
OutM.get(), F.getIntrinsicID(), Values);
275+
OutM.get(), F.getIntrinsicID(), FuncTy->getReturnType(), Values);
276276
ASSERT_TRUE(NewDecl);
277277

278278
// Check that 'old decl' == 'new decl'.

0 commit comments

Comments
 (0)