mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-07 11:33:44 +00:00
Added constant folding support for the extractelement operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25187 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5e1b72c153
commit
bb90a7aa7b
@ -724,6 +724,16 @@ Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Constant *llvm::ConstantFoldExtractElementInstruction(const Constant *Val,
|
||||||
|
const Constant *Idx) {
|
||||||
|
if (const ConstantPacked *CVal = dyn_cast<ConstantPacked>(Val)) {
|
||||||
|
if (const ConstantUInt *CIdx = dyn_cast<ConstantUInt>(Idx)) {
|
||||||
|
return const_cast<Constant*>(CVal->getOperand(CIdx->getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// isZeroSizedType - This type is zero sized if its an array or structure of
|
/// isZeroSizedType - This type is zero sized if its an array or structure of
|
||||||
/// zero sized types. The only leaf zero sized type is an empty structure.
|
/// zero sized types. The only leaf zero sized type is an empty structure.
|
||||||
static bool isMaybeZeroSizedType(const Type *Ty) {
|
static bool isMaybeZeroSizedType(const Type *Ty) {
|
||||||
|
@ -31,6 +31,8 @@ namespace llvm {
|
|||||||
Constant *ConstantFoldSelectInstruction(const Constant *Cond,
|
Constant *ConstantFoldSelectInstruction(const Constant *Cond,
|
||||||
const Constant *V1,
|
const Constant *V1,
|
||||||
const Constant *V2);
|
const Constant *V2);
|
||||||
|
Constant *ConstantFoldExtractElementInstruction(const Constant *Val,
|
||||||
|
const Constant *Idx);
|
||||||
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
|
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
|
||||||
const Constant *V2);
|
const Constant *V2);
|
||||||
Constant *ConstantFoldGetElementPtr(const Constant *C,
|
Constant *ConstantFoldGetElementPtr(const Constant *C,
|
||||||
|
@ -31,6 +31,8 @@ namespace llvm {
|
|||||||
Constant *ConstantFoldSelectInstruction(const Constant *Cond,
|
Constant *ConstantFoldSelectInstruction(const Constant *Cond,
|
||||||
const Constant *V1,
|
const Constant *V1,
|
||||||
const Constant *V2);
|
const Constant *V2);
|
||||||
|
Constant *ConstantFoldExtractElementInstruction(const Constant *Val,
|
||||||
|
const Constant *Idx);
|
||||||
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
|
Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
|
||||||
const Constant *V2);
|
const Constant *V2);
|
||||||
Constant *ConstantFoldGetElementPtr(const Constant *C,
|
Constant *ConstantFoldGetElementPtr(const Constant *C,
|
||||||
|
@ -1403,6 +1403,8 @@ Constant *ConstantExpr::getGetElementPtr(Constant *C,
|
|||||||
|
|
||||||
Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
|
Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
|
||||||
Constant *Idx) {
|
Constant *Idx) {
|
||||||
|
if (Constant *FC = ConstantFoldExtractElementInstruction(Val, Idx))
|
||||||
|
return FC; // Fold a few common cases...
|
||||||
// Look up the constant in the table first to ensure uniqueness
|
// Look up the constant in the table first to ensure uniqueness
|
||||||
std::vector<Constant*> ArgVec(1, Val);
|
std::vector<Constant*> ArgVec(1, Val);
|
||||||
ArgVec.push_back(Idx);
|
ArgVec.push_back(Idx);
|
||||||
|
Loading…
Reference in New Issue
Block a user