about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-10-26 11:29:53 +0530
committerGitHub <noreply@github.com>2022-10-26 11:29:53 +0530
commit8ed3a80b9a37ee31e69f1dbe2f720046f8d4422c (patch)
tree0c6778546b2c3b2fa2a29fa25ba5e837b307213c /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
parentf2c2e582bdb8ca9d1a09643d516e22b6d3406581 (diff)
parentcfcb0a2135da6d4bdbf5f28806dea0cc70c5b6c5 (diff)
downloadrust-8ed3a80b9a37ee31e69f1dbe2f720046f8d4422c.tar.gz
rust-8ed3a80b9a37ee31e69f1dbe2f720046f8d4422c.zip
Rollup merge of #103287 - saethlin:faster-len-check, r=thomcc
Use a faster allocation size check in slice::from_raw_parts

I've been perusing through the codegen changes that result from turning on the standard library debug assertions. The previous check in here uses saturating arithmetic, which in my experience sometimes makes LLVM just fail to optimize things around the saturating operation.

Here is a demo of the codegen difference: https://godbolt.org/z/WMEqrjajW
Before:
```asm
example::len_check_old:
        mov     rax, rdi
        mov     ecx, 3
        mul     rcx
        setno   cl
        test    rax, rax
        setns   al
        and     al, cl
        ret

example::len_check_old:
        mov     rax, rdi
        mov     ecx, 8
        mul     rcx
        setno   cl
        test    rax, rax
        setns   al
        and     al, cl
        ret
```
After:
```asm
example::len_check_new:
        movabs  rax, 3074457345618258603
        cmp     rdi, rax
        setb    al
        ret

example::len_check_new:
        shr     rdi, 60
        sete    al
        ret
```

Running rustc-perf locally, this looks like up to a 4.5% improvement when `debug-assertions-std = true`.

Thanks ```@LegionMammal978``` (I think that's you?) for turning my idea into a much cleaner implementation.

r? ```@thomcc```
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions