mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-27 13:30:05 +00:00
d113448c1d
This change came about primarily because of two issues in the existing code. Niether of: define i64 @test1(i64 %val) { %in = trunc i64 %val to i32 tail call i32 @ret32(i32 returned %in) ret i64 %val } define i64 @test2(i64 %val) { tail call i32 @ret32(i32 returned undef) ret i32 42 } should be tail calls, and the function sameNoopInput is responsible. The main problem is that it is completely symmetric in the "tail call" and "ret" value, but in reality different things are allowed on each side. For these cases: 1. Any truncation should lead to a larger value being generated by "tail call" than needed by "ret". 2. Undef should only be allowed as a source for ret, not as a result of the call. Along the way I noticed that a mismatch between what this function treats as a valid truncation and what the backends see can lead to invalid calls as well (see x86-32 test case). This patch refactors the code so that instead of being based primarily on values which it recurses into when necessary, it starts by inspecting the type and considers each fundamental slot that the backend will see in turn. For example, given a pathological function that returned {{}, {{}, i32, {}}, i32} we would consider each "real" i32 in turn, and ask if it passes through unchanged. This is much closer to what the backend sees as a result of ComputeValueVTs. Aside from the bug fixes, this eliminates the recursion that's going on and, I believe, makes the bulk of the code significantly easier to understand. The trade-off is the nasty iterators needed to find the real types inside a returned value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187787 91177308-0d34-0410-b5e6-96231b3b80d8
98 lines
2.7 KiB
LLVM
98 lines
2.7 KiB
LLVM
; RUN: llc < %s -mtriple=x86_64-pc-win32 | FileCheck %s
|
|
|
|
declare i32 @ret32(i32 returned)
|
|
declare i64 @ret64(i64 returned)
|
|
|
|
define i64 @test1(i64 %val) {
|
|
; CHECK-LABEL: test1:
|
|
; CHECK-NOT: jmp
|
|
; CHECK: callq
|
|
%in = trunc i64 %val to i32
|
|
tail call i32 @ret32(i32 returned %in)
|
|
ret i64 %val
|
|
}
|
|
|
|
define i32 @test2(i64 %val) {
|
|
; CHECK-LABEL: test2:
|
|
; CHECK: jmp
|
|
; CHECK-NOT: callq
|
|
%in = trunc i64 %val to i32
|
|
tail call i64 @ret64(i64 returned %val)
|
|
ret i32 %in
|
|
}
|
|
|
|
define i32 @test3(i64 %in) {
|
|
; CHECK-LABEL: test3:
|
|
; CHECK: jmp
|
|
; CHECK-NOT: callq
|
|
%small = trunc i64 %in to i32
|
|
tail call i32 @ret32(i32 returned %small)
|
|
ret i32 %small
|
|
}
|
|
|
|
declare {i32, i8} @take_i32_i8({i32, i8} returned)
|
|
define { i8, i8 } @test_nocommon_value({i32, i32} %in) {
|
|
; CHECK-LABEL: test_nocommon_value
|
|
; CHECK: jmp
|
|
|
|
%first = extractvalue {i32, i32} %in, 0
|
|
%first.trunc = trunc i32 %first to i8
|
|
|
|
%second = extractvalue {i32, i32} %in, 1
|
|
%second.trunc = trunc i32 %second to i8
|
|
|
|
%tmp = insertvalue {i32, i8} undef, i32 %first, 0
|
|
%callval = insertvalue {i32, i8} %tmp, i8 %second.trunc, 1
|
|
tail call {i32, i8} @take_i32_i8({i32, i8} returned %callval)
|
|
|
|
%restmp = insertvalue {i8, i8} undef, i8 %first.trunc, 0
|
|
%res = insertvalue {i8, i8} %restmp, i8 %second.trunc, 1
|
|
ret {i8, i8} %res
|
|
}
|
|
|
|
declare {i32, {i32, i32}} @give_i32_i32_i32()
|
|
define {{i32, i32}, i32} @test_structs_different_shape() {
|
|
; CHECK-LABEL: test_structs_different_shape
|
|
; CHECK: jmp
|
|
%val = tail call {i32, {i32, i32}} @give_i32_i32_i32()
|
|
|
|
%first = extractvalue {i32, {i32, i32}} %val, 0
|
|
%second = extractvalue {i32, {i32, i32}} %val, 1, 0
|
|
%third = extractvalue {i32, {i32, i32}} %val, 1, 1
|
|
|
|
%restmp = insertvalue {{i32, i32}, i32} undef, i32 %first, 0, 0
|
|
%reseventmper = insertvalue {{i32, i32}, i32} %restmp, i32 %second, 0, 1
|
|
%res = insertvalue {{i32, i32}, i32} %reseventmper, i32 %third, 1
|
|
|
|
ret {{i32, i32}, i32} %res
|
|
}
|
|
|
|
define i64 @test_undef_asymmetry() {
|
|
; CHECK: test_undef_asymmetry
|
|
; CHECK-NOT: jmp
|
|
tail call i64 @ret64(i64 returned undef)
|
|
ret i64 2
|
|
}
|
|
|
|
define {{}, {{}, i32, {}}, [1 x i32]} @evil_empty_aggregates() {
|
|
; CHECK-LABEL: evil_empty_aggregates
|
|
; CHECK: jmp
|
|
%agg = tail call {i32, {i32, i32}} @give_i32_i32_i32()
|
|
|
|
%first = extractvalue {i32, {i32, i32}} %agg, 0
|
|
%second = extractvalue {i32, {i32, i32}} %agg, 1, 0
|
|
|
|
%restmp = insertvalue {{}, {{}, i32, {}}, [1 x i32]} undef, i32 %first, 1, 1
|
|
%res = insertvalue {{}, {{}, i32, {}}, [1 x i32]} %restmp, i32 %second, 2, 0
|
|
ret {{}, {{}, i32, {}}, [1 x i32]} %res
|
|
}
|
|
|
|
define i32 @structure_is_unimportant() {
|
|
; CHECK-LABEL: structure_is_unimportant
|
|
; CHECK: jmp
|
|
%val = tail call {i32, {i32, i32}} @give_i32_i32_i32()
|
|
|
|
%res = extractvalue {i32, {i32, i32}} %val, 0
|
|
ret i32 %res
|
|
}
|