Skip to content

LLVM can compile a function differently if there are different paramters even if the demanded bits are the same #144282

Open
@AZero13

Description

@AZero13

https://godbolt.org/z/4nYe6avsv

unsigned func1(unsigned a, unsigned b)
{
        int c = a & b;
        return (c ^ a)&1;
}

unsigned func1_2(unsigned a, bool b)
{
        int c = a & b;
        return (c ^ a)&1;
}

Here, the only bit that matters is the bottom one, hence it should make no difference.

However, we get:

func1(unsigned int, unsigned int):
        bic     w8, w0, w1
        and     w0, w8, #0x1
        ret

func1_2(unsigned int, bool):
        and     w8, w0, #0x1
        tst     w1, #0x1
        csel    w0, wzr, w8, ne
        ret

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions