Rollup merge of #98078 - erikdesjardins:uncheckedsize, r=petrochenkov
Use unchecked mul to compute slice sizes This allows LLVM to realize that `slice.len() > 0` iff `slice.len() * size_of::<T>() > 0`, allowing a branch on the latter to be folded into the former when dropping vecs and boxed slices, in some cases. Fixes (partially) #96497
This commit is contained in:
commit
2722c2aa33
2 changed files with 35 additions and 1 deletions
|
@ -39,7 +39,12 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
// The info in this case is the length of the str, so the size is that
|
||||
// times the unit size.
|
||||
(
|
||||
bx.mul(info.unwrap(), bx.const_usize(unit.size.bytes())),
|
||||
// All slice sizes must fit into `isize`, so this multiplication cannot (signed) wrap.
|
||||
// NOTE: ideally, we want the effects of both `unchecked_smul` and `unchecked_umul`
|
||||
// (resulting in `mul nsw nuw` in LLVM IR), since we know that the multiplication
|
||||
// cannot signed wrap, and that both operands are non-negative. But at the time of writing,
|
||||
// `BuilderMethods` can't do this, and it doesn't seem to enable any further optimizations.
|
||||
bx.unchecked_smul(info.unwrap(), bx.const_usize(unit.size.bytes())),
|
||||
bx.const_usize(unit.align.abi.bytes()),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue