Skip to content

Commit 7a5d968

Browse files
committed
[Sema] NFC: Reorder misc bits for better code gen
As a general rule, if one wants packs miscellaneous bits into what is otherwise just a number, the low bits are preferable over the high bits, at least on x86. On ppc64/ppc64le, the results are more of a wash. For reference: struct X { unsigned kind : 3; unsigned level : 29; }; X example(X x, unsigned y) { x.level += y; return x; } bool example(X x) { return x.level > 1; } ==== x86_64 with 'kind' first ==== _Z7example1Xj: leal (%rdi,%rsi,8), %eax retq _Z7example1X: cmpl $15, %edi seta %al retq ==== x86_64 with 'kind' last ==== _Z7example1Xj: leal (%rsi,%rdi), %eax andl $536870911, %eax # imm = 0x1FFFFFFF andl $-536870912, %edi # imm = 0xE0000000 orl %edi, %eax retq _Z7example1X: testl $536870910, %edi # imm = 0x1FFFFFFE setne %al retq ==== PPC64 with 'kind' first ==== _Z7example1Xj: add 5, 5, 4 rlwimi 5, 4, 0, 0, 2 stw 5, 0(3) blr _Z7example1X: rlwinm 3, 3, 0, 3, 30 cntlzw 3, 3 srwi 3, 3, 5 xori 3, 3, 1 blr ==== PPC64 with 'kind' last ==== _Z7example1Xj: slwi 5, 5, 3 add 4, 5, 4 stw 4, 0(3) blr _Z7example1X: clrldi 3, 3, 32 subfic 3, 3, 15 rldicl 3, 3, 1, 63 blr ==== PPC64LE with 'kind' first ==== _Z7example1Xj: slwi 4, 4, 3 add 3, 4, 3 blr _Z7example1X: clrldi 3, 3, 32 subfic 3, 3, 15 rldicl 3, 3, 1, 63 blr ==== PPC64LE with 'kind' last ==== _Z7example1Xj: add 4, 4, 3 rlwimi 3, 4, 0, 3, 31 blr _Z7example1X: rlwinm 3, 3, 0, 3, 30 cntlzw 3, 3 srwi 3, 3, 5 xori 3, 3, 1 blr
1 parent 812e945 commit 7a5d968

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
8686
// Selector for the partial_application_of_function_invalid diagnostic
8787
// message.
8888
struct PartialApplication {
89-
unsigned level : 29;
9089
enum : unsigned {
9190
Function,
9291
MutatingMethod,
9392
SuperInit,
9493
SelfInit,
9594
};
95+
// 'kind' before 'level' is better for code gen.
9696
unsigned kind : 3;
97+
unsigned level : 29;
9798
};
9899

99100
// Partial applications of functions that are not permitted. This is
@@ -121,7 +122,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
121122

122123
// Partial applications of delegated initializers aren't allowed, and
123124
// don't really make sense to begin with.
124-
InvalidPartialApplications.insert({ expr, {1, kind} });
125+
InvalidPartialApplications.insert({ expr, {kind, 1} });
125126
return;
126127
}
127128

@@ -141,7 +142,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
141142
if (!expr->getArg()->getType()->isMaterializable()) {
142143
// We need to apply all argument clauses.
143144
InvalidPartialApplications.insert({
144-
fnExpr, {fn->getNumParameterLists(), kind}
145+
fnExpr, {kind, fn->getNumParameterLists()}
145146
});
146147
}
147148
}
@@ -172,7 +173,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
172173
InvalidPartialApplications.erase(foundApplication);
173174
if (level > 1) {
174175
// We have remaining argument clauses.
175-
InvalidPartialApplications.insert({ AE, {level - 1, kind} });
176+
InvalidPartialApplications.insert({ AE, {kind, level - 1} });
176177
}
177178
return;
178179
}

0 commit comments

Comments
 (0)