No auto-vectorization in such case since 1.54.0

Simple case like:

#[inline]
fn check(byte: u8) -> bool {
    return (byte <= 0x20) || (byte == 0x22) || (byte == 0x3D) || (byte == 0x5B) || (byte == 0x5D);
}

unsafe fn test_impl(s: *const u8, len: usize) -> bool {
    const STEP: usize = 32;
    const ZERO: [bool; STEP] = [false; STEP];

    let mut step_data = ZERO.clone();
    let mut s = s;
    let mut len = len;
    while len >= STEP {
        for i in 0..STEP {
            step_data[i] = check(*s.add(i));
        }
        if step_data != ZERO {
            return true;
        }
        s = s.add(STEP);
        len -= STEP;
    }
    for i in 0..len {
        if check(*s.add(i)) {
            return true;
        }
    }
    return false;
}

pub fn test(s: &[u8]) -> bool {
    unsafe { test_impl(s.as_ptr(), s.len()) }
}

With rustc 1.53.0-nightly
run RUSTFLAGS="--emit=asm -C target-feature=+avx2" cargo build --release
rustc can generate vectorized asm.

But with 1.54.0 or higher, rustc can not make optimization.

it can be verified in https://godbolt.org/ as well.

This forum is for users of the Rust language and isn't actively monitored by the compiler team. Please report regressions by creating a ticket against the Rust repo's issue tracker.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.