mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-26 05:00:26 +00:00
Use a simpler constructor when constructing ConstantInst.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34793 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0050c737c5
commit
ef2185b4d2
@ -88,8 +88,7 @@ static Constant *CastConstantVector(ConstantVector *CV,
|
|||||||
for (unsigned i = 0; i != SrcNumElts; ++i) {
|
for (unsigned i = 0; i != SrcNumElts; ++i) {
|
||||||
double V =
|
double V =
|
||||||
DoubleToBits(cast<ConstantFP>(CV->getOperand(i))->getValue());
|
DoubleToBits(cast<ConstantFP>(CV->getOperand(i))->getValue());
|
||||||
Constant *C = ConstantInt::get(Type::Int64Ty,
|
Constant *C = ConstantInt::get(APIntOps::RoundDoubleToAPInt(V));
|
||||||
APIntOps::RoundDoubleToAPInt(V));
|
|
||||||
Result.push_back(ConstantExpr::getBitCast(C, DstEltTy ));
|
Result.push_back(ConstantExpr::getBitCast(C, DstEltTy ));
|
||||||
}
|
}
|
||||||
return ConstantVector::get(Result);
|
return ConstantVector::get(Result);
|
||||||
@ -178,14 +177,14 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
|
if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
|
||||||
uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||||
APInt Val(APIntOps::RoundDoubleToAPInt(FPC->getValue(), DestBitWidth));
|
APInt Val(APIntOps::RoundDoubleToAPInt(FPC->getValue(), DestBitWidth));
|
||||||
return ConstantInt::get(DestTy, Val);
|
return ConstantInt::get(Val);
|
||||||
}
|
}
|
||||||
return 0; // Can't fold.
|
return 0; // Can't fold.
|
||||||
case Instruction::FPToSI:
|
case Instruction::FPToSI:
|
||||||
if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
|
if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
|
||||||
uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||||
APInt Val(APIntOps::RoundDoubleToAPInt(FPC->getValue(), DestBitWidth));
|
APInt Val(APIntOps::RoundDoubleToAPInt(FPC->getValue(), DestBitWidth));
|
||||||
return ConstantInt::get(DestTy, Val);
|
return ConstantInt::get(Val);
|
||||||
}
|
}
|
||||||
return 0; // Can't fold.
|
return 0; // Can't fold.
|
||||||
case Instruction::IntToPtr: //always treated as unsigned
|
case Instruction::IntToPtr: //always treated as unsigned
|
||||||
@ -209,7 +208,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||||
APInt Result(CI->getValue());
|
APInt Result(CI->getValue());
|
||||||
Result.zext(BitWidth);
|
Result.zext(BitWidth);
|
||||||
return ConstantInt::get(DestTy, Result);
|
return ConstantInt::get(Result);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case Instruction::SExt:
|
case Instruction::SExt:
|
||||||
@ -217,7 +216,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||||
APInt Result(CI->getValue());
|
APInt Result(CI->getValue());
|
||||||
Result.sext(BitWidth);
|
Result.sext(BitWidth);
|
||||||
return ConstantInt::get(DestTy, Result);
|
return ConstantInt::get(Result);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case Instruction::Trunc:
|
case Instruction::Trunc:
|
||||||
@ -225,7 +224,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
|
|||||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||||
APInt Result(CI->getValue());
|
APInt Result(CI->getValue());
|
||||||
Result.trunc(BitWidth);
|
Result.trunc(BitWidth);
|
||||||
return ConstantInt::get(DestTy, Result);
|
return ConstantInt::get(Result);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
case Instruction::BitCast:
|
case Instruction::BitCast:
|
||||||
@ -582,55 +581,55 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case Instruction::Add:
|
case Instruction::Add:
|
||||||
return ConstantInt::get(C1->getType(), C1V + C2V);
|
return ConstantInt::get(C1V + C2V);
|
||||||
case Instruction::Sub:
|
case Instruction::Sub:
|
||||||
return ConstantInt::get(C1->getType(), C1V - C2V);
|
return ConstantInt::get(C1V - C2V);
|
||||||
case Instruction::Mul:
|
case Instruction::Mul:
|
||||||
return ConstantInt::get(C1->getType(), C1V * C2V);
|
return ConstantInt::get(C1V * C2V);
|
||||||
case Instruction::UDiv:
|
case Instruction::UDiv:
|
||||||
if (CI2->isNullValue())
|
if (CI2->isNullValue())
|
||||||
return 0; // X / 0 -> can't fold
|
return 0; // X / 0 -> can't fold
|
||||||
return ConstantInt::get(C1->getType(), C1V.udiv(C2V));
|
return ConstantInt::get(C1V.udiv(C2V));
|
||||||
case Instruction::SDiv:
|
case Instruction::SDiv:
|
||||||
if (CI2->isNullValue())
|
if (CI2->isNullValue())
|
||||||
return 0; // X / 0 -> can't fold
|
return 0; // X / 0 -> can't fold
|
||||||
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
|
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
|
||||||
return 0; // MIN_INT / -1 -> overflow
|
return 0; // MIN_INT / -1 -> overflow
|
||||||
return ConstantInt::get(C1->getType(), C1V.sdiv(C2V));
|
return ConstantInt::get(C1V.sdiv(C2V));
|
||||||
case Instruction::URem:
|
case Instruction::URem:
|
||||||
if (C2->isNullValue())
|
if (C2->isNullValue())
|
||||||
return 0; // X / 0 -> can't fold
|
return 0; // X / 0 -> can't fold
|
||||||
return ConstantInt::get(C1->getType(), C1V.urem(C2V));
|
return ConstantInt::get(C1V.urem(C2V));
|
||||||
case Instruction::SRem:
|
case Instruction::SRem:
|
||||||
if (CI2->isNullValue())
|
if (CI2->isNullValue())
|
||||||
return 0; // X % 0 -> can't fold
|
return 0; // X % 0 -> can't fold
|
||||||
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
|
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
|
||||||
return 0; // MIN_INT % -1 -> overflow
|
return 0; // MIN_INT % -1 -> overflow
|
||||||
return ConstantInt::get(C1->getType(), C1V.srem(C2V));
|
return ConstantInt::get(C1V.srem(C2V));
|
||||||
case Instruction::And:
|
case Instruction::And:
|
||||||
return ConstantInt::get(C1->getType(), C1V & C2V);
|
return ConstantInt::get(C1V & C2V);
|
||||||
case Instruction::Or:
|
case Instruction::Or:
|
||||||
return ConstantInt::get(C1->getType(), C1V | C2V);
|
return ConstantInt::get(C1V | C2V);
|
||||||
case Instruction::Xor:
|
case Instruction::Xor:
|
||||||
return ConstantInt::get(C1->getType(), C1V ^ C2V);
|
return ConstantInt::get(C1V ^ C2V);
|
||||||
case Instruction::Shl:
|
case Instruction::Shl:
|
||||||
if (uint32_t shiftAmt = C2V.getZExtValue())
|
if (uint32_t shiftAmt = C2V.getZExtValue())
|
||||||
if (shiftAmt < C1V.getBitWidth())
|
if (shiftAmt < C1V.getBitWidth())
|
||||||
return ConstantInt::get(C1->getType(), C1V.shl(shiftAmt));
|
return ConstantInt::get(C1V.shl(shiftAmt));
|
||||||
else
|
else
|
||||||
return UndefValue::get(C1->getType()); // too big shift is undef
|
return UndefValue::get(C1->getType()); // too big shift is undef
|
||||||
return const_cast<ConstantInt*>(CI1); // Zero shift is identity
|
return const_cast<ConstantInt*>(CI1); // Zero shift is identity
|
||||||
case Instruction::LShr:
|
case Instruction::LShr:
|
||||||
if (uint32_t shiftAmt = C2V.getZExtValue())
|
if (uint32_t shiftAmt = C2V.getZExtValue())
|
||||||
if (shiftAmt < C1V.getBitWidth())
|
if (shiftAmt < C1V.getBitWidth())
|
||||||
return ConstantInt::get(C1->getType(), C1V.lshr(shiftAmt));
|
return ConstantInt::get(C1V.lshr(shiftAmt));
|
||||||
else
|
else
|
||||||
return UndefValue::get(C1->getType()); // too big shift is undef
|
return UndefValue::get(C1->getType()); // too big shift is undef
|
||||||
return const_cast<ConstantInt*>(CI1); // Zero shift is identity
|
return const_cast<ConstantInt*>(CI1); // Zero shift is identity
|
||||||
case Instruction::AShr:
|
case Instruction::AShr:
|
||||||
if (uint32_t shiftAmt = C2V.getZExtValue())
|
if (uint32_t shiftAmt = C2V.getZExtValue())
|
||||||
if (shiftAmt < C1V.getBitWidth())
|
if (shiftAmt < C1V.getBitWidth())
|
||||||
return ConstantInt::get(C1->getType(), C1V.ashr(shiftAmt));
|
return ConstantInt::get(C1V.ashr(shiftAmt));
|
||||||
else
|
else
|
||||||
return UndefValue::get(C1->getType()); // too big shift is undef
|
return UndefValue::get(C1->getType()); // too big shift is undef
|
||||||
return const_cast<ConstantInt*>(CI1); // Zero shift is identity
|
return const_cast<ConstantInt*>(CI1); // Zero shift is identity
|
||||||
|
Loading…
Reference in New Issue
Block a user