[LLVMbugs] [Bug 23226] New: Missed optimisation - memcpy is not removed

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Apr 14 07:41:48 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23226

            Bug ID: 23226
           Summary: Missed optimisation - memcpy is not removed
           Product: new-bugs
           Version: 3.6
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: nick at indigorenderer.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The memcpy on line 24 is not optimised away.
It is not completely dead - there is a read from the destination memory region
on line 26 and 27.

It could be optimised to remove the memcpy, and just read from the source
memory instead.

Note that the only reason I'm using memcpy in the first place is because load
and stores for array types produce terrible code and/or kill llvm compilation.


Code paste with line numbers here: http://pastie.org/10089845

Please let me know if anyone wants more information - I can provide some
context of what I am trying to do etc.. if needed.

The IR is from LLVM 3.4 but the problem still exists with 3.6.


; ModuleID = 'WinterModule'
target datalayout =
"e-p:64:64:64-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"

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

; Function Attrs: nounwind
define void @main_array_int__256___array_int__256__([256 x i32]* noalias
nocapture sret %ret, [256 x i32]* noalias nocapture readonly %vals, [256 x
i32]* noalias nocapture readonly %b) #0 {
entry:
  %"New running state.i" = alloca [256 x i32], align 4
  %"Running state.i" = alloca [256 x i32], align 4
  %0 = bitcast [256 x i32]* %"New running state.i" to i8*
  call void @llvm.lifetime.start(i64 1024, i8* %0) #0
  %1 = bitcast [256 x i32]* %"Running state.i" to i8*
  call void @llvm.lifetime.start(i64 1024, i8* %1) #0
  %2 = bitcast [256 x i32]* %b to i8*
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %2, i32 1024, i32 4, i1
false) #0
  br label %loop.i

loop.i:                                           ; preds = %loop.i, %entry
  %indvars.iv.i = phi i64 [ %indvars.iv.next.i, %loop.i ], [ 0, %entry ]
  %"array elem ptr.i" = getelementptr inbounds [256 x i32]* %vals, i64 0, i64
%indvars.iv.i
  %"array elem.i" = load i32* %"array elem ptr.i", align 4
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %1, i8* %0, i32 1024, i32 4, i1
false) #0
  %3 = sext i32 %"array elem.i" to i64
  %4 = getelementptr inbounds [256 x i32]* %"Running state.i", i64 0, i64 %3
  %5 = load i32* %4, align 4
  %6 = add i32 %5, 1
  %"new elem ptr.i.i.i" = getelementptr inbounds [256 x i32]* %"New running
state.i", i64 0, i64 %3
  store i32 %6, i32* %"new elem ptr.i.i.i", align 4
  %indvars.iv.next.i = add nuw nsw i64 %indvars.iv.i, 1
  %exitcond.i = icmp eq i64 %indvars.iv.next.i, 256
  br i1 %exitcond.i, label
%fold_function_array_int__256___int__array_int__256____array_int__256___array_int__256__.exit,
label %loop.i

fold_function_array_int__256___int__array_int__256____array_int__256___array_int__256__.exit:
; preds = %loop.i
  %7 = bitcast [256 x i32]* %ret to i8*
  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %7, i8* %0, i32 1024, i32 4, i1
false) #0
  call void @llvm.lifetime.end(i64 1024, i8* %0) #0
  call void @llvm.lifetime.end(i64 1024, i8* %1) #0
  ret void
}

; Function Attrs: nounwind
declare void @llvm.lifetime.start(i64, i8* nocapture) #0

; Function Attrs: nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) #0

attributes #0 = { nounwind }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150414/257a9ce0/attachment.html>


More information about the llvm-bugs mailing list