File: returned.ll

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (76 lines) | stat: -rw-r--r-- 2,768 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s

; Test that the "returned" attribute is optimized effectively.

target triple = "wasm32-unknown-unknown"

; CHECK-LABEL: _Z3foov:
; CHECK-NEXT: .functype _Z3foov () -> (i32){{$}}
; CHECK-NEXT: i32.const $push0=, 1{{$}}
; CHECK-NEXT: {{^}} call      $push1=, _Znwm, $pop0{{$}}
; CHECK-NEXT: {{^}} call      $push2=, _ZN5AppleC1Ev, $pop1{{$}}
; CHECK-NEXT: return    $pop2{{$}}
%class.Apple = type { i8 }
declare noalias ptr @_Znwm(i32)
declare ptr @_ZN5AppleC1Ev(ptr returned)
define ptr @_Z3foov() {
entry:
  %call = tail call noalias ptr @_Znwm(i32 1)
  %call1 = tail call ptr @_ZN5AppleC1Ev(ptr %call)
  ret ptr %call
}

; CHECK-LABEL: _Z3barPvS_l:
; CHECK-NEXT: .functype _Z3barPvS_l (i32, i32, i32) -> (i32){{$}}
; CHECK-NEXT: {{^}} call     $push0=, memcpy, $0, $1, $2{{$}}
; CHECK-NEXT: return   $pop0{{$}}
declare ptr @memcpy(ptr returned, ptr, i32)
define ptr @_Z3barPvS_l(ptr %p, ptr %s, i32 %n) {
entry:
  %call = tail call ptr @memcpy(ptr %p, ptr %s, i32 %n)
  ret ptr %p
}

; Test that the optimization isn't performed on constant arguments.

; CHECK-LABEL: test_constant_arg:
; CHECK:      i32.const   $push0=, global{{$}}
; CHECK-NEXT: {{^}} call        $drop=, returns_arg, $pop0{{$}}
; CHECK-NEXT: return{{$}}
@global = external global i32
@addr = global ptr @global
define void @test_constant_arg() {
  %call = call ptr @returns_arg(ptr @global)
  ret void
}
declare ptr @returns_arg(ptr returned)

; Test that the optimization isn't performed on arguments without the
; "returned" attribute.

; CHECK-LABEL: test_other_skipped:
; CHECK-NEXT: .functype test_other_skipped (i32, i32, f64) -> (){{$}}
; CHECK-NEXT: {{^}} call     $drop=, do_something, $0, $1, $2{{$}}
; CHECK-NEXT: {{^}} call     do_something_with_i32, $1{{$}}
; CHECK-NEXT: {{^}} call     do_something_with_double, $2{{$}}
declare i32 @do_something(i32 returned, i32, double)
declare void @do_something_with_i32(i32)
declare void @do_something_with_double(double)
define void @test_other_skipped(i32 %a, i32 %b, double %c) {
    %call = call i32 @do_something(i32 %a, i32 %b, double %c)
    call void @do_something_with_i32(i32 %b)
    call void @do_something_with_double(double %c)
    ret void
}

; Test that the optimization is performed on arguments other than the first.

; CHECK-LABEL: test_second_arg:
; CHECK-NEXT: .functype test_second_arg (i32, i32) -> (i32){{$}}
; CHECK-NEXT: {{^}} call     $push0=, do_something_else, $0, $1{{$}}
; CHECK-NEXT: return   $pop0{{$}}
declare i32 @do_something_else(i32, i32 returned)
define i32 @test_second_arg(i32 %a, i32 %b) {
    %call = call i32 @do_something_else(i32 %a, i32 %b)
    ret i32 %b
}