Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sve] A redundant csel instruction for overflow check #78960

Open
vfdff opened this issue Jan 22, 2024 · 2 comments · May be fixed by #79825
Open

[sve] A redundant csel instruction for overflow check #78960

vfdff opened this issue Jan 22, 2024 · 2 comments · May be fixed by #79825

Comments

@vfdff
Copy link
Contributor

vfdff commented Jan 22, 2024

void mset (int *a, long long num) {
   for (long long i=0; i< num; i++)
     a[i] = 2;
}
  • gcc:
mset:
        cmp     x1, 0
        ble     .L1
        mov     x2, 0
        cntw    x3
        whilelo p7.s, xzr, x1
        mov     z31.s, #2
.L3:
        st1w    z31.s, p7, [x0, x2, lsl 2]
        add     x2, x2, x3    --  before the whilelo
        whilelo p7.s, x2, x1
        b.any   .L3
  • llvm:
mset:                                   // @mset
        cmp     x1, #1
        b.lt    .LBB0_3
        cntw    x8
        mov     z0.s, #2                        // =0x2
        mov     x10, xzr
        subs    x9, x1, x8
        csel    x9, xzr, x9, lo    ---> this is redundant  compare to gcc ??
        whilelo p0.s, xzr, x1
.LBB0_2:                                // =>This Inner Loop Header: Depth=1
        st1w    { z0.s }, p0, [x0, x10, lsl #2]
        whilelo p0.s, x10, x9
        add     x10, x10, x8        -- after the whilelo
        b.mi    .LBB0_2
  • the above redundant csel is used to check the overflow of loop iv, but it seems not necessary.
@vfdff

This comment was marked as outdated.

@vfdff
Copy link
Contributor Author

vfdff commented Jan 23, 2024

  • in the gcc's body, it add the the iter number before the compare (whilelo), so it don't need the csel to guard the overflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants