| Issue |
244034
|
| Summary |
[CIR] AArch64 has no call conv lowering
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
FedericoBruzzone
|
Hi folks, that's not my primary area.
However, I'd like to share this issue I faced.
Please don't hesitate to point out if I'm missing something here - I used AI to investigate the problem.
CIR doesn't lower call conv on AArch64. `-fclangir` output doesn't follow AAPCS64 and cannot be linked with _classic_ CodeGen objects. AMDGPU (#220471) and SPIR (#233633) already have tracking issues, but I could not find one for AArch64.
`getCallConvTarget` returns `None` for AArch64 triples, so `CallConvLoweringPass` never runs.
**Reproducer**
```c
// t.c
typedef struct { long a, b, c, d; } Big;
typedef struct { float x, y, w, h; } HFA4;
Big make_big(long a) { Big b = {a, a, a, a}; return b; }
float take_hfa(HFA4 h) { return h.x + h.h; }
long take_big(Big b) { return b.a + b.d; }
long call(void) { Big b = make_big(1); return take_big(b); }
```
```
clang --target=aarch64-linux-gnu -S -emit-llvm t.c
```
```llvm
define void @make_big(ptr dead_on_unwind noalias writable sret(%struct.Big) align 8 %agg.result, i64 noundef %a)
define float @take_hfa([4 x float] alignstack(8) %h.coerce)
define i64 @take_big(ptr nofreeobj noundef align 8 dead_on_return dereferenceable(32) %b)
```
```
clang --target=aarch64-linux-gnu -fclangir -Xclang -fclangir-call-conv-lowering -S -emit-llvm t.c
```
```llvm
define %struct.Big @make_big(i64 noundef %0)
define float @take_hfa(%struct.HFA4 %0)
define i64 @take_big(%struct.Big %0)
```
The `Big` return has no `sret` (AAPCS64 passes it in `x8`), `HFA4` is **not** coerced to `[4 x float]`, and `Big` is passed by value instead of by reference. A call from a CIR object to a _classic_ one, or the other way round, reads the wrong registers.
I hit this linking a CIR object with a clang object. According to AI, it works on x86-64 only because `sret` happens to be in `rdi`.
Quite obvious, but `llvm/lib/ABI` already has an AArch64 target:
https://github.com/llvm/llvm-project/blob/40cf77cab2923966f21f3718d5ce7974e5e3b441/llvm/lib/ABI/Targets/AArch64.cpp#L88-L91
Now, sorry, but unfortunately I'll not be able to work on this issue at the moment.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs