Skip to content

algorithms/mod: This only black-boxes acc so LLVM keeps the subtraction results #581

@github-actions

Description

@github-actions

On 2026-04-30 @prestwich wrote in 836a44f “Merge pull request #579 from DaniPopes/cmp-with-sub-revived”:

This only black-boxes acc so LLVM keeps the subtraction results
alive long enough for the backend to recognize the borrowing_sub chain
and generate better code: rust-lang/rust#143517
SAFETY: Writing to a local variable through a reference is safe.

    for i in 0..a.len() {
        let x;
        (x, borrow) = borrowing_sub(a[i], b[i], borrow);
        acc |= x;
    }
    // HACK: This only black-boxes `acc` so LLVM keeps the subtraction results
    // alive long enough for the backend to recognize the `borrowing_sub` chain
    // and generate better code: https://github.com/rust-lang/rust/issues/143517
    // SAFETY: Writing to a local variable through a reference is safe.
    unsafe { core::ptr::write_volatile(&mut acc, acc) };
    (acc, borrow)
}

#[inline]

From src/algorithms/mod.rs:188

Metadata

Metadata

Assignees

Labels

hackUgly solution in need of improvementtrackerIssue tracked by bot

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions