<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Missed optimisation - memcpy is not removed"
   href="https://llvm.org/bugs/show_bug.cgi?id=23226">23226</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimisation - memcpy is not removed
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nick@indigorenderer.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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: <a href="http://pastie.org/10089845">http://pastie.org/10089845</a>

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 }</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>