9
9
#include " VPlanAnalysis.h"
10
10
#include " VPlan.h"
11
11
#include " llvm/ADT/TypeSwitch.h"
12
+ #include " llvm/IR/Instruction.h"
12
13
13
14
using namespace llvm ;
14
15
@@ -26,7 +27,24 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPBlendRecipe *R) {
26
27
}
27
28
28
29
Type *VPTypeAnalysis::inferScalarTypeForRecipe (const VPInstruction *R) {
29
- switch (R->getOpcode ()) {
30
+ // Set the result type from the first operand, check if the types for all
31
+ // other operands match and cache them.
32
+ auto SetResultTyFromOp = [this , R]() {
33
+ Type *ResTy = inferScalarType (R->getOperand (0 ));
34
+ for (unsigned Op = 1 ; Op != R->getNumOperands (); ++Op) {
35
+ VPValue *OtherV = R->getOperand (Op);
36
+ assert (inferScalarType (OtherV) == ResTy &&
37
+ " different types inferred for different operands" );
38
+ CachedTypes[OtherV] = ResTy;
39
+ }
40
+ return ResTy;
41
+ };
42
+
43
+ unsigned Opcode = R->getOpcode ();
44
+ if (Instruction::isBinaryOp (Opcode) || Instruction::isUnaryOp (Opcode))
45
+ return SetResultTyFromOp ();
46
+
47
+ switch (Opcode) {
30
48
case Instruction::Select: {
31
49
Type *ResTy = inferScalarType (R->getOperand (1 ));
32
50
VPValue *OtherV = R->getOperand (2 );
@@ -35,28 +53,16 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
35
53
CachedTypes[OtherV] = ResTy;
36
54
return ResTy;
37
55
}
38
- case Instruction::Or:
39
56
case Instruction::ICmp:
40
- case VPInstruction::FirstOrderRecurrenceSplice: {
41
- Type *ResTy = inferScalarType (R->getOperand (0 ));
42
- VPValue *OtherV = R->getOperand (1 );
43
- assert (inferScalarType (OtherV) == ResTy &&
44
- " different types inferred for different operands" );
45
- CachedTypes[OtherV] = ResTy;
46
- return ResTy;
47
- }
57
+ case VPInstruction::FirstOrderRecurrenceSplice:
58
+ case VPInstruction::Not:
59
+ return SetResultTyFromOp ();
48
60
case VPInstruction::ExtractFromEnd: {
49
61
Type *BaseTy = inferScalarType (R->getOperand (0 ));
50
62
if (auto *VecTy = dyn_cast<VectorType>(BaseTy))
51
63
return VecTy->getElementType ();
52
64
return BaseTy;
53
65
}
54
- case VPInstruction::Not: {
55
- Type *ResTy = inferScalarType (R->getOperand (0 ));
56
- assert (IntegerType::get (Ctx, 1 ) == ResTy &&
57
- " unexpected scalar type inferred for operand" );
58
- return ResTy;
59
- }
60
66
case VPInstruction::LogicalAnd:
61
67
return IntegerType::get (Ctx, 1 );
62
68
case VPInstruction::PtrAdd:
0 commit comments