Skip to content

__builtin_nondeterministic_value is converted to a zero #101121

Open
@dzaima

Description

@dzaima

The code:

void f(int x, int a, int b) {
    ext(__builtin_nondeterministic_value(5), a, b);
}

gets optimized to ext(0, a, b);, thus ending up with an unnecessary zeroing of a register. IR-wise, a freeze i32 poison becomes 0 during instcombine. https://godbolt.org/z/6rxsdr634

This means that __builtin_nondeterministic_value is unsuitable for efficiently calling a function where the caller knows that the callee won't use some argument(s). The only option that roughly works that I've found is to read an uninitialized variable, but that produces a warning and breaks under memorysanitizer.

Passing the pre-instcombine IR directly to the backend generates the desired assembly: https://godbolt.org/z/on6W17ex4

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:instcombineCovers the InstCombine, InstSimplify and AggressiveInstCombine passes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions