[llvm-bugs] [Bug 43880] New: -expandmemcmp generates loads with incorrect alignment

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Nov 1 22:18:54 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43880

            Bug ID: 43880
           Summary: -expandmemcmp generates loads with incorrect alignment
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: juneyoung.lee at sf.snu.ac.kr
                CC: llvm-bugs at lists.llvm.org

--
$ cat memcmp.ll
target datalayout = "e-i8:8:8-i16:16:16"
target triple = "x86_64-unknown-unknown"
declare i32 @memcmp(i8* nocapture, i8* nocapture, i64)

define i32 @cmp2(i8* nocapture readonly %x, i8* nocapture readonly %y)  {
  %call = tail call i32 @memcmp(i8* %x, i8* %y, i64 2)
  ret i32 %call
}

$ ./llvm/bin/opt -expandmemcmp -S -o - memcmp.ll
; ModuleID = 'memcmp.ll'
source_filename = "memcmp.ll"
target datalayout = "e-i8:8:8-i16:16:16"
target triple = "x86_64-unknown-unknown"

declare i32 @memcmp(i8* nocapture, i8* nocapture, i64)

define i32 @cmp2(i8* nocapture readonly %x, i8* nocapture readonly %y) {
  %1 = bitcast i8* %x to i16*
  %2 = bitcast i8* %y to i16*
  %3 = load i16, i16* %1
  %4 = load i16, i16* %2
  %5 = call i16 @llvm.bswap.i16(i16 %3)
  %6 = call i16 @llvm.bswap.i16(i16 %4)
  %7 = zext i16 %5 to i32
  %8 = zext i16 %6 to i32
  %9 = sub i32 %7, %8
  ret i32 %9
}

; Function Attrs: nounwind readnone speculatable willreturn
declare i16 @llvm.bswap.i16(i16) #0

attributes #0 = { nounwind readnone speculatable willreturn }
--

This is incorrect because the loads in the output has align 2 (omitted
alignment in loads mean they have the ABI alignment). If %x or %y is not 2-byte
aligned, the optimized code raises undefined behavior, where as the source
wouldn't.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191102/66047e41/attachment.html>


More information about the llvm-bugs mailing list