Issue 63883
Summary Suboptimal code loading aligned odd size _BitInt
Labels new issue
Assignees
Reporter VoxSciurorum
    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; }
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to