File: returned.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (62 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (14)
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
}