mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
fix PR4963: folding insertvalue would sometimes turn a packed struct into
an unpacked one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81845 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -499,17 +499,19 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
|
|||||||
|
|
||||||
if (isa<UndefValue>(Agg)) {
|
if (isa<UndefValue>(Agg)) {
|
||||||
// Insertion of constant into aggregate undef
|
// Insertion of constant into aggregate undef
|
||||||
// Optimize away insertion of undef
|
// Optimize away insertion of undef.
|
||||||
if (isa<UndefValue>(Val))
|
if (isa<UndefValue>(Val))
|
||||||
return const_cast<Constant*>(Agg);
|
return const_cast<Constant*>(Agg);
|
||||||
|
|
||||||
// Otherwise break the aggregate undef into multiple undefs and do
|
// Otherwise break the aggregate undef into multiple undefs and do
|
||||||
// the insertion
|
// the insertion.
|
||||||
const CompositeType *AggTy = cast<CompositeType>(Agg->getType());
|
const CompositeType *AggTy = cast<CompositeType>(Agg->getType());
|
||||||
unsigned numOps;
|
unsigned numOps;
|
||||||
if (const ArrayType *AR = dyn_cast<ArrayType>(AggTy))
|
if (const ArrayType *AR = dyn_cast<ArrayType>(AggTy))
|
||||||
numOps = AR->getNumElements();
|
numOps = AR->getNumElements();
|
||||||
else
|
else
|
||||||
numOps = cast<StructType>(AggTy)->getNumElements();
|
numOps = cast<StructType>(AggTy)->getNumElements();
|
||||||
|
|
||||||
std::vector<Constant*> Ops(numOps);
|
std::vector<Constant*> Ops(numOps);
|
||||||
for (unsigned i = 0; i < numOps; ++i) {
|
for (unsigned i = 0; i < numOps; ++i) {
|
||||||
const Type *MemberTy = AggTy->getTypeAtIndex(i);
|
const Type *MemberTy = AggTy->getTypeAtIndex(i);
|
||||||
@@ -520,24 +522,27 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
|
|||||||
UndefValue::get(MemberTy);
|
UndefValue::get(MemberTy);
|
||||||
Ops[i] = const_cast<Constant*>(Op);
|
Ops[i] = const_cast<Constant*>(Op);
|
||||||
}
|
}
|
||||||
if (isa<StructType>(AggTy))
|
|
||||||
return ConstantStruct::get(Context, Ops);
|
if (const StructType* ST = dyn_cast<StructType>(AggTy))
|
||||||
else
|
return ConstantStruct::get(Context, Ops, ST->isPacked());
|
||||||
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
|
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<ConstantAggregateZero>(Agg)) {
|
if (isa<ConstantAggregateZero>(Agg)) {
|
||||||
// Insertion of constant into aggregate zero
|
// Insertion of constant into aggregate zero
|
||||||
// Optimize away insertion of zero
|
// Optimize away insertion of zero.
|
||||||
if (Val->isNullValue())
|
if (Val->isNullValue())
|
||||||
return const_cast<Constant*>(Agg);
|
return const_cast<Constant*>(Agg);
|
||||||
|
|
||||||
// Otherwise break the aggregate zero into multiple zeros and do
|
// Otherwise break the aggregate zero into multiple zeros and do
|
||||||
// the insertion
|
// the insertion.
|
||||||
const CompositeType *AggTy = cast<CompositeType>(Agg->getType());
|
const CompositeType *AggTy = cast<CompositeType>(Agg->getType());
|
||||||
unsigned numOps;
|
unsigned numOps;
|
||||||
if (const ArrayType *AR = dyn_cast<ArrayType>(AggTy))
|
if (const ArrayType *AR = dyn_cast<ArrayType>(AggTy))
|
||||||
numOps = AR->getNumElements();
|
numOps = AR->getNumElements();
|
||||||
else
|
else
|
||||||
numOps = cast<StructType>(AggTy)->getNumElements();
|
numOps = cast<StructType>(AggTy)->getNumElements();
|
||||||
|
|
||||||
std::vector<Constant*> Ops(numOps);
|
std::vector<Constant*> Ops(numOps);
|
||||||
for (unsigned i = 0; i < numOps; ++i) {
|
for (unsigned i = 0; i < numOps; ++i) {
|
||||||
const Type *MemberTy = AggTy->getTypeAtIndex(i);
|
const Type *MemberTy = AggTy->getTypeAtIndex(i);
|
||||||
@@ -549,13 +554,14 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
|
|||||||
Constant::getNullValue(MemberTy);
|
Constant::getNullValue(MemberTy);
|
||||||
Ops[i] = const_cast<Constant*>(Op);
|
Ops[i] = const_cast<Constant*>(Op);
|
||||||
}
|
}
|
||||||
if (isa<StructType>(AggTy))
|
|
||||||
return ConstantStruct::get(Context, Ops);
|
if (const StructType* ST = dyn_cast<StructType>(AggTy))
|
||||||
else
|
return ConstantStruct::get(Context, Ops, ST->isPacked());
|
||||||
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
|
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<ConstantStruct>(Agg) || isa<ConstantArray>(Agg)) {
|
if (isa<ConstantStruct>(Agg) || isa<ConstantArray>(Agg)) {
|
||||||
// Insertion of constant into aggregate constant
|
// Insertion of constant into aggregate constant.
|
||||||
std::vector<Constant*> Ops(Agg->getNumOperands());
|
std::vector<Constant*> Ops(Agg->getNumOperands());
|
||||||
for (unsigned i = 0; i < Agg->getNumOperands(); ++i) {
|
for (unsigned i = 0; i < Agg->getNumOperands(); ++i) {
|
||||||
const Constant *Op =
|
const Constant *Op =
|
||||||
@@ -565,12 +571,10 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
|
|||||||
Agg->getOperand(i);
|
Agg->getOperand(i);
|
||||||
Ops[i] = const_cast<Constant*>(Op);
|
Ops[i] = const_cast<Constant*>(Op);
|
||||||
}
|
}
|
||||||
Constant *C;
|
|
||||||
if (isa<StructType>(Agg->getType()))
|
if (const StructType* ST = dyn_cast<StructType>(Agg->getType()))
|
||||||
C = ConstantStruct::get(Context, Ops);
|
return ConstantStruct::get(Context, Ops, ST->isPacked());
|
||||||
else
|
return ConstantArray::get(cast<ArrayType>(Agg->getType()), Ops);
|
||||||
C = ConstantArray::get(cast<ArrayType>(Agg->getType()), Ops);
|
|
||||||
return C;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -585,7 +589,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
|||||||
if (C1->getType() == Type::getPPC_FP128Ty(Context))
|
if (C1->getType() == Type::getPPC_FP128Ty(Context))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Handle UndefValue up front
|
// Handle UndefValue up front.
|
||||||
if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
|
if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
|
||||||
switch (Opcode) {
|
switch (Opcode) {
|
||||||
case Instruction::Xor:
|
case Instruction::Xor:
|
||||||
|
@@ -21,3 +21,9 @@ define float @dar({{i32},{float, double}}* %p) nounwind {
|
|||||||
store {{i32},{float, double}} insertvalue ({{i32},{float, double}} zeroinitializer, double 20.0, 1, 1), {{i32},{float, double}}* %p
|
store {{i32},{float, double}} insertvalue ({{i32},{float, double}} zeroinitializer, double 20.0, 1, 1), {{i32},{float, double}}* %p
|
||||||
ret float extractvalue ({{i32},{float, double}} zeroinitializer, 1, 0)
|
ret float extractvalue ({{i32},{float, double}} zeroinitializer, 1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
; PR4963
|
||||||
|
define <{ i32, i32 }> @test57() {
|
||||||
|
ret <{ i32, i32 }> insertvalue (<{ i32, i32 }> zeroinitializer, i32 4, 1)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user