Index: lib/Transforms/Scalar/SROA.cpp =================================================================== --- lib/Transforms/Scalar/SROA.cpp +++ lib/Transforms/Scalar/SROA.cpp @@ -3949,9 +3949,14 @@ // the alloca's alignment unconstrained. if (Alignment <= DL.getABITypeAlignment(SliceTy)) Alignment = 0; + + StringRef AIName = AI.getName(); + size_t Offset = AIName.find(".sroa."); NewAI = new AllocaInst( - SliceTy, AI.getType()->getAddressSpace(), nullptr, Alignment, - AI.getName() + ".sroa." + Twine(P.begin() - AS.begin()), &AI); + SliceTy, AI.getType()->getAddressSpace(), nullptr, Alignment, + ((Offset != StringRef::npos) ? AIName.substr(0, Offset) : AIName) + + ".sroa." + Twine(P.begin() - AS.begin()), + &AI); ++NumNewAllocas; } Index: test/Transforms/SROA/register-name-too-long.ll =================================================================== --- test/Transforms/SROA/register-name-too-long.ll +++ test/Transforms/SROA/register-name-too-long.ll @@ -0,0 +1,55 @@ +; this etst case used to swap because of too many intermediate steps resulting in utterly long names +; RUN: opt < %s -sroa -S + +source_filename = "bugpoint-output-1d9ce6e.bc" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%Array = type { [812 x i8] } +%CharArrayPair = type { i8, %Array } +%Either = type { [814 x i8] } + +; Function Attrs: noinline nounwind uwtable +define void @foo() unnamed_addr #0 { +start: + %_9 = alloca %Array, align 1 + %_8 = alloca %Array, align 1 + %array = alloca %Array, align 1 + %_2 = alloca %CharArrayPair, align 1 + %either = alloca %Either, align 1 + %0 = bitcast %Either* %either to %CharArrayPair* + %1 = bitcast %CharArrayPair* %_2 to i8* + %2 = bitcast %CharArrayPair* %0 to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %1, i64 813, i32 1, i1 false) + %3 = bitcast %Either* %either to %CharArrayPair* + %4 = bitcast %CharArrayPair* %3 to i8* + %5 = load i8, i8* %4 + br i1 undef, label %bb1, label %bb2 + +bb1: ; preds = %start + %6 = bitcast %Either* %either to %CharArrayPair* + %7 = getelementptr inbounds %CharArrayPair, %CharArrayPair* %6, i32 0, i32 1 + %8 = bitcast %Array* %7 to i8* + %9 = bitcast %Array* %_8 to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %9, i8* %8, i64 812, i32 1, i1 false) + %10 = bitcast %Array* %_8 to i8* + %11 = bitcast %Array* %array to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %11, i8* %10, i64 812, i32 1, i1 false) + ret void + +bb2: ; preds = %start + %12 = bitcast %Either* %either to %Array* + %13 = bitcast %Array* %12 to i8* + %14 = bitcast %Array* %_9 to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %14, i8* %13, i64 812, i32 1, i1 false) + %15 = bitcast %Array* %_9 to i8* + %16 = bitcast %Array* %array to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %16, i8* %15, i64 812, i32 1, i1 false) + unreachable +} + +; Function Attrs: argmemonly nounwind +declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #1 + +attributes #0 = { noinline nounwind uwtable } +attributes #1 = { argmemonly nounwind }