[LLVMbugs] [Bug 4408] New: Incorrect inlining on function with complex parameters

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Wed Jun 17 11:06:23 PDT 2009


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

           Summary: Incorrect inlining on function with complex parameters
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: quickslyver at free.fr
                CC: llvmbugs at cs.uiuc.edu


The inliner seems to generate incorrect code, the initial icmp on length in
memcpy_custom is removed after inlining.

--orignal c source code ------------
extern char __DATA_START,__TEXT_END;
extern char __BSS_START,__BSS_LENGTH;
extern int  __DATA_LENGTH;

void* memcpy_custom(void* dst,const void* src, unsigned int length);
void a() 
{
  memcpy_custom(&__DATA_START,&__TEXT_END,(unsigned int)&__DATA_LENGTH);
}

void* memcpy_custom(void* dst,const void* src, unsigned int length)
{
  char* dst_char=dst;
  const char* src_char=src;
  while(length--)
  {
    *dst_char++=*src_char++;
  }
  return 0;
}

----------llvm code after clang-cc --emit-llvm test.c -O3

; ModuleID = 'test.c'
target datalayout =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i386-pc-linux-gnu"
@__DATA_START = external global i8              ; <i8*> [#uses=1]
@__TEXT_END = external global i8                ; <i8*> [#uses=1]
@__DATA_LENGTH = external global i32            ; <i32*> [#uses=1]

define void @a() nounwind {
entry:
        br label %while.body.i

while.body.i:           ; preds = %while.body.i, %entry
        %indvar.i = phi i32 [ 0, %entry ], [ %indvar.next.i, %while.body.i ]   
        ; <i32> [#uses=3]
        %dst_char.09.i = getelementptr i8* @__DATA_START, i32 %indvar.i        
; <i8*> [#uses=1]
        %src_char.010.i = getelementptr i8* @__TEXT_END, i32 %indvar.i         
; <i8*> [#uses=1]
        %tmp5.i = load i8* %src_char.010.i              ; <i8> [#uses=1]
        store i8 %tmp5.i, i8* %dst_char.09.i
        %indvar.next.i = add i32 %indvar.i, 1           ; <i32> [#uses=2]
        %exitcond = icmp eq i32 %indvar.next.i, ptrtoint (i32* @__DATA_LENGTH
to i32)           ; <i1> [#uses=1]
        br i1 %exitcond, label %memcpy_custom.exit, label %while.body.i

memcpy_custom.exit:             ; preds = %while.body.i
        ret void
}

define noalias i8* @memcpy_custom(i8* nocapture %dst, i8* nocapture %src, i32
%length) nounwind {
entry:
        %tobool13 = icmp eq i32 %length, 0              ; <i1> [#uses=1]
        br i1 %tobool13, label %while.end, label %while.body

while.body:             ; preds = %while.body, %entry
        %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %while.body ]         
; <i32> [#uses=3]
        %src_char.010 = getelementptr i8* %src, i32 %indvar             ; <i8*>
[#uses=1]
        %dst_char.09 = getelementptr i8* %dst, i32 %indvar              ; <i8*>
[#uses=1]
        %tmp5 = load i8* %src_char.010          ; <i8> [#uses=1]
        store i8 %tmp5, i8* %dst_char.09
        %indvar.next = add i32 %indvar, 1               ; <i32> [#uses=2]
        %exitcond = icmp eq i32 %indvar.next, %length           ; <i1>
[#uses=1]
        br i1 %exitcond, label %while.end, label %while.body

while.end:              ; preds = %while.body, %entry
        ret i8* null
}


-- 
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