You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This may be a limitation with llvm's alias analysis (or other components). Does rust perhaps emit suboptimal llvm-ir?:
(reduced test-case)
targetdatalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"targettriple = "x86_64-unknown-linux-gnu"%VecU8 = type { [0 x i64], { i8*, i64 }, [0 x i64], i64, [0 x i64] }
definei64@_ZN7example1a17haca38bae68eb7066E() {
%v2 = alloca%VecU8, align8%1 = bitcast%VecU8*%v2toi8**%2 = getelementptrinbounds%VecU8, %VecU8*%v2, i640, i321, i321%3 = bitcasti64*%2toi8*; `buf` is a 16-bytes, "zero-initialized" by a memset, array%buf = alloca [16 x i8], align8%buf_ptr = getelementptrinbounds [16 x i8], [16 x i8]* %buf, i640, i640callvoid@llvm.memset.p0i8.i64(i8*nonnullalign8%buf_ptr, i80, i6416, i1false)
storei8*inttoptr (i641toi8*), i8**%1, align8; "zero-initializes" the two i64 (skipping the i8*) of %v2 through %2 by copying from %buf which is "known" to be zerocallvoid@llvm.memcpy.p0i8.p0i8.i64(i8*nonnullalign8%3, i8*nonnullalign8%buf_ptr, i6416, i1false)
; llvm can't prove that the i64 at %v2.idx has been zero-initialized by the memcpy%v2.idx = getelementptrinbounds%VecU8, %VecU8*%v2, i640, i323%v2.idx.val = loadi64, i64*%v2.idx, align8reti64%v2.idx.val
}
declarevoid@llvm.memcpy.p0i8.p0i8.i64(i8*nocapturewriteonly, i8*nocapturereadonly, i64, i1)
declarevoid@llvm.memset.p0i8.i64(i8*nocapturewriteonly, i8, i64, i1)
The Vec::new() variant optimizes well on nightly, presumably as a result of the LLVM 12 upgrade. I'm not sure which upstream change is responsible in this case though.
Activity
cynecx commentedon Sep 24, 2018
This may be a limitation with llvm's alias analysis (or other components). Does rust perhaps emit suboptimal llvm-ir?:
(reduced test-case)
https://godbolt.org/z/-IvKEW
matthiaskrgr commentedon Dec 12, 2019
Note that making
Vec::new()aconst fndid not fix the issue.tspiteri commentedon Mar 31, 2020
If you create a const
Vecand use it instead ofVec::new(), it does seem to work around the issue.https://rust.godbolt.org/z/ftbvHX
RalfJung commentedon Mar 31, 2020
And unsurprisingly so -- making a function
const fnhas exactly no effect at all on the generated LLVM IR.nikic commentedon Mar 13, 2021
The Vec::new() variant optimizes well on nightly, presumably as a result of the LLVM 12 upgrade. I'm not sure which upstream change is responsible in this case though.