1 //===- ConstantHandling.cpp - Implement ConstantHandling.h ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the various intrinsic operations, on constant values.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ConstantHandling.h"
15 #include "llvm/iPHINode.h"
16 #include "llvm/InstrTypes.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/Support/GetElementPtrTypeIterator.h"
22 static unsigned getSize(const Type *Ty) {
23 unsigned S = Ty->getPrimitiveSize();
24 return S ? S : 8; // Treat pointers at 8 bytes
27 Constant *llvm::ConstantFoldCastInstruction(const Constant *V,
29 if (V->getType() == DestTy) return (Constant*)V;
31 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
32 if (CE->getOpcode() == Instruction::Cast) {
33 Constant *Op = const_cast<Constant*>(CE->getOperand(0));
34 // Try to not produce a cast of a cast, which is almost always redundant.
35 if (!Op->getType()->isFloatingPoint() &&
36 !CE->getType()->isFloatingPoint() &&
37 !DestTy->getType()->isFloatingPoint()) {
38 unsigned S1 = getSize(Op->getType()), S2 = getSize(CE->getType());
39 unsigned S3 = getSize(DestTy);
40 if (Op->getType() == DestTy && S3 >= S2)
42 if (S1 >= S2 && S2 >= S3)
43 return ConstantExpr::getCast(Op, DestTy);
44 if (S1 <= S2 && S2 >= S3 && S1 <= S3)
45 return ConstantExpr::getCast(Op, DestTy);
47 } else if (CE->getOpcode() == Instruction::GetElementPtr) {
48 // If all of the indexes in the GEP are null values, there is no pointer
49 // adjustment going on. We might as well cast the source pointer.
50 bool isAllNull = true;
51 for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
52 if (!CE->getOperand(i)->isNullValue()) {
57 return ConstantExpr::getCast(CE->getOperand(0), DestTy);
60 return ConstRules::get(*V, *V).castTo(V, DestTy);
63 Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
67 case Instruction::Add: return *V1 + *V2;
68 case Instruction::Sub: return *V1 - *V2;
69 case Instruction::Mul: return *V1 * *V2;
70 case Instruction::Div: return *V1 / *V2;
71 case Instruction::Rem: return *V1 % *V2;
72 case Instruction::And: return *V1 & *V2;
73 case Instruction::Or: return *V1 | *V2;
74 case Instruction::Xor: return *V1 ^ *V2;
76 case Instruction::SetEQ: return *V1 == *V2;
77 case Instruction::SetNE: return *V1 != *V2;
78 case Instruction::SetLE: return *V1 <= *V2;
79 case Instruction::SetGE: return *V1 >= *V2;
80 case Instruction::SetLT: return *V1 < *V2;
81 case Instruction::SetGT: return *V1 > *V2;
86 Constant *llvm::ConstantFoldShiftInstruction(unsigned Opcode,
90 case Instruction::Shl: return *V1 << *V2;
91 case Instruction::Shr: return *V1 >> *V2;
96 Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
97 const std::vector<Constant*> &IdxList) {
98 if (IdxList.size() == 0 ||
99 (IdxList.size() == 1 && IdxList[0]->isNullValue()))
100 return const_cast<Constant*>(C);
102 // TODO If C is null and all idx's are null, return null of the right type.
105 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(const_cast<Constant*>(C))) {
106 // Combine Indices - If the source pointer to this getelementptr instruction
107 // is a getelementptr instruction, combine the indices of the two
108 // getelementptr instructions into a single instruction.
110 if (CE->getOpcode() == Instruction::GetElementPtr) {
111 const Type *LastTy = 0;
112 for (gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE);
116 if ((LastTy && isa<ArrayType>(LastTy)) || IdxList[0]->isNullValue()) {
117 std::vector<Constant*> NewIndices;
118 NewIndices.reserve(IdxList.size() + CE->getNumOperands());
119 for (unsigned i = 1, e = CE->getNumOperands()-1; i != e; ++i)
120 NewIndices.push_back(cast<Constant>(CE->getOperand(i)));
122 // Add the last index of the source with the first index of the new GEP.
123 // Make sure to handle the case when they are actually different types.
124 Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
125 if (!IdxList[0]->isNullValue()) // Otherwise it must be an array
127 ConstantExpr::get(Instruction::Add,
128 ConstantExpr::getCast(IdxList[0], Type::LongTy),
129 ConstantExpr::getCast(Combined, Type::LongTy));
131 NewIndices.push_back(Combined);
132 NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
133 return ConstantExpr::getGetElementPtr(CE->getOperand(0), NewIndices);
137 // Implement folding of:
138 // int* getelementptr ([2 x int]* cast ([3 x int]* %X to [2 x int]*),
140 // To: int* getelementptr ([3 x int]* %X, long 0, long 0)
142 if (CE->getOpcode() == Instruction::Cast && IdxList.size() > 1 &&
143 IdxList[0]->isNullValue())
144 if (const PointerType *SPT =
145 dyn_cast<PointerType>(CE->getOperand(0)->getType()))
146 if (const ArrayType *SAT = dyn_cast<ArrayType>(SPT->getElementType()))
147 if (const ArrayType *CAT =
148 dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
149 if (CAT->getElementType() == SAT->getElementType())
150 return ConstantExpr::getGetElementPtr(
151 (Constant*)CE->getOperand(0), IdxList);
157 //===----------------------------------------------------------------------===//
158 // TemplateRules Class
159 //===----------------------------------------------------------------------===//
161 // TemplateRules - Implement a subclass of ConstRules that provides all
162 // operations as noops. All other rules classes inherit from this class so
163 // that if functionality is needed in the future, it can simply be added here
164 // and to ConstRules without changing anything else...
166 // This class also provides subclasses with typesafe implementations of methods
167 // so that don't have to do type casting.
169 template<class ArgType, class SubClassName>
170 class TemplateRules : public ConstRules {
172 //===--------------------------------------------------------------------===//
173 // Redirecting functions that cast to the appropriate types
174 //===--------------------------------------------------------------------===//
176 virtual Constant *add(const Constant *V1, const Constant *V2) const {
177 return SubClassName::Add((const ArgType *)V1, (const ArgType *)V2);
179 virtual Constant *sub(const Constant *V1, const Constant *V2) const {
180 return SubClassName::Sub((const ArgType *)V1, (const ArgType *)V2);
182 virtual Constant *mul(const Constant *V1, const Constant *V2) const {
183 return SubClassName::Mul((const ArgType *)V1, (const ArgType *)V2);
185 virtual Constant *div(const Constant *V1, const Constant *V2) const {
186 return SubClassName::Div((const ArgType *)V1, (const ArgType *)V2);
188 virtual Constant *rem(const Constant *V1, const Constant *V2) const {
189 return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2);
191 virtual Constant *op_and(const Constant *V1, const Constant *V2) const {
192 return SubClassName::And((const ArgType *)V1, (const ArgType *)V2);
194 virtual Constant *op_or(const Constant *V1, const Constant *V2) const {
195 return SubClassName::Or((const ArgType *)V1, (const ArgType *)V2);
197 virtual Constant *op_xor(const Constant *V1, const Constant *V2) const {
198 return SubClassName::Xor((const ArgType *)V1, (const ArgType *)V2);
200 virtual Constant *shl(const Constant *V1, const Constant *V2) const {
201 return SubClassName::Shl((const ArgType *)V1, (const ArgType *)V2);
203 virtual Constant *shr(const Constant *V1, const Constant *V2) const {
204 return SubClassName::Shr((const ArgType *)V1, (const ArgType *)V2);
207 virtual ConstantBool *lessthan(const Constant *V1,
208 const Constant *V2) const {
209 return SubClassName::LessThan((const ArgType *)V1, (const ArgType *)V2);
211 virtual ConstantBool *equalto(const Constant *V1,
212 const Constant *V2) const {
213 return SubClassName::EqualTo((const ArgType *)V1, (const ArgType *)V2);
216 // Casting operators. ick
217 virtual ConstantBool *castToBool(const Constant *V) const {
218 return SubClassName::CastToBool((const ArgType*)V);
220 virtual ConstantSInt *castToSByte(const Constant *V) const {
221 return SubClassName::CastToSByte((const ArgType*)V);
223 virtual ConstantUInt *castToUByte(const Constant *V) const {
224 return SubClassName::CastToUByte((const ArgType*)V);
226 virtual ConstantSInt *castToShort(const Constant *V) const {
227 return SubClassName::CastToShort((const ArgType*)V);
229 virtual ConstantUInt *castToUShort(const Constant *V) const {
230 return SubClassName::CastToUShort((const ArgType*)V);
232 virtual ConstantSInt *castToInt(const Constant *V) const {
233 return SubClassName::CastToInt((const ArgType*)V);
235 virtual ConstantUInt *castToUInt(const Constant *V) const {
236 return SubClassName::CastToUInt((const ArgType*)V);
238 virtual ConstantSInt *castToLong(const Constant *V) const {
239 return SubClassName::CastToLong((const ArgType*)V);
241 virtual ConstantUInt *castToULong(const Constant *V) const {
242 return SubClassName::CastToULong((const ArgType*)V);
244 virtual ConstantFP *castToFloat(const Constant *V) const {
245 return SubClassName::CastToFloat((const ArgType*)V);
247 virtual ConstantFP *castToDouble(const Constant *V) const {
248 return SubClassName::CastToDouble((const ArgType*)V);
250 virtual Constant *castToPointer(const Constant *V,
251 const PointerType *Ty) const {
252 return SubClassName::CastToPointer((const ArgType*)V, Ty);
255 //===--------------------------------------------------------------------===//
256 // Default "noop" implementations
257 //===--------------------------------------------------------------------===//
259 static Constant *Add(const ArgType *V1, const ArgType *V2) { return 0; }
260 static Constant *Sub(const ArgType *V1, const ArgType *V2) { return 0; }
261 static Constant *Mul(const ArgType *V1, const ArgType *V2) { return 0; }
262 static Constant *Div(const ArgType *V1, const ArgType *V2) { return 0; }
263 static Constant *Rem(const ArgType *V1, const ArgType *V2) { return 0; }
264 static Constant *And(const ArgType *V1, const ArgType *V2) { return 0; }
265 static Constant *Or (const ArgType *V1, const ArgType *V2) { return 0; }
266 static Constant *Xor(const ArgType *V1, const ArgType *V2) { return 0; }
267 static Constant *Shl(const ArgType *V1, const ArgType *V2) { return 0; }
268 static Constant *Shr(const ArgType *V1, const ArgType *V2) { return 0; }
269 static ConstantBool *LessThan(const ArgType *V1, const ArgType *V2) {
272 static ConstantBool *EqualTo(const ArgType *V1, const ArgType *V2) {
276 // Casting operators. ick
277 static ConstantBool *CastToBool (const Constant *V) { return 0; }
278 static ConstantSInt *CastToSByte (const Constant *V) { return 0; }
279 static ConstantUInt *CastToUByte (const Constant *V) { return 0; }
280 static ConstantSInt *CastToShort (const Constant *V) { return 0; }
281 static ConstantUInt *CastToUShort(const Constant *V) { return 0; }
282 static ConstantSInt *CastToInt (const Constant *V) { return 0; }
283 static ConstantUInt *CastToUInt (const Constant *V) { return 0; }
284 static ConstantSInt *CastToLong (const Constant *V) { return 0; }
285 static ConstantUInt *CastToULong (const Constant *V) { return 0; }
286 static ConstantFP *CastToFloat (const Constant *V) { return 0; }
287 static ConstantFP *CastToDouble(const Constant *V) { return 0; }
288 static Constant *CastToPointer(const Constant *,
289 const PointerType *) {return 0;}
294 //===----------------------------------------------------------------------===//
296 //===----------------------------------------------------------------------===//
298 // EmptyRules provides a concrete base class of ConstRules that does nothing
300 struct EmptyRules : public TemplateRules<Constant, EmptyRules> {
301 static ConstantBool *EqualTo(const Constant *V1, const Constant *V2) {
302 if (V1 == V2) return ConstantBool::True;
309 //===----------------------------------------------------------------------===//
311 //===----------------------------------------------------------------------===//
313 // BoolRules provides a concrete base class of ConstRules for the 'bool' type.
315 struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
317 static ConstantBool *LessThan(const ConstantBool *V1, const ConstantBool *V2){
318 return ConstantBool::get(V1->getValue() < V2->getValue());
321 static ConstantBool *EqualTo(const Constant *V1, const Constant *V2) {
322 return ConstantBool::get(V1 == V2);
325 static Constant *And(const ConstantBool *V1, const ConstantBool *V2) {
326 return ConstantBool::get(V1->getValue() & V2->getValue());
329 static Constant *Or(const ConstantBool *V1, const ConstantBool *V2) {
330 return ConstantBool::get(V1->getValue() | V2->getValue());
333 static Constant *Xor(const ConstantBool *V1, const ConstantBool *V2) {
334 return ConstantBool::get(V1->getValue() ^ V2->getValue());
337 // Casting operators. ick
338 #define DEF_CAST(TYPE, CLASS, CTYPE) \
339 static CLASS *CastTo##TYPE (const ConstantBool *V) { \
340 return CLASS::get(Type::TYPE##Ty, (CTYPE)(bool)V->getValue()); \
343 DEF_CAST(Bool , ConstantBool, bool)
344 DEF_CAST(SByte , ConstantSInt, signed char)
345 DEF_CAST(UByte , ConstantUInt, unsigned char)
346 DEF_CAST(Short , ConstantSInt, signed short)
347 DEF_CAST(UShort, ConstantUInt, unsigned short)
348 DEF_CAST(Int , ConstantSInt, signed int)
349 DEF_CAST(UInt , ConstantUInt, unsigned int)
350 DEF_CAST(Long , ConstantSInt, int64_t)
351 DEF_CAST(ULong , ConstantUInt, uint64_t)
352 DEF_CAST(Float , ConstantFP , float)
353 DEF_CAST(Double, ConstantFP , double)
358 //===----------------------------------------------------------------------===//
359 // NullPointerRules Class
360 //===----------------------------------------------------------------------===//
362 // NullPointerRules provides a concrete base class of ConstRules for null
365 struct NullPointerRules : public TemplateRules<ConstantPointerNull,
367 static ConstantBool *EqualTo(const Constant *V1, const Constant *V2) {
368 return ConstantBool::True; // Null pointers are always equal
370 static ConstantBool *CastToBool (const Constant *V) {
371 return ConstantBool::False;
373 static ConstantSInt *CastToSByte (const Constant *V) {
374 return ConstantSInt::get(Type::SByteTy, 0);
376 static ConstantUInt *CastToUByte (const Constant *V) {
377 return ConstantUInt::get(Type::UByteTy, 0);
379 static ConstantSInt *CastToShort (const Constant *V) {
380 return ConstantSInt::get(Type::ShortTy, 0);
382 static ConstantUInt *CastToUShort(const Constant *V) {
383 return ConstantUInt::get(Type::UShortTy, 0);
385 static ConstantSInt *CastToInt (const Constant *V) {
386 return ConstantSInt::get(Type::IntTy, 0);
388 static ConstantUInt *CastToUInt (const Constant *V) {
389 return ConstantUInt::get(Type::UIntTy, 0);
391 static ConstantSInt *CastToLong (const Constant *V) {
392 return ConstantSInt::get(Type::LongTy, 0);
394 static ConstantUInt *CastToULong (const Constant *V) {
395 return ConstantUInt::get(Type::ULongTy, 0);
397 static ConstantFP *CastToFloat (const Constant *V) {
398 return ConstantFP::get(Type::FloatTy, 0);
400 static ConstantFP *CastToDouble(const Constant *V) {
401 return ConstantFP::get(Type::DoubleTy, 0);
404 static Constant *CastToPointer(const ConstantPointerNull *V,
405 const PointerType *PTy) {
406 return ConstantPointerNull::get(PTy);
411 //===----------------------------------------------------------------------===//
413 //===----------------------------------------------------------------------===//
415 // DirectRules provides a concrete base classes of ConstRules for a variety of
416 // different types. This allows the C++ compiler to automatically generate our
417 // constant handling operations in a typesafe and accurate manner.
419 template<class ConstantClass, class BuiltinType, Type **Ty, class SuperClass>
420 struct DirectRules : public TemplateRules<ConstantClass, SuperClass> {
421 static Constant *Add(const ConstantClass *V1, const ConstantClass *V2) {
422 BuiltinType R = (BuiltinType)V1->getValue() + (BuiltinType)V2->getValue();
423 return ConstantClass::get(*Ty, R);
426 static Constant *Sub(const ConstantClass *V1, const ConstantClass *V2) {
427 BuiltinType R = (BuiltinType)V1->getValue() - (BuiltinType)V2->getValue();
428 return ConstantClass::get(*Ty, R);
431 static Constant *Mul(const ConstantClass *V1, const ConstantClass *V2) {
432 BuiltinType R = (BuiltinType)V1->getValue() * (BuiltinType)V2->getValue();
433 return ConstantClass::get(*Ty, R);
436 static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
437 if (V2->isNullValue()) return 0;
438 BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
439 return ConstantClass::get(*Ty, R);
442 static ConstantBool *LessThan(const ConstantClass *V1,
443 const ConstantClass *V2) {
444 bool R = (BuiltinType)V1->getValue() < (BuiltinType)V2->getValue();
445 return ConstantBool::get(R);
448 static ConstantBool *EqualTo(const ConstantClass *V1,
449 const ConstantClass *V2) {
450 bool R = (BuiltinType)V1->getValue() == (BuiltinType)V2->getValue();
451 return ConstantBool::get(R);
454 static Constant *CastToPointer(const ConstantClass *V,
455 const PointerType *PTy) {
456 if (V->isNullValue()) // Is it a FP or Integral null value?
457 return ConstantPointerNull::get(PTy);
458 return 0; // Can't const prop other types of pointers
461 // Casting operators. ick
462 #define DEF_CAST(TYPE, CLASS, CTYPE) \
463 static CLASS *CastTo##TYPE (const ConstantClass *V) { \
464 return CLASS::get(Type::TYPE##Ty, (CTYPE)(BuiltinType)V->getValue()); \
467 DEF_CAST(Bool , ConstantBool, bool)
468 DEF_CAST(SByte , ConstantSInt, signed char)
469 DEF_CAST(UByte , ConstantUInt, unsigned char)
470 DEF_CAST(Short , ConstantSInt, signed short)
471 DEF_CAST(UShort, ConstantUInt, unsigned short)
472 DEF_CAST(Int , ConstantSInt, signed int)
473 DEF_CAST(UInt , ConstantUInt, unsigned int)
474 DEF_CAST(Long , ConstantSInt, int64_t)
475 DEF_CAST(ULong , ConstantUInt, uint64_t)
476 DEF_CAST(Float , ConstantFP , float)
477 DEF_CAST(Double, ConstantFP , double)
482 //===----------------------------------------------------------------------===//
483 // DirectIntRules Class
484 //===----------------------------------------------------------------------===//
486 // DirectIntRules provides implementations of functions that are valid on
487 // integer types, but not all types in general.
489 template <class ConstantClass, class BuiltinType, Type **Ty>
490 struct DirectIntRules
491 : public DirectRules<ConstantClass, BuiltinType, Ty,
492 DirectIntRules<ConstantClass, BuiltinType, Ty> > {
494 static Constant *Div(const ConstantClass *V1, const ConstantClass *V2) {
495 if (V2->isNullValue()) return 0;
496 if (V2->isAllOnesValue() && // MIN_INT / -1
497 (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
499 BuiltinType R = (BuiltinType)V1->getValue() / (BuiltinType)V2->getValue();
500 return ConstantClass::get(*Ty, R);
503 static Constant *Rem(const ConstantClass *V1,
504 const ConstantClass *V2) {
505 if (V2->isNullValue()) return 0; // X / 0
506 if (V2->isAllOnesValue() && // MIN_INT / -1
507 (BuiltinType)V1->getValue() == -(BuiltinType)V1->getValue())
509 BuiltinType R = (BuiltinType)V1->getValue() % (BuiltinType)V2->getValue();
510 return ConstantClass::get(*Ty, R);
513 static Constant *And(const ConstantClass *V1, const ConstantClass *V2) {
514 BuiltinType R = (BuiltinType)V1->getValue() & (BuiltinType)V2->getValue();
515 return ConstantClass::get(*Ty, R);
517 static Constant *Or(const ConstantClass *V1, const ConstantClass *V2) {
518 BuiltinType R = (BuiltinType)V1->getValue() | (BuiltinType)V2->getValue();
519 return ConstantClass::get(*Ty, R);
521 static Constant *Xor(const ConstantClass *V1, const ConstantClass *V2) {
522 BuiltinType R = (BuiltinType)V1->getValue() ^ (BuiltinType)V2->getValue();
523 return ConstantClass::get(*Ty, R);
526 static Constant *Shl(const ConstantClass *V1, const ConstantClass *V2) {
527 BuiltinType R = (BuiltinType)V1->getValue() << (BuiltinType)V2->getValue();
528 return ConstantClass::get(*Ty, R);
531 static Constant *Shr(const ConstantClass *V1, const ConstantClass *V2) {
532 BuiltinType R = (BuiltinType)V1->getValue() >> (BuiltinType)V2->getValue();
533 return ConstantClass::get(*Ty, R);
538 //===----------------------------------------------------------------------===//
539 // DirectFPRules Class
540 //===----------------------------------------------------------------------===//
542 // DirectFPRules provides implementations of functions that are valid on
543 // floating point types, but not all types in general.
545 template <class ConstantClass, class BuiltinType, Type **Ty>
547 : public DirectRules<ConstantClass, BuiltinType, Ty,
548 DirectFPRules<ConstantClass, BuiltinType, Ty> > {
549 static Constant *Rem(const ConstantClass *V1, const ConstantClass *V2) {
550 if (V2->isNullValue()) return 0;
551 BuiltinType Result = std::fmod((BuiltinType)V1->getValue(),
552 (BuiltinType)V2->getValue());
553 return ConstantClass::get(*Ty, Result);
557 ConstRules &ConstRules::get(const Constant &V1, const Constant &V2) {
558 static EmptyRules EmptyR;
559 static BoolRules BoolR;
560 static NullPointerRules NullPointerR;
561 static DirectIntRules<ConstantSInt, signed char , &Type::SByteTy> SByteR;
562 static DirectIntRules<ConstantUInt, unsigned char , &Type::UByteTy> UByteR;
563 static DirectIntRules<ConstantSInt, signed short, &Type::ShortTy> ShortR;
564 static DirectIntRules<ConstantUInt, unsigned short, &Type::UShortTy> UShortR;
565 static DirectIntRules<ConstantSInt, signed int , &Type::IntTy> IntR;
566 static DirectIntRules<ConstantUInt, unsigned int , &Type::UIntTy> UIntR;
567 static DirectIntRules<ConstantSInt, int64_t , &Type::LongTy> LongR;
568 static DirectIntRules<ConstantUInt, uint64_t , &Type::ULongTy> ULongR;
569 static DirectFPRules <ConstantFP , float , &Type::FloatTy> FloatR;
570 static DirectFPRules <ConstantFP , double , &Type::DoubleTy> DoubleR;
572 if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2) ||
573 isa<ConstantPointerRef>(V1) || isa<ConstantPointerRef>(V2))
576 // FIXME: This assert doesn't work because shifts pass both operands in to
577 // check for constant exprs. :(
578 //assert(V1.getType() == V2.getType() &&"Nonequal types to constant folder?");
580 switch (V1.getType()->getPrimitiveID()) {
581 default: assert(0 && "Unknown value type for constant folding!");
582 case Type::BoolTyID: return BoolR;
583 case Type::PointerTyID: return NullPointerR;
584 case Type::SByteTyID: return SByteR;
585 case Type::UByteTyID: return UByteR;
586 case Type::ShortTyID: return ShortR;
587 case Type::UShortTyID: return UShortR;
588 case Type::IntTyID: return IntR;
589 case Type::UIntTyID: return UIntR;
590 case Type::LongTyID: return LongR;
591 case Type::ULongTyID: return ULongR;
592 case Type::FloatTyID: return FloatR;
593 case Type::DoubleTyID: return DoubleR;