@@ -37,45 +37,6 @@ using namespace llvm::PatternMatch;
37
37
// ConstantFold*Instruction Implementations
38
38
// ===----------------------------------------------------------------------===//
39
39
40
- // / Convert the specified vector Constant node to the specified vector type.
41
- // / At this point, we know that the elements of the input vector constant are
42
- // / all simple integer or FP values.
43
- static Constant *BitCastConstantVector (Constant *CV, VectorType *DstTy) {
44
-
45
- if (CV->isAllOnesValue ()) return Constant::getAllOnesValue (DstTy);
46
- if (CV->isNullValue ()) return Constant::getNullValue (DstTy);
47
-
48
- // Do not iterate on scalable vector. The num of elements is unknown at
49
- // compile-time.
50
- if (isa<ScalableVectorType>(DstTy))
51
- return nullptr ;
52
-
53
- // If this cast changes element count then we can't handle it here:
54
- // doing so requires endianness information. This should be handled by
55
- // Analysis/ConstantFolding.cpp
56
- unsigned NumElts = cast<FixedVectorType>(DstTy)->getNumElements ();
57
- if (NumElts != cast<FixedVectorType>(CV->getType ())->getNumElements ())
58
- return nullptr ;
59
-
60
- Type *DstEltTy = DstTy->getElementType ();
61
- // Fast path for splatted constants.
62
- if (Constant *Splat = CV->getSplatValue ()) {
63
- return ConstantVector::getSplat (DstTy->getElementCount (),
64
- ConstantExpr::getBitCast (Splat, DstEltTy));
65
- }
66
-
67
- SmallVector<Constant*, 16 > Result;
68
- Type *Ty = IntegerType::get (CV->getContext (), 32 );
69
- for (unsigned i = 0 ; i != NumElts; ++i) {
70
- Constant *C =
71
- ConstantExpr::getExtractElement (CV, ConstantInt::get (Ty, i));
72
- C = ConstantExpr::getBitCast (C, DstEltTy);
73
- Result.push_back (C);
74
- }
75
-
76
- return ConstantVector::get (Result);
77
- }
78
-
79
40
// / This function determines which opcode to use to fold two constant cast
80
41
// / expressions together. It uses CastInst::isEliminableCastPair to determine
81
42
// / the opcode. Consequently its just a wrapper around that function.
@@ -114,24 +75,15 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) {
114
75
// Handle casts from one vector constant to another. We know that the src
115
76
// and dest type have the same size (otherwise its an illegal cast).
116
77
if (VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
117
- if (VectorType *SrcTy = dyn_cast<VectorType>(V->getType ())) {
118
- assert (DestPTy->getPrimitiveSizeInBits () ==
119
- SrcTy->getPrimitiveSizeInBits () &&
120
- " Not cast between same sized vectors!" );
121
- SrcTy = nullptr ;
122
- // First, check for null. Undef is already handled.
123
- if (isa<ConstantAggregateZero>(V))
124
- return Constant::getNullValue (DestTy);
125
-
126
- // Handle ConstantVector and ConstantAggregateVector.
127
- return BitCastConstantVector (V, DestPTy);
128
- }
78
+ if (V->isAllOnesValue ())
79
+ return Constant::getAllOnesValue (DestTy);
129
80
130
81
// Canonicalize scalar-to-vector bitcasts into vector-to-vector bitcasts
131
82
// This allows for other simplifications (although some of them
132
83
// can only be handled by Analysis/ConstantFolding.cpp).
133
84
if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
134
85
return ConstantExpr::getBitCast (ConstantVector::get (V), DestPTy);
86
+ return nullptr ;
135
87
}
136
88
137
89
// Finally, implement bitcast folding now. The code below doesn't handle
0 commit comments