66 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=memcpyopt -S -verify-memoryssa | FileCheck %s3; These memmoves should get optimized to memcpys.4 5target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"6target triple = "x86_64-apple-darwin9.0"7 8@C = external constant [0 x i8]9 10declare void @llvm.memmove.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind11 12define ptr @test1(ptr nocapture %src) nounwind {13; CHECK-LABEL: @test1(14; CHECK-NEXT: entry:15; CHECK-NEXT: [[MUL:%.*]] = mul nuw i64 ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64), 1316; CHECK-NEXT: [[TRUNC:%.*]] = trunc i64 [[MUL]] to i3217; CHECK-NEXT: [[MALLOCCALL:%.*]] = tail call ptr @malloc(i32 [[TRUNC]])18; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[MALLOCCALL]], ptr [[SRC:%.*]], i64 13, i1 false)19; CHECK-NEXT: ret ptr [[MALLOCCALL]]20;21entry:22 %mul = mul nuw i64 ptrtoint (ptr getelementptr (i8, ptr null, i32 1) to i64), 1323 %trunc = trunc i64 %mul to i3224 %malloccall = tail call ptr @malloc(i32 %trunc)25 tail call void @llvm.memmove.p0.p0.i64(ptr %malloccall, ptr %src, i64 13, i1 false)26 ret ptr %malloccall27}28declare noalias ptr @malloc(i32)29 30 31define void @test2(ptr %P) nounwind {32; CHECK-LABEL: @test2(33; CHECK-NEXT: entry:34; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 1635; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P]], ptr [[ADD_PTR]], i64 16, i1 false)36; CHECK-NEXT: ret void37;38entry:39 %add.ptr = getelementptr i8, ptr %P, i64 1640 tail call void @llvm.memmove.p0.p0.i64(ptr %P, ptr %add.ptr, i64 16, i1 false)41 ret void42}43 44; This cannot be optimize because the src/dst really do overlap.45define void @test3(ptr %P) nounwind {46; CHECK-LABEL: @test3(47; CHECK-NEXT: entry:48; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 1649; CHECK-NEXT: tail call void @llvm.memmove.p0.p0.i64(ptr [[P]], ptr [[ADD_PTR]], i64 17, i1 false)50; CHECK-NEXT: ret void51;52entry:53 %add.ptr = getelementptr i8, ptr %P, i64 1654 tail call void @llvm.memmove.p0.p0.i64(ptr %P, ptr %add.ptr, i64 17, i1 false)55 ret void56}57 58define void @test4(ptr %P) nounwind {59; CHECK-LABEL: @test4(60; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P:%.*]], ptr @C, i64 17, i1 false)61; CHECK-NEXT: ret void62;63 tail call void @llvm.memmove.p0.p0.i64(ptr %P, ptr @C, i64 17, i1 false)64 ret void65}66