File: i128-cmp-ext-conv.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,999,616 kB
  • sloc: cpp: 6,951,724; ansic: 1,486,157; asm: 913,598; python: 232,059; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,079; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,430; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (143 lines) | stat: -rw-r--r-- 5,619 bytes parent folder | download | duplicates (6)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
; RUN: opt < %s -passes="print<cost-model>" 2>&1 -disable-output -mtriple=systemz-unknown -mcpu=z13 | FileCheck %s
;

define i128 @fun1(i128 %val1, i128 %val2) {
; CHECK-LABEL: 'fun1'
; CHECK: Cost Model: Found an estimated cost of 1 for instruction:   %cmp = icmp eq i128 %val1, %val2
; CHECK: Cost Model: Found an estimated cost of 5 for instruction:   %v128 = sext i1 %cmp to i128
  %cmp = icmp eq i128 %val1, %val2
  %v128 = sext i1 %cmp to i128
  ret i128 %v128
}

define i128 @fun2(i128 %val1, i128 %val2) {
; CHECK-LABEL: 'fun2'
; CHECK: Cost Model: Found an estimated cost of 1 for instruction:   %cmp = icmp eq i128 %val1, %val2
; CHECK: Cost Model: Found an estimated cost of 5 for instruction:   %v128 = zext i1 %cmp to i128
  %cmp = icmp eq i128 %val1, %val2
  %v128 = zext i1 %cmp to i128
  ret i128 %v128
}

define i128 @fun3(i128 %val1, i128 %val2,
                  i128 %val3, i128 %val4) {
; CHECK-LABEL: 'fun3'
; CHECK: Cost Model: Found an estimated cost of 1 for instruction:   %cmp = icmp eq i128 %val1, %val2
; CHECK: Cost Model: Found an estimated cost of 1 for instruction:   %add = add i128 %val3, %val4
; CHECK: Cost Model: Found an estimated cost of 4 for instruction:   %sel = select i1 %cmp, i128 %val3, i128 %add
  %cmp = icmp eq i128 %val1, %val2
  %add = add i128 %val3, %val4
  %sel = select i1 %cmp, i128 %val3, i128 %add
  ret i128 %sel
}

define i128 @fun4(ptr %src) {
; CHECK-LABEL: 'fun4'
; CHECK: Cost Model: Found an estimated cost of 2 for instruction:   %res = sext i64 %v to i128
  %v = load i64, ptr %src, align 8
  %res = sext i64 %v to i128
  ret i128 %res
}

define i128 @fun5(i64 %lhs, i64 %rhs) {
; CHECK-LABEL: 'fun5'
; CHECK: Cost Model: Found an estimated cost of 2 for instruction:   %res = sext i64 %v to i128
  %v = add i64 %lhs, %rhs
  %res = sext i64 %v to i128
  ret i128 %res
}

define i128 @fun6(ptr %src) {
; CHECK-LABEL: 'fun6'
; CHECK: Cost Model: Found an estimated cost of 1 for instruction:   %res = zext i64 %v to i128
  %v = load i64, ptr %src, align 8
  %res = zext i64 %v to i128
  ret i128 %res
}

define i128 @fun7(i64 %lhs, i64 %rhs) {
; CHECK-LABEL: 'fun7'
; CHECK: Cost Model: Found an estimated cost of 2 for instruction:   %res = zext i64 %v to i128
  %v = add i64 %lhs, %rhs
  %res = zext i64 %v to i128
  ret i128 %res
}

; Truncating store is free.
define void @fun8(i128 %lhs, i128 %rhs, ptr %dst) {
; CHECK-LABEL: 'fun8'
; CHECK: Cost Model: Found an estimated cost of 0 for instruction:   %t = trunc i128 %v to i64
  %v = add i128 %lhs, %rhs
  %t = trunc i128 %v to i64
  store i64 %t, ptr %dst, align 8
  ret void
}

; If there is a non-store user, an extraction is needed.
define i64 @fun9(i128 %lhs, i128 %rhs, ptr %dst) {
; CHECK-LABEL: 'fun9'
; CHECK: Cost Model: Found an estimated cost of 2 for instruction:   %t = trunc i128 %v to i64
  %v = add i128 %lhs, %rhs
  %t = trunc i128 %v to i64
  store i64 %t, ptr %dst, align 8
  ret i64 %t
}

; Truncation of load is free.
define i64 @fun10(ptr %src) {
; CHECK-LABEL: 'fun10'
; CHECK: Cost Model: Found an estimated cost of 0 for instruction:   %t = trunc i128 %v to i64
  %v = load i128, ptr %src, align 8
  %t = trunc i128 %v to i64
  ret i64 %t
}

; If the load has another user, the truncation becomes an extract.
define i64 @fun11(ptr %src, i128 %val2, ptr %dst) {
; CHECK-LABEL: 'fun11'
; CHECK: Cost Model: Found an estimated cost of 2 for instruction:   %t = trunc i128 %v to i64
  %v = load i128, ptr %src, align 8
  %t = trunc i128 %v to i64
  %a = add i128 %v, %val2
  store i128 %a, ptr %dst
  ret i64 %t
}

; Trunction with a GPR use typically requires an extraction.
define i64 @fun12(i128 %lhs, i128 %rhs) {
; CHECK-LABEL: 'fun12'
; CHECK: Cost Model: Found an estimated cost of 2 for instruction:   %t = trunc i128 %v to i64
  %v = add i128 %lhs, %rhs
  %t = trunc i128 %v to i64
  ret i64 %t
}

; Fp<->Int conversions require libcalls.
define void @fun13() {
; CHECK-LABEL: 'fun13'
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v0 = fptosi fp128 undef to i128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v1 = fptosi double undef to i128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v2 = fptosi float undef to i128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v3 = fptoui fp128 undef to i128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v4 = fptoui double undef to i128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v5 = fptoui float undef to i128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v6 = sitofp i128 undef to fp128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v7 = sitofp i128 undef to double
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v8 = sitofp i128 undef to float
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v9 = uitofp i128 undef to fp128
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v10 = uitofp i128 undef to double
; CHECK: Cost Model: Found an estimated cost of 30 for instruction:   %v11 = uitofp i128 undef to float
  %v0 = fptosi fp128 undef to i128
  %v1 = fptosi double undef to i128
  %v2 = fptosi float undef to i128
  %v3 = fptoui fp128 undef to i128
  %v4 = fptoui double undef to i128
  %v5 = fptoui float undef to i128
  %v6 = sitofp i128 undef to fp128
  %v7 = sitofp i128 undef to double
  %v8 = sitofp i128 undef to float
  %v9 = uitofp i128 undef to fp128
  %v10 = uitofp i128 undef to double
  %v11 = uitofp i128 undef to float
  ret void
}