[LLVMbugs] [Bug 14241] New: LoopIdiomRecognize forms an invalid memcpy

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Nov 1 23:30:28 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=14241

             Bug #: 14241
           Summary: LoopIdiomRecognize forms an invalid memcpy
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: chandlerc at gmail.com
                CC: benny.kra at gmail.com, dblaikie at gmail.com,
                    llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Consider the following test case:

% cat bug.cpp 
struct S { int v; };

void f(S *s, unsigned size) {
  S *i = s, *e = s + size - 1;
  while (i != e) {
    *i = *(i + 1);
    ++i;
  }
}

% ./bin/clang -S -emit-llvm -o - -O1 bug.cpp
; ModuleID = 'bug.cpp'
target 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-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.S = type { i32 }

define void @_Z1fP1Sj(%struct.S* %s, i32 %size) nounwind uwtable {
entry:
  %cmp7 = icmp eq i32 %size, 1
  br i1 %cmp7, label %while.end, label %while.cond.while.end_crit_edge

while.cond.while.end_crit_edge:                   ; preds = %entry
  %s9 = bitcast %struct.S* %s to i8*
  %scevgep = getelementptr %struct.S* %s, i64 1
  %scevgep10 = bitcast %struct.S* %scevgep to i8*
  %0 = zext i32 %size to i64
  %1 = shl nuw nsw i64 %0, 2
  %2 = add i64 %1, -4
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %s9, i8* %scevgep10, i64 %2, i32 4,
i1 false)
  br label %while.end

while.end:                                        ; preds =
%while.cond.while.end_crit_edge, %entry
  ret void
}

declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32,
i1) nounwind


Note that we produce a single memcpy call based on the loop trip count. This
isn't valid because the destination overlaps with the source. We need to form
memmove if we do this optimization at all.

Many thanks to David Blaikie for the excellent reduction here.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list