Skip to content

Inefficient codegen in builder pattern with existed copyable base value #113134

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

Open
CrazyboyQCD opened this issue Oct 21, 2024 · 1 comment · May be fixed by #115314
Open

Inefficient codegen in builder pattern with existed copyable base value #113134

CrazyboyQCD opened this issue Oct 21, 2024 · 1 comment · May be fixed by #115314

Comments

@CrazyboyQCD
Copy link

CrazyboyQCD commented Oct 21, 2024

In a builder pattern code, when building with existed copyable base value, codegen isn't efficient like partial copy.
This can be reproduced on both argument value and constant value.

Full copy and patial copy:
C version: https://godbolt.org/z/z3fWsKhqE
Rust version: https://godbolt.org/z/MeGf8E5Gd

Existed value and non existed value:
C version: https://godbolt.org/z/9z3x3Kv5c
Rust version: https://godbolt.org/z/vWEaEfd3e

Real use case examaple in rust: https://godbolt.org/z/3q9jn5c1o

@dtcxzyw
Copy link
Member

dtcxzyw commented Nov 7, 2024

/// Returns true if the beginning of this instruction can be safely shortened
/// in length.
static bool isShortenableAtTheBeginning(Instruction *I) {
// FIXME: Handle only memset for now. Supporting memcpy/memmove should be
// easily done by offsetting the source address.
return isa<AnyMemSetInst>(I);
}

It can be fixed by supporting memcpy in tryToShortenBegin.

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

Successfully merging a pull request may close this issue.

4 participants