As pointed out in PR45708, -ffine-grained-bitfield-accesses doesn't trigger in all cases you think it might for RISC-V. The logic in CGRecordLowering::accumulateBitFields checks OffsetInRecord is a legal integer according to the datalayout. RISC targets will typically only have the native width as a legal integer type so this check will fail for OffsetInRecord of 8 or 16 when you would expect the transformation is still worthwhile.
This patch changes the logic to check for an OffsetInRecord of a at least 1 byte, that fits in a legal integer, and is a power of 2. We would prefer to query whether native load/store operations are available, but I don't believe that is possible.
StartBitOffset is the offset in bits of the beginning of the current run, the comment above explains that. It's not obvious what OffsetInRecord is; I guess it's the size in bits of the current run? The name isn't really intuitive.
This patch seems reasonable; you want to allow any legal integer, and any smaller type that can probably be naturally loaded and stored.