[LLVMbugs] [Bug 13920] New: SROA miscompiling underaligned memcpy

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Sep 25 15:17:01 PDT 2012


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

             Bug #: 13920
           Summary: SROA miscompiling underaligned memcpy
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: richard-llvm at metafoo.co.uk
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


New SROA misoptimizes this

  #include <cstring>
  typedef long long m128i __attribute__((__vector_size__(16)));
  void f(m128i a, unsigned short *b) { memcpy(b, &a, 16); }

to a movaps.


More specifically, it transforms


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"

define void @_Z1fDv2_xPt(<2 x i64> %a, i16* %b) nounwind uwtable {
entry:
  %a.addr = alloca <2 x i64>, align 16
  store <2 x i64> %a, <2 x i64>* %a.addr, align 16
  %0 = bitcast i16* %b to i8*
  %1 = bitcast <2 x i64>* %a.addr to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %1, i64 16, i32 2, i1 false)
  ret void
}

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


into


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"

define void @_Z1fDv2_xPt(<2 x i64> %a, i16* %b) nounwind uwtable {
entry:
  %0 = bitcast i16* %b to i8*
  %a.addr.0..cast = bitcast i8* %0 to <2 x i64>*
  store <2 x i64> %a, <2 x i64>* %a.addr.0..cast
  ret void
}

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


Note that the 2 byte alignment on the memcpy has been lost, and we're left with
a naturally-aligned (16-byte aligned) store of a <2 x i64>.

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