@@ -499,17 +499,19 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
499
499
500
500
if (isa<UndefValue>(Agg)) {
501
501
// Insertion of constant into aggregate undef
502
- // Optimize away insertion of undef
502
+ // Optimize away insertion of undef.
503
503
if (isa<UndefValue>(Val))
504
504
return const_cast <Constant*>(Agg);
505
+
505
506
// Otherwise break the aggregate undef into multiple undefs and do
506
- // the insertion
507
+ // the insertion.
507
508
const CompositeType *AggTy = cast<CompositeType>(Agg->getType ());
508
509
unsigned numOps;
509
510
if (const ArrayType *AR = dyn_cast<ArrayType>(AggTy))
510
511
numOps = AR->getNumElements ();
511
512
else
512
513
numOps = cast<StructType>(AggTy)->getNumElements ();
514
+
513
515
std::vector<Constant*> Ops (numOps);
514
516
for (unsigned i = 0 ; i < numOps; ++i) {
515
517
const Type *MemberTy = AggTy->getTypeAtIndex (i);
@@ -520,24 +522,27 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
520
522
UndefValue::get (MemberTy);
521
523
Ops[i] = const_cast <Constant*>(Op);
522
524
}
523
- if (isa<StructType>(AggTy))
524
- return ConstantStruct::get (Context, Ops);
525
- else
526
- return ConstantArray::get (cast<ArrayType>(AggTy), Ops);
525
+
526
+ if ( const StructType* ST = dyn_cast<StructType>(AggTy))
527
+ return ConstantStruct::get (Context, Ops, ST-> isPacked ());
528
+ return ConstantArray::get (cast<ArrayType>(AggTy), Ops);
527
529
}
530
+
528
531
if (isa<ConstantAggregateZero>(Agg)) {
529
532
// Insertion of constant into aggregate zero
530
- // Optimize away insertion of zero
533
+ // Optimize away insertion of zero.
531
534
if (Val->isNullValue ())
532
535
return const_cast <Constant*>(Agg);
536
+
533
537
// Otherwise break the aggregate zero into multiple zeros and do
534
- // the insertion
538
+ // the insertion.
535
539
const CompositeType *AggTy = cast<CompositeType>(Agg->getType ());
536
540
unsigned numOps;
537
541
if (const ArrayType *AR = dyn_cast<ArrayType>(AggTy))
538
542
numOps = AR->getNumElements ();
539
543
else
540
544
numOps = cast<StructType>(AggTy)->getNumElements ();
545
+
541
546
std::vector<Constant*> Ops (numOps);
542
547
for (unsigned i = 0 ; i < numOps; ++i) {
543
548
const Type *MemberTy = AggTy->getTypeAtIndex (i);
@@ -549,13 +554,14 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
549
554
Constant::getNullValue (MemberTy);
550
555
Ops[i] = const_cast <Constant*>(Op);
551
556
}
552
- if (isa<StructType>(AggTy))
553
- return ConstantStruct::get (Context, Ops);
554
- else
555
- return ConstantArray::get (cast<ArrayType>(AggTy), Ops);
557
+
558
+ if ( const StructType* ST = dyn_cast<StructType>(AggTy))
559
+ return ConstantStruct::get (Context, Ops, ST-> isPacked ());
560
+ return ConstantArray::get (cast<ArrayType>(AggTy), Ops);
556
561
}
562
+
557
563
if (isa<ConstantStruct>(Agg) || isa<ConstantArray>(Agg)) {
558
- // Insertion of constant into aggregate constant
564
+ // Insertion of constant into aggregate constant.
559
565
std::vector<Constant*> Ops (Agg->getNumOperands ());
560
566
for (unsigned i = 0 ; i < Agg->getNumOperands (); ++i) {
561
567
const Constant *Op =
@@ -565,12 +571,10 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
565
571
Agg->getOperand (i);
566
572
Ops[i] = const_cast <Constant*>(Op);
567
573
}
568
- Constant *C;
569
- if (isa<StructType>(Agg->getType ()))
570
- C = ConstantStruct::get (Context, Ops);
571
- else
572
- C = ConstantArray::get (cast<ArrayType>(Agg->getType ()), Ops);
573
- return C;
574
+
575
+ if (const StructType* ST = dyn_cast<StructType>(Agg->getType ()))
576
+ return ConstantStruct::get (Context, Ops, ST->isPacked ());
577
+ return ConstantArray::get (cast<ArrayType>(Agg->getType ()), Ops);
574
578
}
575
579
576
580
return 0 ;
@@ -585,7 +589,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
585
589
if (C1->getType () == Type::getPPC_FP128Ty (Context))
586
590
return 0 ;
587
591
588
- // Handle UndefValue up front
592
+ // Handle UndefValue up front.
589
593
if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
590
594
switch (Opcode) {
591
595
case Instruction::Xor:
0 commit comments