<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63883>63883</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Suboptimal code loading aligned odd size _BitInt
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
VoxSciurorum
</td>
</tr>
</table>
<pre>
A `_BitInt(17)` known to be aligned to 4 bytes can be loaded with a single memory reference. Code generation generates two, apparently because it treats the value as fundamentally 24 bits. I observe this on aarch64 (code below) and amd64. I expect it happens on any machine without a native 17 or 24 bit type.
IR example:
```
; ModuleID = 'extract17.c'
source_filename = "extract17.c"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-freebsd"
define dso_local i32 @f(ptr nocapture noundef readonly %0) local_unnamed_addr {
%2 = load i17, ptr %0, align 4
%3 = sext i17 %2 to i32
ret i32 %3
}
```
Code looks like
```
ldrb w8, [x0, #2]
ldrh w9, [x0]
bfi w9, w8, #16, #16
sbfx w0, w9, #0, #17
ret
```
but should look like the corresponding code with a bit field of width 17,
```
ldr w8, [x0]
sbfx w0, w8, #0, #17
ret
```
C code:
```
struct Field { int value : 17; };
struct BitInt { _BitInt(17) value; int aligner; };
int f1(struct Field *sp) { return sp->value; }
int f2(struct BitInt *sp) { return sp->value; }
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU2P8yYQ_jXkMkpkg-OPQw7JpivtoZe-Uq8rbMYxXQwWjDdJf30FTrIf6vtKrZRgA88888wwjGUI-mQRd2x7YNvjSs40OL_7011-dHr2zs_jqnXqutsDK7PXg6YXS4zXecV4w8oM3qw7WyAHLYI0kUvFWQHtlTBAJ23cMU4qVHDWNICEoO3JIIw4On8Fjz16tB1uAJ6cQjihRS9JO3t_xQB0dow_gZwm6dGSuUKLnZwDgiYgj5IC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