Skip to content

Commit

Permalink
[IR] Make VPIntrinsic::getDeclarationForParams() opaque pointer compa…
Browse files Browse the repository at this point in the history
…tible

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
  • Loading branch information
nikic committed Dec 14, 2021
1 parent d733f2c commit 6213f1d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 3 additions & 1 deletion llvm/include/llvm/IR/IntrinsicInst.h
Expand Up @@ -390,8 +390,10 @@ class DbgLabelInst : public DbgInfoIntrinsic {
class VPIntrinsic : public IntrinsicInst {
public:
/// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
/// \p Params.
/// \p Params. Additionally, the load and gather intrinsics require
/// \p ReturnType to be specified.
static Function *getDeclarationForParams(Module *M, Intrinsic::ID,
Type *ReturnType,
ArrayRef<Value *> Params);

static Optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
Expand Down
14 changes: 4 additions & 10 deletions llvm/lib/IR/IntrinsicInst.cpp
Expand Up @@ -468,6 +468,7 @@ bool VPIntrinsic::canIgnoreVectorLengthParam() const {
}

Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
Type *ReturnType,
ArrayRef<Value *> Params) {
assert(isVPIntrinsic(VPID) && "not a VP intrinsic");
Function *VPFunc;
Expand All @@ -486,22 +487,15 @@ Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
break;
case Intrinsic::vp_load:
VPFunc = Intrinsic::getDeclaration(
M, VPID,
{Params[0]->getType()->getPointerElementType(), Params[0]->getType()});
M, VPID, {ReturnType, Params[0]->getType()});
break;
case Intrinsic::vp_gather:
VPFunc = Intrinsic::getDeclaration(
M, VPID,
{VectorType::get(cast<VectorType>(Params[0]->getType())
->getElementType()
->getPointerElementType(),
cast<VectorType>(Params[0]->getType())),
Params[0]->getType()});
M, VPID, {ReturnType, Params[0]->getType()});
break;
case Intrinsic::vp_store:
VPFunc = Intrinsic::getDeclaration(
M, VPID,
{Params[1]->getType()->getPointerElementType(), Params[1]->getType()});
M, VPID, {Params[0]->getType(), Params[1]->getType()});
break;
case Intrinsic::vp_scatter:
VPFunc = Intrinsic::getDeclaration(
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/IR/VPIntrinsicTest.cpp
Expand Up @@ -272,7 +272,7 @@ TEST_F(VPIntrinsicTest, VPIntrinsicDeclarationForParams) {

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

// Check that 'old decl' == 'new decl'.
Expand Down

0 comments on commit 6213f1d

Please sign in to comment.