llvm.org GIT mirror llvm / b580bd1
Merge 81845 from mainline. fix PR4963: folding insertvalue would sometimes turn a packed struct into an unpacked one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_26@81980 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 11 years ago
2 changed file(s) with 32 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
498498
499499 if (isa(Agg)) {
500500 // Insertion of constant into aggregate undef
501 // Optimize away insertion of undef
501 // Optimize away insertion of undef.
502502 if (isa(Val))
503503 return const_cast(Agg);
504
504505 // Otherwise break the aggregate undef into multiple undefs and do
505 // the insertion
506 // the insertion.
506507 const CompositeType *AggTy = cast(Agg->getType());
507508 unsigned numOps;
508509 if (const ArrayType *AR = dyn_cast(AggTy))
509510 numOps = AR->getNumElements();
510511 else
511512 numOps = cast(AggTy)->getNumElements();
513
512514 std::vector Ops(numOps);
513515 for (unsigned i = 0; i < numOps; ++i) {
514516 const Type *MemberTy = AggTy->getTypeAtIndex(i);
519521 UndefValue::get(MemberTy);
520522 Ops[i] = const_cast(Op);
521523 }
522 if (isa(AggTy))
523 return ConstantStruct::get(Context, Ops);
524 else
525 return ConstantArray::get(cast(AggTy), Ops);
526 }
524
525 if (const StructType* ST = dyn_cast(AggTy))
526 return ConstantStruct::get(Context, Ops, ST->isPacked());
527 return ConstantArray::get(cast(AggTy), Ops);
528 }
529
527530 if (isa(Agg)) {
528531 // Insertion of constant into aggregate zero
529 // Optimize away insertion of zero
532 // Optimize away insertion of zero.
530533 if (Val->isNullValue())
531534 return const_cast(Agg);
535
532536 // Otherwise break the aggregate zero into multiple zeros and do
533 // the insertion
537 // the insertion.
534538 const CompositeType *AggTy = cast(Agg->getType());
535539 unsigned numOps;
536540 if (const ArrayType *AR = dyn_cast(AggTy))
537541 numOps = AR->getNumElements();
538542 else
539543 numOps = cast(AggTy)->getNumElements();
544
540545 std::vector Ops(numOps);
541546 for (unsigned i = 0; i < numOps; ++i) {
542547 const Type *MemberTy = AggTy->getTypeAtIndex(i);
548553 Constant::getNullValue(MemberTy);
549554 Ops[i] = const_cast(Op);
550555 }
551 if (isa(AggTy))
552 return ConstantStruct::get(Context, Ops);
553 else
554 return ConstantArray::get(cast(AggTy), Ops);
555 }
556
557 if (const StructType* ST = dyn_cast(AggTy))
558 return ConstantStruct::get(Context, Ops, ST->isPacked());
559 return ConstantArray::get(cast(AggTy), Ops);
560 }
561
556562 if (isa(Agg) || isa(Agg)) {
557 // Insertion of constant into aggregate constant
563 // Insertion of constant into aggregate constant.
558564 std::vector Ops(Agg->getNumOperands());
559565 for (unsigned i = 0; i < Agg->getNumOperands(); ++i) {
560566 const Constant *Op =
564570 Agg->getOperand(i);
565571 Ops[i] = const_cast(Op);
566572 }
567 Constant *C;
568 if (isa(Agg->getType()))
569 C = ConstantStruct::get(Context, Ops);
570 else
571 C = ConstantArray::get(cast(Agg->getType()), Ops);
572 return C;
573
574 if (const StructType* ST = dyn_cast(Agg->getType()))
575 return ConstantStruct::get(Context, Ops, ST->isPacked());
576 return ConstantArray::get(cast(Agg->getType()), Ops);
573577 }
574578
575579 return 0;
584588 if (C1->getType() == Type::getPPC_FP128Ty(Context))
585589 return 0;
586590
587 // Handle UndefValue up front
591 // Handle UndefValue up front.
588592 if (isa(C1) || isa(C2)) {
589593 switch (Opcode) {
590594 case Instruction::Xor:
2020 store {{i32},{float, double}} insertvalue ({{i32},{float, double}} zeroinitializer, double 20.0, 1, 1), {{i32},{float, double}}* %p
2121 ret float extractvalue ({{i32},{float, double}} zeroinitializer, 1, 0)
2222 }
23
24
25 ; PR4963
26 define <{ i32, i32 }> @test57() {
27 ret <{ i32, i32 }> insertvalue (<{ i32, i32 }> zeroinitializer, i32 4, 1)
28 }