[llvm] [GISel][RISCV]Implement indirect parameter passing for large scalars (PR #95429)
Gábor Spaits via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 13 10:20:16 PDT 2024
spaits wrote:
> > Why don't just do the lowering in the frontend? I.e. return getNaturalAlignIndirect(...) if argument's size exceeds 2xXLEN
>
> I think we do.
In case of this code https://godbolt.org/z/bqY5Kd5n8 we don't do that in the frontend. This is the IR after the final step in before the irtranslator:
```llvm
define dso_local noundef i128 @fun(__int128, int)(i128 noundef %i, i32 noundef %a) {
entry:
%i.addr = alloca i128, align 16
%a.addr = alloca i32, align 4
%r = alloca i128, align 16
store i128 %i, ptr %i.addr, align 16
store i32 %a, ptr %a.addr, align 4
%0 = load i128, ptr %i.addr, align 16
%1 = load i32, ptr %a.addr, align 4
%sh_prom = zext i32 %1 to i128
%shl = shl i128 %0, %sh_prom
store i128 %shl, ptr %r, align 16
%2 = load i128, ptr %r, align 16
ret i128 %2
}
```
In case of large struct, yes, the frontend wants to pass them as a reference. Code: https://godbolt.org/z/4M1cEa5hh
This is the IR after the final step in before the irtranslator:
```llvm
define dso_local i128 @fun(LargeStruct, int)(%struct.LargeStruct* byval(%struct.LargeStruct) align 8 %0, i32 %a) {
entry:
%i = alloca %struct.LargeStruct, align 16
%a.addr = alloca i32, align 4
%r = alloca i128, align 16
%1 = bitcast %struct.LargeStruct* %i to i8*
%2 = bitcast %struct.LargeStruct* %0 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 16 %1, i8* align 8 %2, i32 80, i1 false)
store i32 %a, i32* %a.addr, align 4
%a1 = getelementptr inbounds %struct.LargeStruct, %struct.LargeStruct* %i, i32 0, i32 0
%3 = load i128, i128* %a1, align 16
%4 = load i32, i32* %a.addr, align 4
%sh_prom = zext i32 %4 to i128
%shl = shl i128 %3, %sh_prom
store i128 %shl, i128* %r, align 16
%5 = load i128, i128* %r, align 16
ret i128 %5
}
```
https://github.com/llvm/llvm-project/pull/95429
More information about the llvm-commits
mailing list