Unfortunately the current call lowering code is built on top of the legacy MVT/DAG based code. However, GlobalISel was not using it the same way. In short, the DAG passes legalized types to the assignment function, and GlobalISel was passing the original raw type if it was simple. I do believe the DAG lowering is conceptually broken since it requires picking a type up front before knowing how/where the value will be passed. This ends up being a problem for AArch64, which wants to pass i1/i8/i16 values as a different size if passed on the stack or in registers. The argument type decision is split across 3 different places which is hard to follow. SelectionDAG builder uses getRegisterTypeForCallingConv to pick a legal type, tablegen gives the illusion of controlling the type, and the target may have additional hacks in the C++ part of the call lowering. AArch64 hacks around this by not using the standard AnalyzeFormalArguments and special casing i1/i8/i16 by looking at the underlying type of the original IR argument. I believe people have generally assumed the calling convention code is processing the original types, and I've discovered a number of dead paths in several targets. x86 actually relies on the opposite behavior from AArch64, and relies on x86_32 and x86_64 sharing calling convention code where the 64-bit cases implicitly do not work on x86_32 due to using the pre-legalized types. AMDGPU targets without legal i16/f16 have always used a broken ABI that promotes to i32/f32. GlobalISel accidentally fixed this to be the ABI we should have, but this fixes it so we're using the worse ABI that is compatible with the DAG. Ideally we would fix the DAG to match the old GlobalISel behavior, but I don't wish to fight that battle. A new native GlobalISel call lowering framework should let the target process the incoming types directly. CCValAssigns select a "ValVT" and "LocVT" but the meanings of these aren't entirely clear. Different targets don't use them consistently, even within their own call lowering code. My current belief is the intent was "ValVT" is supposed to be the legalized value type to use in the end, and and LocVT was supposed to be the ABI passed type (which is also legalized). With the default CCState::Analyze functions always passing the same type for these arguments, these only differ when the TableGen part of the lowering decide to promote the type from one legal type to another. AArch64's i1/i8/i16 hack ends up inverting the meanings of these values, so I had to add an additional hack to let the target interpret how large the argument memory is. Since targets don't consistently interpret ValVT and LocVT, this doesn't produce quite equivalent code to the initial DAG lowerings. I've opted to consistently interpret LocVT as the in-memory size for stack passed values, and ValVT as the register type to assign from that memory. We therefore produce extending loads directly out of the IRTranslator, whereas the DAG would emit regular loads of smaller values. This will also produce loads/stores that are wider than the argument value if the allocated stack slot is larger (and there will be undef padding bytes). If we had the optimizations to reduce load/stores based on truncated values, this wouldn't produce a different end result. Since ValVT/LocVT are more consistently interpreted, we now will emit more G_BITCASTS as requested by the CCAssignFn. For example AArch64 was directly assigning types to some physical vector registers which according to the tablegen spec should have been casted to a vector with a different element type. This also moves the responsibility for inserting G_ASSERT_SEXT/G_ASSERT_ZEXT from the target ValueHandlers into the generic code, which is closer to how SelectionDAGBuilder works. I had to xfail an x86 test since I don't see a quick way to fix it right now (I filed bug 50035 for this). It's broken independently of this change, and only triggers since now we end up with more ands which hit the improperly handled selection pattern. I also observed that FP arguments that need promotion (e.g. f16 passed as f32) are broken, and use regular G_TRUNC and G_ANYEXT. TLDR; the current call lowering infrastructure is bad and nobody has ever understood how it chooses types.
139 lines
6.1 KiB
LLVM
139 lines
6.1 KiB
LLVM
; RUN: llc -mtriple arm-unknown -verify-machineinstrs -global-isel -global-isel-abort=2 -pass-remarks-missed='gisel*' %s -o - 2>&1 | FileCheck %s -check-prefixes=CHECK
|
|
; RUN: llc -mtriple arm-unknown -verify-machineinstrs -global-isel -global-isel-abort=2 -pass-remarks-missed='gisel*' -relocation-model=pic %s -o - 2>&1 | FileCheck %s -check-prefixes=PIC
|
|
; RUN: llc -mtriple arm-unknown -verify-machineinstrs -global-isel -global-isel-abort=2 -pass-remarks-missed='gisel*' -relocation-model=ropi %s -o - 2>&1 | FileCheck %s -check-prefixes=ROPI
|
|
; RUN: llc -mtriple arm-unknown -verify-machineinstrs -global-isel -global-isel-abort=2 -pass-remarks-missed='gisel*' -relocation-model=rwpi %s -o - 2>&1 | FileCheck %s -check-prefixes=RWPI
|
|
; RUN: llc -mtriple arm-unknown -verify-machineinstrs -global-isel -global-isel-abort=2 -pass-remarks-missed='gisel*' -relocation-model=ropi-rwpi %s -o - 2>&1 | FileCheck %s -check-prefixes=ROPI-RWPI
|
|
|
|
; This file checks that we use the fallback path for things that are known to
|
|
; be unsupported on the ARM target. It should progressively shrink in size.
|
|
|
|
define <4 x i32> @test_int_vectors(<4 x i32> %a, <4 x i32> %b) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: <4 x i32> (<4 x i32>, <4 x i32>)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_int_vectors
|
|
%res = add <4 x i32> %a, %b
|
|
ret <4 x i32> %res
|
|
}
|
|
|
|
define <4 x float> @test_float_vectors(<4 x float> %a, <4 x float> %b) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: <4 x float> (<4 x float>, <4 x float>)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_float_vectors
|
|
%res = fadd <4 x float> %a, %b
|
|
ret <4 x float> %res
|
|
}
|
|
|
|
define i64 @test_i64(i64 %a, i64 %b) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: i64 (i64, i64)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_i64
|
|
%res = add i64 %a, %b
|
|
ret i64 %res
|
|
}
|
|
|
|
define void @test_i64_arr([1 x i64] %a) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: void ([1 x i64])*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_i64_arr
|
|
ret void
|
|
}
|
|
|
|
define i128 @test_i128(i128 %a, i128 %b) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: i128 (i128, i128)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_i128
|
|
%res = add i128 %a, %b
|
|
ret i128 %res
|
|
}
|
|
|
|
define i17 @test_funny_ints(i17 %a, i17 %b) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: i17 (i17, i17)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_funny_ints
|
|
%res = add i17 %a, %b
|
|
ret i17 %res
|
|
}
|
|
|
|
define half @test_half(half %a, half %b) {
|
|
; CHECK: remark: {{.*}} unable to legalize instruction: %{{[0-9]+}}:_(s16) = G_FADD %{{[0-9]+}}:_, %{{[0-9]+}}:_ (in function: test_half)
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_half
|
|
%res = fadd half %a, %b
|
|
ret half %res
|
|
}
|
|
|
|
declare [16 x i32] @ret_demotion_target()
|
|
|
|
define [16 x i32] @test_ret_demotion() {
|
|
; CHECK: remark: {{.*}} unable to translate instruction: call{{.*}} @ret_demotion_target
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_ret_demotion
|
|
%res = call [16 x i32] @ret_demotion_target()
|
|
ret [16 x i32] %res
|
|
}
|
|
|
|
%large.struct = type { i32, i32, i32, i32, i32} ; Doesn't fit in R0-R3
|
|
|
|
declare %large.struct @large_struct_return_target()
|
|
|
|
define %large.struct @test_large_struct_return() {
|
|
; CHECK: remark: {{.*}} unable to translate instruction: call{{.*}} @large_struct_return_target
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_large_struct_return
|
|
%r = call %large.struct @large_struct_return_target()
|
|
ret %large.struct %r
|
|
}
|
|
|
|
%mixed.struct = type {i32*, float, i32}
|
|
|
|
define %mixed.struct @test_mixed_struct(%mixed.struct %x) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: %mixed.struct (%mixed.struct)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_mixed_struct
|
|
ret %mixed.struct %x
|
|
}
|
|
|
|
%bad.element.type = type {i24, i24}
|
|
|
|
define void @test_bad_element_struct(%bad.element.type %x) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: void (%bad.element.type)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_bad_element_struct
|
|
ret void
|
|
}
|
|
|
|
define void @test_vararg_definition(i32 %a, ...) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: void (i32, ...)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_vararg_definition
|
|
ret void
|
|
}
|
|
|
|
define i32 @test_thumb(i32 %a) #0 {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: i32 (i32)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_thumb
|
|
ret i32 %a
|
|
}
|
|
|
|
@thread_local_global = thread_local global i32 42
|
|
|
|
define i32 @test_thread_local_global() {
|
|
; CHECK: remark: {{.*}} cannot select: {{.*}} G_GLOBAL_VALUE
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_thread_local_global
|
|
; PIC: remark: {{.*}} cannot select: {{.*}} G_GLOBAL_VALUE
|
|
; PIC-LABEL: warning: Instruction selection used fallback path for test_thread_local_global
|
|
; ROPI: remark: {{.*}} cannot select: {{.*}} G_GLOBAL_VALUE
|
|
; ROPI-LABEL: warning: Instruction selection used fallback path for test_thread_local_global
|
|
; RWPI: remark: {{.*}} cannot select: {{.*}} G_GLOBAL_VALUE
|
|
; RWPI-LABEL: warning: Instruction selection used fallback path for test_thread_local_global
|
|
; ROPI-RWPI: remark: {{.*}} cannot select: {{.*}} G_GLOBAL_VALUE
|
|
; ROPI-RWPI-LABEL: warning: Instruction selection used fallback path for test_thread_local_global
|
|
%v = load i32, i32* @thread_local_global
|
|
ret i32 %v
|
|
}
|
|
|
|
%byval.class = type { i32 }
|
|
|
|
define void @test_byval_arg(%byval.class* byval(%byval.class) %x) {
|
|
; CHECK: remark: {{.*}} unable to lower arguments: void (%byval.class*)*
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_byval
|
|
ret void
|
|
}
|
|
|
|
define void @test_byval_param(%byval.class* %x) {
|
|
; CHECK: remark: {{.*}} unable to translate instruction: call
|
|
; CHECK-LABEL: warning: Instruction selection used fallback path for test_byval_param
|
|
call void @test_byval_arg(%byval.class* byval(%byval.class) %x)
|
|
ret void
|
|
}
|
|
|
|
attributes #0 = { "target-features"="+thumb-mode" }
|