File: pow-1.ll

package info (click to toggle)
llvm-toolchain-5.0 1:5.0.1-2~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 553,688 kB
  • sloc: cpp: 2,878,786; ansic: 584,110; asm: 246,252; python: 124,751; objc: 106,925; sh: 21,542; lisp: 8,628; pascal: 5,885; ml: 5,544; perl: 5,312; makefile: 2,208; cs: 2,022; xml: 686; php: 212; csh: 117
file content (194 lines) | stat: -rw-r--r-- 6,774 bytes parent folder | download
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
; Test that the pow library call simplifier works correctly.
;
; RUN: opt < %s -instcombine -S | FileCheck %s
; RUN: opt -instcombine -S < %s -mtriple=x86_64-apple-macosx10.9 | FileCheck %s --check-prefix=CHECK-EXP10
; RUN: opt -instcombine -S < %s -mtriple=arm-apple-ios7.0 | FileCheck %s --check-prefix=CHECK-EXP10
; RUN: opt -instcombine -S < %s -mtriple=x86_64-apple-macosx10.8 | FileCheck %s --check-prefix=CHECK-NO-EXP10
; RUN: opt -instcombine -S < %s -mtriple=arm-apple-ios6.0 | FileCheck %s --check-prefix=CHECK-NO-EXP10
; RUN: opt -instcombine -S < %s -mtriple=x86_64-netbsd | FileCheck %s --check-prefix=CHECK-NO-EXP10
; RUN: opt -instcombine -S < %s -mtriple=arm-apple-tvos9.0 | FileCheck %s --check-prefix=CHECK-EXP10
; RUN: opt -instcombine -S < %s -mtriple=arm-apple-watchos2.0 | FileCheck %s --check-prefix=CHECK-EXP10
; rdar://7251832

; NOTE: The readonly attribute on the pow call should be preserved
; in the cases below where pow is transformed into another function call.

declare float @powf(float, float) nounwind readonly
declare double @pow(double, double) nounwind readonly

; Check pow(1.0, x) -> 1.0.

