bitfields poorly optimized
Bug #641397 reported by
Andrew Stubbs
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Linaro GCC |
New
|
Medium
|
Unassigned | ||
gcc |
Fix Released
|
Wishlist
|
Bug Description
Consider the following code:
struct bits {
unsigned a : 5;
unsigned b : 5;
unsigned c : 5;
unsigned d : 5;
};
struct bits
f (unsigned int a) {
struct bits bits;
bits.a = 1;
bits.b = 2;
bits.c = 3;
bits.d = a;
return bits;
}
The function 'f' creates a new struct with three constant initialized bitfields, and one from the argument.
You might expect GCC to compile this to one constant load, and a single "bfi" instruction for "a", but it doesn't. Instead it produces code that builds the struct from component bit fields at run time. This is both speed and space inefficient.
[CodeSourcery Tracker ID #6753]
Related branches
lp://staging/~ams-codesourcery/gcc-linaro/lp641397
On hold
for merging
into
lp://staging/gcc-linaro/4.6
- Linaro Toolchain Developers: Pending requested
-
Diff: 80 lines (+30/-6)3 files modifiedChangeLog.linaro (+8/-0)
gcc/cse.c (+21/-5)
gcc/passes.c (+1/-1)
tags: | added: speed task |
Changed in gcc: | |
importance: | Unknown → Wishlist |
status: | Unknown → Confirmed |
Changed in gcc-linaro: | |
importance: | Undecided → Medium |
importance: | Medium → Low |
Changed in gcc-linaro: | |
importance: | Low → Medium |
Changed in gcc-linaro: | |
assignee: | Andrew Stubbs (ams-codesourcery) → nobody |
Changed in gcc-linaro: | |
status: | In Progress → New |
Changed in gcc: | |
status: | Confirmed → In Progress |
Changed in gcc: | |
status: | In Progress → Fix Released |
To post a comment you must log in.
The compiler has some code to deal with this sort of case, but it appears bit-rotted.
It doesn't work when:
* the target cpu has no bit-field-insert instruction that takes an immediate constant.
* the assignment is to an uninitialized (or zero-initialized) destination.
Both are true in this case.