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

           Summary: Scalar replacement introduces store with incorrect
                    alignment
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


When the scalar replacement pass replaces a structure which is the source of a
llvm.memcpy then it replaces the memcpy with stores. It does not seem to be
taking into account the alignment of the memcpy when setting the alignment of
these stores.

running opt -scalar-repl on the following:

        %struct.st = type <{ i16 }>

define void @f(i8* %p) nounwind {
entry:
        %s = alloca %struct.st, align 4  ; <%struct.st*> [#uses=2]
        %0 = getelementptr %struct.st* %s, i32 0, i32 0  ; <i16*> [#uses=1]
        store i16 1, i16* %0, align 4
        %s1 = bitcast %struct.st* %s to i8*  ; <i8*> [#uses=1]
        call void @llvm.memcpy.i32(i8* %p, i8* %s1, i32 2, i32 1)
        ret void
}

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

Results in the following output:

        %struct.st = type <{ i16 }>

define void @f(i8* %p) nounwind {
entry:
        %p1 = bitcast i8* %p to %struct.st*  ; <%struct.st*> [#uses=1]
        %p1.0 = getelementptr %struct.st* %p1, i32 0, i32 0  ; <i16*> [#uses=1]
        store i16 1, i16* %p1.0
        ret void
}

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

This is invalid - if %p isn't 16bit aligned then the store will be misaligned
and this may trap depending on the target.


-- 
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to