define float @test_simplify1(float %x) {
; CHECK-LABEL: @test_simplify1(
  %retval = call float @powf(float 1.0, float %x)
  ret float %retval
; CHECK-NEXT: ret float 1.000000e+00
}

define double @test_simplify2(double %x) {
; CHECK-LABEL: @test_simplify2(
  %retval = call double @pow(double 1.0, double %x)
  ret double %retval
; CHECK-NEXT: ret double 1.000000e+00
}

; Check pow(2.0, x) -> exp2(x).

define float @test_simplify3(float %x) {
; CHECK-LABEL: @test_simplify3(
  %retval = call float @powf(float 2.0, float %x)
; CHECK-NEXT: [[EXP2F:%[a-z0-9]+]] = call float @llvm.exp2.f32(float %x)
  ret float %retval
; CHECK-NEXT: ret float [[EXP2F]]
}

define double @test_simplify4(double %x) {
; CHECK-LABEL: @test_simplify4(
  %retval = call double @pow(double 2.0, double %x)
; CHECK-NEXT: [[EXP2:%[a-z0-9]+]] = call double @llvm.exp2.f64(double %x)
  ret double %retval
; CHECK-NEXT: ret double [[EXP2]]
}

; Check pow(x, 0.0) -> 1.0.

define float @test_simplify5(float %x) {
; CHECK-LABEL: @test_simplify5(
  %retval = call float @powf(float %x, float 0.0)
  ret float %retval
; CHECK-NEXT: ret float 1.000000e+00
}

define double @test_simplify6(double %x) {
; CHECK-LABEL: @test_simplify6(
  %retval = call double @pow(double %x, double 0.0)
  ret double %retval
; CHECK-NEXT: ret double 1.000000e+00
}

; Check pow(x, 0.5) -> fabs(sqrt(x)), where x != -infinity.

define float @test_simplify7(float %x) {
; CHECK-LABEL: @test_simplify7(
  %retval = call float @powf(float %x, float 0.5)
; CHECK-NEXT: [[SQRTF:%[a-z0-9]+]] = call float @sqrtf(float %x) [[NUW_RO:#[0-9]+]]
; CHECK-NEXT: [[FABSF:%[a-z0-9]+]] = call float @llvm.fabs.f32(float [[SQRTF]])
; CHECK-NEXT: [[FCMP:%[a-z0-9]+]] = fcmp oeq float %x, 0xFFF0000000000000
; CHECK-NEXT: [[SELECT:%[a-z0-9]+]] = select i1 [[FCMP]], float 0x7FF0000000000000, float [[FABSF]]
  ret float %retval
; CHECK-NEXT: ret float [[SELECT]]
}

define double @test_simplify8(double %x) {
; CHECK-LABEL: @test_simplify8(
  %retval = call double @pow(double %x, double 0.5)
; CHECK-NEXT: [[SQRT:%[a-z0-9]+]] = call double @sqrt(double %x) [[NUW_RO]]
; CHECK-NEXT: [[FABS:%[a-z0-9]+]] = call double @llvm.fabs.f64(double [[SQRT]])
; CHECK-NEXT: [[FCMP:%[a-z0-9]+]] = fcmp oeq double %x, 0xFFF0000000000000
; CHECK-NEXT: [[SELECT:%[a-z0-9]+]] = select i1 [[FCMP]], double 0x7FF0000000000000, double [[FABS]]
  ret double %retval
; CHECK-NEXT: ret double [[SELECT]]
}

; Check pow(-infinity, 0.5) -> +infinity.

define float @test_simplify9(float %x) {
; CHECK-LABEL: @test_simplify9(
  %retval = call float @powf(float 0xFFF0000000000000, float 0.5)
  ret float %retval
; CHECK-NEXT: ret float 0x7FF0000000000000
}

define double @test_simplify10(double %x) {
; CHECK-LABEL: @test_simplify10(
  %retval = call double @pow(double 0xFFF0000000000000, double 0.5)
  ret double %retval
; CHECK-NEXT: ret double 0x7FF0000000000000
}

; Check pow(x, 1.0) -> x.

define float @test_simplify11(float %x) {
; CHECK-LABEL: @test_simplify11(
  %retval = call float @powf(float %x, float 1.0)
  ret float %retval
; CHECK-NEXT: ret float %x
}

define double @test_simplify12(double %x) {
; CHECK-LABEL: @test_simplify12(
  %retval = call double @pow(double %x, double 1.0)
  ret double %retval
; CHECK-NEXT: ret double %x
}

; Check pow(x, 2.0) -> x*x.

define float @test_simplify13(float %x) {
; CHECK-LABEL: @test_simplify13(
  %retval = call float @powf(float %x, float 2.0)
; CHECK-NEXT: [[SQUARE:%[a-z0-9]+]] = fmul float %x, %x
  ret float %retval
; CHECK-NEXT: ret float [[SQUARE]]
}

define double @test_simplify14(double %x) {
; CHECK-LABEL: @test_simplify14(
  %retval = call double @pow(double %x, double 2.0)
; CHECK-NEXT: [[SQUARE:%[a-z0-9]+]] = fmul double %x, %x
  ret double %retval
; CHECK-NEXT: ret double [[SQUARE]]
}

; Check pow(x, -1.0) -> 1.0/x.

define float @test_simplify15(float %x) {
; CHECK-LABEL: @test_simplify15(
  %retval = call float @powf(float %x, float -1.0)
; CHECK-NEXT: [[RECIPROCAL:%[a-z0-9]+]] = fdiv float 1.000000e+00, %x
  ret float %retval
; CHECK-NEXT: ret float [[RECIPROCAL]]
}

define double @test_simplify16(double %x) {
; CHECK-LABEL: @test_simplify16(
  %retval = call double @pow(double %x, double -1.0)
; CHECK-NEXT: [[RECIPROCAL:%[a-z0-9]+]] = fdiv double 1.000000e+00, %x
  ret double %retval
; CHECK-NEXT: ret double [[RECIPROCAL]]
}

declare double @llvm.pow.f64(double %Val, double %Power)
define double @test_simplify17(double %x) {
; CHECK-LABEL: @test_simplify17(
  %retval = call double @llvm.pow.f64(double %x, double 0.5)
; CHECK-NEXT: [[SQRT:%[a-z0-9]+]] = call double @sqrt(double %x)
; CHECK-NEXT: [[FABS:%[a-z0-9]+]] = call double @llvm.fabs.f64(double [[SQRT]])
; CHECK-NEXT: [[FCMP:%[a-z0-9]+]] = fcmp oeq double %x, 0xFFF0000000000000
; CHECK-NEXT: [[SELECT:%[a-z0-9]+]] = select i1 [[FCMP]], double 0x7FF0000000000000, double [[FABS]]
  ret double %retval
; CHECK-NEXT: ret double [[SELECT]]
}

; Check pow(10.0, x) -> __exp10(x) on OS X 10.9+ and iOS 7.0+.

define float @test_simplify18(float %x) {
; CHECK-LABEL: @test_simplify18(
  %retval = call float @powf(float 10.0, float %x)
; CHECK-EXP10: [[EXP10F:%[_a-z0-9]+]] = call float @__exp10f(float %x) [[NUW_RO:#[0-9]+]]
  ret float %retval
; CHECK-EXP10: ret float [[EXP10F]]
; CHECK-NO-EXP10: call float @powf
}

define double @test_simplify19(double %x) {
; CHECK-LABEL: @test_simplify19(
  %retval = call double @pow(double 10.0, double %x)
; CHECK-EXP10: [[EXP10:%[_a-z0-9]+]] = call double @__exp10(double %x) [[NUW_RO]]
  ret double %retval
; CHECK-EXP10: ret double [[EXP10]]
; CHECK-NO-EXP10: call double @pow
}

; CHECK: attributes [[NUW_RO]] = { nounwind readonly }