Skip to content

Commit 66963bf

Browse files
author
Simon Moll
committed
[VP] make getFunctionalOpcode return an Optional
The operation of some VP intrinsics do/will not map to regular instruction opcodes. Returning 'None' seems more intuitive here than 'Instruction::Call'. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D102778
1 parent f076da6 commit 66963bf

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,12 @@ class VPIntrinsic : public IntrinsicInst {
417417
}
418418

419419
// Equivalent non-predicated opcode
420-
unsigned getFunctionalOpcode() const {
420+
Optional<unsigned> getFunctionalOpcode() const {
421421
return GetFunctionalOpcodeForVP(getIntrinsicID());
422422
}
423423

424424
// Equivalent non-predicated opcode
425-
static unsigned GetFunctionalOpcodeForVP(Intrinsic::ID ID);
425+
static Optional<unsigned> GetFunctionalOpcodeForVP(Intrinsic::ID ID);
426426
};
427427

428428
/// This is the common base class for constrained floating point intrinsics.

llvm/lib/CodeGen/ExpandVectorPredication.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ CachingVPExpander::expandPredicationInBinaryOperator(IRBuilder<> &Builder,
217217
VPI.canIgnoreVectorLengthParam()) &&
218218
"Implicitly dropping %evl in non-speculatable operator!");
219219

220-
auto OC = static_cast<Instruction::BinaryOps>(VPI.getFunctionalOpcode());
220+
auto OC = static_cast<Instruction::BinaryOps>(*VPI.getFunctionalOpcode());
221221
assert(Instruction::isBinaryOp(OC));
222222

223223
Value *Op0 = VPI.getOperand(0);
@@ -316,9 +316,9 @@ Value *CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
316316
IRBuilder<> Builder(&VPI);
317317

318318
// Try lowering to a LLVM instruction first.
319-
unsigned OC = VPI.getFunctionalOpcode();
319+
auto OC = VPI.getFunctionalOpcode();
320320

321-
if (Instruction::isBinaryOp(OC))
321+
if (OC && Instruction::isBinaryOp(*OC))
322322
return expandPredicationInBinaryOperator(Builder, VPI);
323323

324324
return &VPI;

llvm/lib/IR/IntrinsicInst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ bool VPIntrinsic::IsVPIntrinsic(Intrinsic::ID ID) {
317317
}
318318

319319
// Equivalent non-predicated opcode
320-
unsigned VPIntrinsic::GetFunctionalOpcodeForVP(Intrinsic::ID ID) {
321-
unsigned FunctionalOC = Instruction::Call;
320+
Optional<unsigned> VPIntrinsic::GetFunctionalOpcodeForVP(Intrinsic::ID ID) {
321+
Optional<unsigned> FunctionalOC;
322322
switch (ID) {
323323
default:
324324
break;

llvm/unittests/IR/VPIntrinsicTest.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,17 @@ TEST_F(VPIntrinsicTest, OpcodeRoundTrip) {
183183
unsigned FullTripCounts = 0;
184184
for (unsigned OC : Opcodes) {
185185
Intrinsic::ID VPID = VPIntrinsic::GetForOpcode(OC);
186-
// no equivalent VP intrinsic available
186+
// No equivalent VP intrinsic available.
187187
if (VPID == Intrinsic::not_intrinsic)
188188
continue;
189189

190-
unsigned RoundTripOC = VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
191-
// no equivalent Opcode available
192-
if (RoundTripOC == Instruction::Call)
190+
Optional<unsigned> RoundTripOC =
191+
VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
192+
// No equivalent Opcode available.
193+
if (!RoundTripOC)
193194
continue;
194195

195-
ASSERT_EQ(RoundTripOC, OC);
196+
ASSERT_EQ(*RoundTripOC, OC);
196197
++FullTripCounts;
197198
}
198199
ASSERT_NE(FullTripCounts, 0u);
@@ -207,13 +208,13 @@ TEST_F(VPIntrinsicTest, IntrinsicIDRoundTrip) {
207208
unsigned FullTripCounts = 0;
208209
for (const auto &VPDecl : *M) {
209210
auto VPID = VPDecl.getIntrinsicID();
210-
unsigned OC = VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
211+
Optional<unsigned> OC = VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
211212

212213
// no equivalent Opcode available
213-
if (OC == Instruction::Call)
214+
if (!OC)
214215
continue;
215216

216-
Intrinsic::ID RoundTripVPID = VPIntrinsic::GetForOpcode(OC);
217+
Intrinsic::ID RoundTripVPID = VPIntrinsic::GetForOpcode(*OC);
217218

218219
ASSERT_EQ(RoundTripVPID, VPID);
219220
++FullTripCounts;

0 commit comments

Comments
 (0)