@@ -198,36 +198,35 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
198198 if (ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
199199 bool ignored;
200200 APFloat Val = FPC->getValueAPF ();
201- Val.convert (DestTy->getFltSemantics (), APFloat::rmNearestTiesToEven ,
202- &ignored);
203- return ConstantFP::get (V-> getContext () , Val);
201+ Val.convert (DestTy->getScalarType ()-> getFltSemantics (),
202+ APFloat::rmNearestTiesToEven, &ignored);
203+ return ConstantFP::get (DestTy , Val);
204204 }
205205 return nullptr ; // Can't fold.
206206 case Instruction::FPToUI:
207207 case Instruction::FPToSI:
208208 if (ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
209209 const APFloat &V = FPC->getValueAPF ();
210210 bool ignored;
211- uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth ();
212- APSInt IntVal (DestBitWidth, opc == Instruction::FPToUI);
211+ APSInt IntVal (DestTy->getScalarSizeInBits (), opc == Instruction::FPToUI);
213212 if (APFloat::opInvalidOp ==
214213 V.convertToInteger (IntVal, APFloat::rmTowardZero, &ignored)) {
215214 // Undefined behavior invoked - the destination type can't represent
216215 // the input constant.
217216 return PoisonValue::get (DestTy);
218217 }
219- return ConstantInt::get (FPC-> getContext () , IntVal);
218+ return ConstantInt::get (DestTy , IntVal);
220219 }
221220 return nullptr ; // Can't fold.
222221 case Instruction::UIToFP:
223222 case Instruction::SIToFP:
224223 if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
225224 const APInt &api = CI->getValue ();
226- APFloat apf (DestTy->getFltSemantics (),
227- APInt::getZero (DestTy->getPrimitiveSizeInBits ()));
225+ APFloat apf (DestTy->getScalarType ()-> getFltSemantics (),
226+ APInt::getZero (DestTy->getScalarSizeInBits ()));
228227 apf.convertFromAPInt (api, opc==Instruction::SIToFP,
229228 APFloat::rmNearestTiesToEven);
230- return ConstantFP::get (V-> getContext () , apf);
229+ return ConstantFP::get (DestTy , apf);
231230 }
232231 return nullptr ;
233232 case Instruction::ZExt:
@@ -573,7 +572,7 @@ Constant *llvm::ConstantFoldUnaryInstruction(unsigned Opcode, Constant *C) {
573572 default :
574573 break ;
575574 case Instruction::FNeg:
576- return ConstantFP::get (C->getContext (), neg (CV));
575+ return ConstantFP::get (C->getType (), neg (CV));
577576 }
578577 } else if (auto *VTy = dyn_cast<VectorType>(C->getType ())) {
579578 // Fast path for splatted constants.
@@ -857,19 +856,19 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
857856 break ;
858857 case Instruction::FAdd:
859858 (void )C3V.add (C2V, APFloat::rmNearestTiesToEven);
860- return ConstantFP::get (C1->getContext (), C3V);
859+ return ConstantFP::get (C1->getType (), C3V);
861860 case Instruction::FSub:
862861 (void )C3V.subtract (C2V, APFloat::rmNearestTiesToEven);
863- return ConstantFP::get (C1->getContext (), C3V);
862+ return ConstantFP::get (C1->getType (), C3V);
864863 case Instruction::FMul:
865864 (void )C3V.multiply (C2V, APFloat::rmNearestTiesToEven);
866- return ConstantFP::get (C1->getContext (), C3V);
865+ return ConstantFP::get (C1->getType (), C3V);
867866 case Instruction::FDiv:
868867 (void )C3V.divide (C2V, APFloat::rmNearestTiesToEven);
869- return ConstantFP::get (C1->getContext (), C3V);
868+ return ConstantFP::get (C1->getType (), C3V);
870869 case Instruction::FRem:
871870 (void )C3V.mod (C2V);
872- return ConstantFP::get (C1->getContext (), C3V);
871+ return ConstantFP::get (C1->getType (), C3V);
873872 }
874873 }
875874 }
0 commit comments