@@ -151,8 +151,14 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
151151 return FoldBitCast (ConstantVector::get (Ops), DestTy, DL);
152152 }
153153
154+ // Some of what follows may extend to cover scalable vectors but the current
155+ // implementation is fixed length specific.
156+ if (!isa<FixedVectorType>(C->getType ()))
157+ return ConstantExpr::getBitCast (C, DestTy);
158+
154159 // If this is a bitcast from constant vector -> vector, fold it.
155- if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
160+ if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C) &&
161+ !isa<ConstantInt>(C) && !isa<ConstantFP>(C))
156162 return ConstantExpr::getBitCast (C, DestTy);
157163
158164 // If the element types match, IR can fold it.
@@ -194,10 +200,9 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
194200 IntegerType::get (C->getContext (), FPWidth), NumSrcElt);
195201 // Ask IR to do the conversion now that #elts line up.
196202 C = ConstantExpr::getBitCast (C, SrcIVTy);
197- // If IR wasn't able to fold it, bail out.
198- if (!isa<ConstantVector>(C) && // FIXME: Remove ConstantVector.
199- !isa<ConstantDataVector>(C))
200- return C;
203+ assert ((isa<ConstantVector>(C) || // FIXME: Remove ConstantVector.
204+ isa<ConstantDataVector>(C) || isa<ConstantInt>(C)) &&
205+ " Constant folding cannot fail for plain fp->int bitcast!" );
201206 }
202207
203208 // Now we know that the input and output vectors are both integer vectors
0 commit comments