Commit 03e6535
authored
[CIR][ABI][AArch64][Lowering] Fix calls for struct types > 128 bits (#1335)
In [PR#1074](#1074) we introduced
calls for struct types > 128 bits, but there's is an issue here.
[This](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp#L1169)
is meant to be a `memcpy` of the alloca instead of directly passing the
alloca, just like in the
[OG](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CodeGen/CGCall.cpp#L5323).
The PR was meant to use a `memcpy` and later handle cases where we don't
need the `memcpy`.
For example, running the following code snippet `tmp.c` using `bin/clang
tmp.c -o tmp -Xclang -fclangir -Xclang -fclangir-call-conv-lowering
--target=aarch64-none-linux-gnu`:
```
#include <stdio.h>
typedef struct {
int a, b, c, d, e;
} S;
void change(S s) { s.a = 10; }
void foo(void) {
S s;
s.a = 9;
change(s);
printf("%d\n", s.a);
}
int main(void) {
foo();
return 0;
}
```
gives 10 instead of 9, because we pass the pointer instead of a copy.
Relevant part of the OG LLVM output:
```
@foo()
%s = alloca %struct.S, align 4
%byval-temp = alloca %struct.S, align 4
%a = getelementptr inbounds nuw %struct.S, ptr %s, i32 0, i32 0
store i32 9, ptr %a, align 4
call void @llvm.memcpy.p0.p0.i64(ptr align 4 %byval-temp, ptr align 4 %s, i64 20, i1 false)
call void @change(ptr noundef %byval-temp)
```
Current LLVM output through CIR:
```
@foo()
%1 = alloca %struct.S, i64 1, align 4
%2 = getelementptr %struct.S, ptr %1, i32 0, i32 0
store i32 9, ptr %2, align 4
%3 = load %struct.S, ptr %1, align 4
call void @change(ptr %1)
```
So, there should be a memcpy.
This PR fixes this, and adds a comment/note for the future cases where
we need to check if the copy is not needed. I have also updated the old
test with structs having size > 128.1 parent 6dd6d82 commit 03e6535
File tree
2 files changed
+21
-11
lines changed- clang
- lib/CIR/Dialect/Transforms/TargetLowering
- test/CIR/CallConvLowering/AArch64
2 files changed
+21
-11
lines changedLines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1166 | 1166 | | |
1167 | 1167 | | |
1168 | 1168 | | |
1169 | | - | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
1170 | 1176 | | |
1171 | 1177 | | |
1172 | 1178 | | |
| |||
Lines changed: 14 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
188 | 192 | | |
189 | 193 | | |
190 | 194 | | |
| |||
0 commit comments