This is an archive of the discontinued LLVM Phabricator instance.

[memcpyopt] Memcpy-memcpy dependence isn't detected across basic blocks
Needs ReviewPublic

Authored by pcwalton on Aug 12 2016, 3:47 PM.

Details

Summary

Make the memory dependence queries in the memcpy optimizer nonlocal.

This eliminates 28% of the llvm.memcpy calls in librustc.

Fixes PR28958.

Diff Detail

Event Timeline

pcwalton updated this revision to Diff 67929.Aug 12 2016, 3:47 PM
pcwalton retitled this revision from to [memcpyopt] Memcpy-memcpy dependence isn't detected across basic blocks.
pcwalton updated this object.
pcwalton added reviewers: dberlin, majnemer, hfinkel.
pcwalton added a subscriber: llvm-commits.
majnemer edited edge metadata.Aug 12 2016, 3:49 PM

Thanks for the patch!

Could you please reduce the testcase? It contains quite a few unnecessary instructions.

Something along the lines of the following would be more appropriate:

define void @wobble(i8* noalias nocapture sret %arg, i8* nocapture readonly dereferenceable(64) %arg1, i1 zeroext %arg3) local_unnamed_addr #0 {
bb:
  %tmp51 = alloca [64 x i8], align 8
  %tmp51.sub = getelementptr inbounds [64 x i8], [64 x i8]* %tmp51, i64 0, i64 0
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp51.sub, i8* nonnull %arg1, i64 64, i32 8, i1 false)
  br i1 %arg3, label %bb11, label %bb12

bb11:                                             ; preds = %bb
  tail call void @ham() #3
  unreachable

bb12:                                             ; preds = %bb
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %arg, i8* %tmp51.sub, i64 64, i32 8, i1 false)
  ret void
}

; Function Attrs: argmemonly nounwind
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #1

; Function Attrs: noreturn nounwind
declare void @ham() local_unnamed_addr #2
dberlin added inline comments.Aug 13 2016, 8:22 PM
include/llvm/Analysis/MemoryDependenceAnalysis.h
384

I figure you are trying to make the two API's look the same, but the honest truth is: the other API sucks :)

There are a bunch of instructions that affect memory that don't have MemoryLocation's (calls are a good example).

I know you just are pushing the first two lines it does up, and that this means the function will crash on things like fences, etc, but we shouldn't make it worse :)

In any case, if you really want to do this, this should be shoved into a different patch, as it's completely unrelated to your change

pcwalton added inline comments.Aug 22 2016, 12:27 PM
include/llvm/Analysis/MemoryDependenceAnalysis.h
384

OK, I think I'm going to just go the MemorySSA route instead. I wrote some boilerplate code to get MemCpyOpt using MemorySSA, so at this point it'd be awesome if you could summarize how you'd like me to change MemorySSA to conform to MemCpyOpt's requirements :)

I posted an updated version of this patch for review here: https://reviews.llvm.org/D38374