[Sema] NFC: Reorder misc bits for better code gen #16690
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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