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

            Bug ID: 31001
           Summary: Slow code generated for memcpy of a `zext i1`
           Product: libraries
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: arie...@mail.tau.ac.il
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

A memcpy with a constant length is lowered to a (fast) sequence of load and
store instructions. A memcpy with a non-constant length is lowered to a call to
the memcpy function, which is slow for short copies.

For example, a memcpy of a `zext i1` is equivalent to a conditional load and
store of a single byte, but the generated IR (and ASM) contains a call to
memcpy:


```
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture
readonly, i64, i32, i1) #2

define i8 @test_load_store(i1 %cond, i8* %buf) {
  %_result = alloca i8, align 8
  %_len = zext i1 %cond to i64
  store i8 0, i8* %_result
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %_result, i8* nonnull %buf,
i64 %_len, i32 1, i1 false)
  %_ret = load i8, i8* %_result
  ret i8 %_ret
}
```

This causes slowness in Rust's Cursor::read, which we discovered in PR
https://github.com/rust-lang/rust/pull/37573..

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to