llvm.org GIT mirror llvm / a756b1d
Fix a crash in scalarrepl for memcpy/memmove where the source and destination are the same. I had already fixed a similar problem where the source and destination were different bitcasts derived from the same alloca, but the previous fix still did not handle the case where both operands are exactly the same value. Radar 7552893. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93848 91177308-0d34-0410-b5e6-96231b3b80d8 Bob Wilson 9 years ago
2 changed file(s) with 28 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
751751 }
752752 break;
753753 }
754 // If OtherPtr has already been rewritten, this intrinsic will be dead.
755 if (OtherPtr == NewElts[0])
754 // Copying the alloca to itself is a no-op: just delete it.
755 if (OtherPtr == AI || OtherPtr == NewElts[0]) {
756 // This code will run twice for a no-op memcpy -- once for each operand.
757 // Put only one reference to MI on the DeadInsts list.
758 for (SmallVector::const_iterator I = DeadInsts.begin(),
759 E = DeadInsts.end(); I != E; ++I)
760 if (*I == MI) return;
761 DeadInsts.push_back(MI);
756762 return;
763 }
757764
758765 if (ConstantExpr *BCE = dyn_cast(OtherPtr))
759766 if (BCE->getOpcode() == Instruction::BitCast)
778785 Value *OtherElt = 0;
779786 unsigned OtherEltAlign = MemAlignment;
780787
781 if (OtherPtr == AI) {
782 OtherElt = NewElts[i];
783 OtherEltAlign = 0;
784 } else if (OtherPtr) {
788 if (OtherPtr) {
785789 Value *Idx[2] = { Zero,
786790 ConstantInt::get(Type::getInt32Ty(MI->getContext()), i) };
787791 OtherElt = GetElementPtrInst::CreateInBounds(OtherPtr, Idx, Idx + 2,
0 ; RUN: opt < %s -scalarrepl -S | FileCheck %s
1 ; Radar 7552893
2
3 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
4
5 %struct.test = type { [3 x double ] }
6
7 define arm_apcscc void @test_memcpy_self() nounwind {
8 ; CHECK: @test_memcpy_self
9 ; CHECK-NOT: alloca
10 ; CHECK: ret void
11 %1 = alloca %struct.test
12 %2 = bitcast %struct.test* %1 to i8*
13 call void @llvm.memcpy.i32(i8* %2, i8* %2, i32 24, i32 4)
14 ret void
15 }
16
17 declare void @llvm.memcpy.i32(i8* nocapture, i8* nocapture, i32, i32) nounwind