Closed
Description
The way else if is currently translated the following code
auto x = if (a) {
b
} else if (c) {
d
} else {
e
};
translates the same as
auto x = if (a) {
b
} else {
if (c) {
d
} else {
e
}
};
This creates a new sub-scope for each else if branch.
The mechanism for returning results from blocks entails copying the result into a new alloca and dropping any refs for it in the parent scope. These two things combined mean that an else if chain with n else if branches will generate allocas for n results and n take/drop pairs.
I suppose it could be possible to eliminate them in an optimization pass that eliminated redundant take/drops, but this also might be a good argument for reverting to the previous, non-recursive definition of else if.
Metadata
Metadata
Assignees
Labels
No labels