mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-24 22:32:47 +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
29 lines
551 B
LLVM
29 lines
551 B
LLVM
; RUN: llc -march=hexagon < %s | FileCheck %s
|
|
|
|
declare i32 @ret_i32()
|
|
|
|
define i8 @test_i8() {
|
|
; CHECK-LABEL: test_i8:
|
|
; CHECK: jump ret_i32
|
|
%res = tail call i32 @ret_i32()
|
|
%val = trunc i32 %res to i8
|
|
ret i8 %val
|
|
}
|
|
|
|
define i16 @test_i16() {
|
|
; CHECK-LABEL: test_i16:
|
|
; CHECK: jump ret_i32
|
|
%res = tail call i32 @ret_i32()
|
|
%val = trunc i32 %res to i16
|
|
ret i16 %val
|
|
}
|
|
|
|
declare i64 @ret_i64()
|
|
define i32 @test_i32() {
|
|
; CHECK-LABEL: test_i32:
|
|
; CHECK: call ret_i64
|
|
%res = tail call i64 @ret_i64()
|
|
%val = trunc i64 %res to i32
|
|
ret i32 42
|
|
}
|