File: returned.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (62 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (12)
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
; RUN: opt < %s -passes=deadargelim -S | FileCheck %s

%Ty = type { i32, i32 }

; Validate that the argument and return value are both dead
; CHECK-LABEL: define internal void @test1()

define internal ptr @test1(ptr %this) {
  ret ptr %this
}

; do not keep alive the return value of a function with a dead 'returned' argument
; CHECK-LABEL: define internal void @test2()

define internal ptr @test2(ptr returned %this) {
  ret ptr %this
}

; dummy to keep 'this' alive
@dummy = global ptr null 

; Validate that return value is dead
; CHECK-LABEL: define internal void @test3(ptr %this)

define internal ptr @test3(ptr %this) {
  store volatile ptr %this, ptr @dummy
  ret ptr %this
}

; keep alive return value of a function if the 'returned' argument is live
; CHECK-LABEL: define internal ptr @test4(ptr returned %this)

define internal ptr @test4(ptr returned %this) {
  store volatile ptr %this, ptr @dummy
  ret ptr %this
}

; don't do this if 'returned' is on the call site...
; CHECK-LABEL: define internal void @test5(ptr %this)

define internal ptr @test5(ptr %this) {
  store volatile ptr %this, ptr @dummy
  ret ptr %this
}

; Drop all these attributes
; CHECK-LABEL: define internal void @test6
define internal align 8 dereferenceable_or_null(2) noundef noalias ptr @test6() {
  ret ptr null
}

define ptr @caller(ptr %this) {
  %1 = call ptr @test1(ptr %this)
  %2 = call ptr @test2(ptr %this)
  %3 = call ptr @test3(ptr %this)
  %4 = call ptr @test4(ptr %this)
; ...instead, drop 'returned' form the call site
; CHECK: call void @test5(ptr %this)
  %5 = call ptr @test5(ptr returned %this)
  %6 = call ptr @test6()
  ret ptr %this
}