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

dead code emits redundant instructions #2802

Open
MkazemAkhgary opened this issue Mar 19, 2024 · 2 comments
Open

dead code emits redundant instructions #2802

MkazemAkhgary opened this issue Mar 19, 2024 · 2 comments
Labels
Bugs Performance All issues related to performance/code generation

Comments

@MkazemAkhgary
Copy link

MkazemAkhgary commented Mar 19, 2024

I was testing a few things and noticed this. the _x variable is not used here so it shouldn't be compiled. (target AVX2)

uint8 test(uniform uint8<TARGET_WIDTH> x)
{
    uint8 _x;
    unmasked
    {
        _x = x[programIndex]+1;
    }
    return  x[programIndex]+1;
}
test___unT_3C_8_3E_:                    # @test___unT_3C_8_3E_
        vmovmskps       eax, ymm1
        cmp     eax, 255
        je      .LBB1_2
        not     al
        test    al, -127
.LBB1_2:
        vpcmpeqd        xmm1, xmm1, xmm1
        vpsubb  xmm0, xmm0, xmm1
        vzeroupper
        ret

by removing the redundant part:

uint8 test(uniform uint8<TARGET_WIDTH> x)
{
    return  x[programIndex]+1;
}
test___unT_3C_8_3E_:                    # @test___unT_3C_8_3E_
        vpcmpeqd        xmm1, xmm1, xmm1
        vpsubb  xmm0, xmm0, xmm1
        ret 

I'm not sure what those extra instructions do, looks redundant to me.

@MkazemAkhgary MkazemAkhgary changed the title redundant code emits redundant instructions dead code emits redundant instructions Mar 21, 2024
@nurmukhametov
Copy link
Collaborator

Yes, indeed. I think that unmasked region doesn't matter here. The following code also produces similar redundancy

uint8 test(uniform uint8<TARGET_WIDTH> x)
{
    uint8 y = x[0];
    return x[programIndex]+1;
}
test___unT_3C_8_3E_:                    # @test___unT_3C_8_3E_
        vmovmskps       eax, ymm1
        cmp     eax, 255
        je      .LBB1_2
        not     al
        test    al, -127
.LBB1_2:
        vpcmpeqd        xmm1, xmm1, xmm1
        vpsubb  xmm0, xmm0, xmm1
        vzeroupper
        ret

@dbabokin
Copy link
Collaborator

I would experiment with SimplifyCFG and DCE to see if they are able to solve the problem and if they trigger in the right place in the opt pipeline.

@pbrubaker pbrubaker added Performance All issues related to performance/code generation Bugs labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugs Performance All issues related to performance/code generation
Projects
Status: No status
Development

No branches or pull requests

4 participants