diff options
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 9 | ||||
-rw-r--r-- | test/CodeGen/X86/memcpy.ll | 30 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 86e00ce6e2..c1b5ec2538 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -3266,6 +3266,15 @@ static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps, if (VT.bitsGT(LVT)) VT = LVT; } + + // If we're optimizing for size, and there is a limit, bump the maximum number + // of operations inserted down to 4. This is a wild guess that approximates + // the size of a call to memcpy or memset (3 arguments + call). + if (Limit != ~0U) { + const Function *F = DAG.getMachineFunction().getFunction(); + if (F->hasFnAttr(Attribute::OptimizeForSize)) + Limit = 4; + } unsigned NumMemOps = 0; while (Size != 0) { diff --git a/test/CodeGen/X86/memcpy.ll b/test/CodeGen/X86/memcpy.ll index 16bf7c5a38..7bc31bec16 100644 --- a/test/CodeGen/X86/memcpy.ll +++ b/test/CodeGen/X86/memcpy.ll @@ -25,3 +25,33 @@ entry: ; CHECK: memcpy } +; Large constant memcpy's should lower to a call when optimizing for size. +; PR6623 +define void @test3(i8* nocapture %A, i8* nocapture %B) nounwind optsize noredzone { +entry: + tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i32 1, i1 false) + ret void +; CHECK: test3: +; CHECK: memcpy +} + +; Large constant memcpy's should be inlined when not optimizing for size. +define void @test4(i8* nocapture %A, i8* nocapture %B) nounwind noredzone { +entry: + tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %A, i8* %B, i64 64, i32 1, i1 false) + ret void +; CHECK: test4: +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +; CHECK: movq +} + |