}
}
+ // Check that src isn't captured by the called function since the
+ // transformation can cause aliasing issues in that case.
+ for (unsigned i = 0, e = CS.arg_size(); i != e; ++i)
+ if (CS.getArgument(i) == cpySrc && !CS.doesNotCapture(i))
+ return false;
+
// Since we're changing the parameter to the callsite, we need to make sure
// that what would be the new parameter dominates the callsite.
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
%0 = type { x86_fp80, x86_fp80 }
-define internal fastcc void @initialize(%0* noalias sret %agg.result) nounwind {
+define internal fastcc void @initialize(%0* noalias nocapture sret %agg.result) nounwind {
entry:
%agg.result.03 = getelementptr %0* %agg.result, i32 0, i32 0
store x86_fp80 0xK00000000000000000000, x86_fp80* %agg.result.03
ret void
}
-declare fastcc x86_fp80 @passed_uninitialized(%0*) nounwind
+declare fastcc x86_fp80 @passed_uninitialized(%0* nocapture) nounwind
define fastcc void @badly_optimized() nounwind {
entry:
%a = type { i32 }
%b = type { float }
-declare void @g(%a*)
+declare void @g(%a* nocapture)
define float @f() {
entry:
--- /dev/null
+; RUN: opt < %s -basicaa -memcpyopt -S | FileCheck %s
+
+target datalayout = "e"
+
+declare void @foo(i8*)
+declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
+
+define void @test() {
+ %ptr1 = alloca i8
+ %ptr2 = alloca i8
+ call void @foo(i8* %ptr2)
+ call void @llvm.memcpy.p0i8.p0i8.i32(i8* %ptr1, i8* %ptr2, i32 1, i32 1, i1 false)
+ call void @foo(i8* %ptr1)
+ ret void
+
+ ; Check that the transformation isn't applied if the called function can
+ ; capture the pointer argument (i.e. the nocapture attribute isn't present)
+ ; CHECK-LABEL: @test(
+ ; CHECK: call void @foo(i8* %ptr2)
+ ; CHECK-NEXT: call void @llvm.memcpy
+ ; CHECK-NEXT: call void @foo(i8* %ptr1)
+}
ret void
}
-declare void @_Z3barv(%"class.std::auto_ptr"* sret)
+declare void @_Z3barv(%"class.std::auto_ptr"* nocapture sret)
; CHECK: ret void
}
-declare void @ccoshl(%0* sret , x86_fp80, x86_fp80) nounwind
+declare void @ccoshl(%0* nocapture sret, x86_fp80, x86_fp80) nounwind
; The intermediate alloca and one of the memcpy's should be eliminated, the
ret void
}
-declare void @f1(%struct.big* sret)
+declare void @f1(%struct.big* nocapture sret)
declare void @f2(%struct.big*)
; CHECK: attributes [[NUW]] = { nounwind }
ret void
}
-declare void @ccoshl(%0* noalias sret, %0* byval) nounwind
+declare void @ccoshl(%0* noalias nocapture sret, %0* byval) nounwind
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind