[PATCH] D41296: Limit size of SROA - generated register names
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 08:56:20 PST 2017
serge-sans-paille created this revision.
serge-sans-paille added reviewers: chandlerc, hfinkel.
Otherwise, as in the test attached to this patch, huge slowdown happen because of manipulation of very large string.
Repository:
rL LLVM
https://reviews.llvm.org/D41296
Files:
lib/Transforms/Scalar/SROA.cpp
test/Transforms/SROA/register-name-too-long.ll
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 }
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41296.127145.patch
Type: text/x-patch
Size: 3303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171215/25646a4c/attachment.bin>
More information about the llvm-commits
mailing list