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

We can't copy trivial structs #1128

Open
ChuanqiXu9 opened this issue Nov 15, 2024 · 3 comments
Open

We can't copy trivial structs #1128

ChuanqiXu9 opened this issue Nov 15, 2024 · 3 comments

Comments

@ChuanqiXu9
Copy link
Member

Reproducer:

struct S {
    int a;
    int b;
};

S getS(S);

S foo() {
    S s;
    s = getS(s);
    return s;
}

when we try to emit CIR for it, we will get

llvm_unreachable("NYI");

@smeenai
Copy link
Collaborator

smeenai commented Nov 15, 2024

Yeah, this is part of a broader category of issues where we want to emit a constructor call instead of a memcpy to facilitate better analysis, but then we need to remove trivial constructors and convert to memcpy where possible to have parity with CodeGen. I ran into #1055 with a slightly more complex case, and #1098 is a current missed optimization. I think we'd want to emit copy constructors here and then convert to memcpy later in the pipeline somewhere. ABI lowering also comes into play for the function arguments and return values, which is another consideration.

@ChuanqiXu9
Copy link
Member Author

Yeah, this is part of a broader category of issues where we want to emit a constructor call instead of a memcpy to facilitate better analysis, but then we need to remove trivial constructors and convert to memcpy where possible to have parity with CodeGen. I ran into #1055 with a slightly more complex case, and #1098 is a current missed optimization. I think we'd want to emit copy constructors here and then convert to memcpy later in the pipeline somewhere. ABI lowering also comes into play for the function arguments and return values, which is another consideration.

Thanks for replying. I feel currently CIR may be slightly low level. It should be good enough here to emit a constructor here. Such layering is helpful for analysis too.

@smeenai
Copy link
Collaborator

smeenai commented Nov 15, 2024

Yup, emitting a constructor here is good (and we've been trying to represent all constructor calls faithfully in CIR); any optimizations can come later.

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

No branches or pull requests

2 participants