[llvm] 66963bf - [VP] make getFunctionalOpcode return an Optional
Simon Moll via llvm-commits
llvm-commits at lists.llvm.org
Wed May 19 08:09:03 PDT 2021
Author: Simon Moll
Date: 2021-05-19T17:08:34+02:00
New Revision: 66963bf3819df4f47bd874a946af058f0c1c4ec0
URL: https://github.com/llvm/llvm-project/commit/66963bf3819df4f47bd874a946af058f0c1c4ec0
DIFF: https://github.com/llvm/llvm-project/commit/66963bf3819df4f47bd874a946af058f0c1c4ec0.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/IR/IntrinsicInst.h
llvm/lib/CodeGen/ExpandVectorPredication.cpp
llvm/lib/IR/IntrinsicInst.cpp
llvm/unittests/IR/VPIntrinsicTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h
index b4c0740cca3c..66540d20fdf5 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -417,12 +417,12 @@ class VPIntrinsic : public IntrinsicInst {
}
// Equivalent non-predicated opcode
- unsigned getFunctionalOpcode() const {
+ Optional<unsigned> getFunctionalOpcode() const {
return GetFunctionalOpcodeForVP(getIntrinsicID());
}
// Equivalent non-predicated opcode
- static unsigned GetFunctionalOpcodeForVP(Intrinsic::ID ID);
+ static Optional<unsigned> GetFunctionalOpcodeForVP(Intrinsic::ID ID);
};
/// This is the common base class for constrained floating point intrinsics.
diff --git a/llvm/lib/CodeGen/ExpandVectorPredication.cpp b/llvm/lib/CodeGen/ExpandVectorPredication.cpp
index 9f34eb08510d..a8d4d4ebe8bd 100644
--- a/llvm/lib/CodeGen/ExpandVectorPredication.cpp
+++ b/llvm/lib/CodeGen/ExpandVectorPredication.cpp
@@ -217,7 +217,7 @@ CachingVPExpander::expandPredicationInBinaryOperator(IRBuilder<> &Builder,
VPI.canIgnoreVectorLengthParam()) &&
"Implicitly dropping %evl in non-speculatable operator!");
- auto OC = static_cast<Instruction::BinaryOps>(VPI.getFunctionalOpcode());
+ auto OC = static_cast<Instruction::BinaryOps>(*VPI.getFunctionalOpcode());
assert(Instruction::isBinaryOp(OC));
Value *Op0 = VPI.getOperand(0);
@@ -316,9 +316,9 @@ Value *CachingVPExpander::expandPredication(VPIntrinsic &VPI) {
IRBuilder<> Builder(&VPI);
// Try lowering to a LLVM instruction first.
- unsigned OC = VPI.getFunctionalOpcode();
+ auto OC = VPI.getFunctionalOpcode();
- if (Instruction::isBinaryOp(OC))
+ if (OC && Instruction::isBinaryOp(*OC))
return expandPredicationInBinaryOperator(Builder, VPI);
return &VPI;
diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp
index 2dd8c98a4137..a78b05109f88 100644
--- a/llvm/lib/IR/IntrinsicInst.cpp
+++ b/llvm/lib/IR/IntrinsicInst.cpp
@@ -317,8 +317,8 @@ bool VPIntrinsic::IsVPIntrinsic(Intrinsic::ID ID) {
}
// Equivalent non-predicated opcode
-unsigned VPIntrinsic::GetFunctionalOpcodeForVP(Intrinsic::ID ID) {
- unsigned FunctionalOC = Instruction::Call;
+Optional<unsigned> VPIntrinsic::GetFunctionalOpcodeForVP(Intrinsic::ID ID) {
+ Optional<unsigned> FunctionalOC;
switch (ID) {
default:
break;
diff --git a/llvm/unittests/IR/VPIntrinsicTest.cpp b/llvm/unittests/IR/VPIntrinsicTest.cpp
index c04ebf35fe65..cfa68c8c8e31 100644
--- a/llvm/unittests/IR/VPIntrinsicTest.cpp
+++ b/llvm/unittests/IR/VPIntrinsicTest.cpp
@@ -183,16 +183,17 @@ TEST_F(VPIntrinsicTest, OpcodeRoundTrip) {
unsigned FullTripCounts = 0;
for (unsigned OC : Opcodes) {
Intrinsic::ID VPID = VPIntrinsic::GetForOpcode(OC);
- // no equivalent VP intrinsic available
+ // No equivalent VP intrinsic available.
if (VPID == Intrinsic::not_intrinsic)
continue;
- unsigned RoundTripOC = VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
- // no equivalent Opcode available
- if (RoundTripOC == Instruction::Call)
+ Optional<unsigned> RoundTripOC =
+ VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
+ // No equivalent Opcode available.
+ if (!RoundTripOC)
continue;
- ASSERT_EQ(RoundTripOC, OC);
+ ASSERT_EQ(*RoundTripOC, OC);
++FullTripCounts;
}
ASSERT_NE(FullTripCounts, 0u);
@@ -207,13 +208,13 @@ TEST_F(VPIntrinsicTest, IntrinsicIDRoundTrip) {
unsigned FullTripCounts = 0;
for (const auto &VPDecl : *M) {
auto VPID = VPDecl.getIntrinsicID();
- unsigned OC = VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
+ Optional<unsigned> OC = VPIntrinsic::GetFunctionalOpcodeForVP(VPID);
// no equivalent Opcode available
- if (OC == Instruction::Call)
+ if (!OC)
continue;
- Intrinsic::ID RoundTripVPID = VPIntrinsic::GetForOpcode(OC);
+ Intrinsic::ID RoundTripVPID = VPIntrinsic::GetForOpcode(*OC);
ASSERT_EQ(RoundTripVPID, VPID);
++FullTripCounts;
More information about the llvm-commits
mailing list