Skip to content

Commit e219d38

Browse files
author
Evandro Menezes
committedAug 17, 2018
[NFC] Expand test cases for simplifying pow()
In prepatration for the improvements that D49273 enables. llvm-svn: 340060
1 parent 730890d commit e219d38

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed
 

‎llvm/test/Transforms/InstCombine/pow-1.ll

+41-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ define <2 x double> @test_simplify2v(<2 x double> %x) {
5353
ret <2 x double> %retval
5454
}
5555

56-
; Check pow(2.0, x) -> exp2(x).
56+
; Check pow(2.0 ** n, x) -> exp2(n * x).
5757

5858
define float @test_simplify3(float %x) {
5959
; ANY-LABEL: @test_simplify3(
@@ -64,6 +64,16 @@ define float @test_simplify3(float %x) {
6464
ret float %retval
6565
}
6666

67+
; TODO: Should result in exp2(-2.0 * x).
68+
define double @test_simplify3n(double %x) {
69+
; ANY-LABEL: @test_simplify3n(
70+
; ANY-NEXT: [[RETVAL:%.*]] = call double @pow(double 2.500000e-01, double [[X:%.*]])
71+
; ANY-NEXT: ret double [[RETVAL]]
72+
;
73+
%retval = call double @pow(double 0.25, double %x)
74+
ret double %retval
75+
}
76+
6777
define <2 x float> @test_simplify3v(<2 x float> %x) {
6878
; ANY-LABEL: @test_simplify3v(
6979
; ANY-NEXT: [[EXP2:%.*]] = call <2 x float> @llvm.exp2.v2f32(<2 x float> [[X:%.*]])
@@ -73,6 +83,16 @@ define <2 x float> @test_simplify3v(<2 x float> %x) {
7383
ret <2 x float> %retval
7484
}
7585

86+
; TODO: Should result in exp2(2.0 * x).
87+
define <2 x double> @test_simplify3vn(<2 x double> %x) {
88+
; ANY-LABEL: @test_simplify3vn(
89+
; ANY-NEXT: [[RETVAL:%.*]] = call <2 x double> @llvm.pow.v2f64(<2 x double> <double 4.000000e+00, double 4.000000e+00>, <2 x double> [[X:%.*]])
90+
; ANY-NEXT: ret <2 x double> [[RETVAL]]
91+
;
92+
%retval = call <2 x double> @llvm.pow.v2f64(<2 x double> <double 4.0, double 4.0>, <2 x double> %x)
93+
ret <2 x double> %retval
94+
}
95+
7696
define double @test_simplify4(double %x) {
7797
; ANY-LABEL: @test_simplify4(
7898
; ANY-NEXT: [[EXP2:%.*]] = call double @llvm.exp2.f64(double [[X:%.*]])
@@ -82,6 +102,16 @@ define double @test_simplify4(double %x) {
82102
ret double %retval
83103
}
84104

105+
; TODO: Should result in exp2f(3.0 * x).
106+
define float @test_simplify4n(float %x) {
107+
; ANY-LABEL: @test_simplify4n(
108+
; ANY-NEXT: [[RETVAL:%.*]] = call float @powf(float 8.000000e+00, float [[X:%.*]])
109+
; ANY-NEXT: ret float [[RETVAL]]
110+
;
111+
%retval = call float @powf(float 8.0, float %x)
112+
ret float %retval
113+
}
114+
85115
define <2 x double> @test_simplify4v(<2 x double> %x) {
86116
; ANY-LABEL: @test_simplify4v(
87117
; ANY-NEXT: [[EXP2:%.*]] = call <2 x double> @llvm.exp2.v2f64(<2 x double> [[X:%.*]])
@@ -91,6 +121,16 @@ define <2 x double> @test_simplify4v(<2 x double> %x) {
91121
ret <2 x double> %retval
92122
}
93123

124+
; TODO: Should result in exp2f(-x).
125+
define <2 x float> @test_simplify4vn(<2 x float> %x) {
126+
; ANY-LABEL: @test_simplify4vn(
127+
; ANY-NEXT: [[RETVAL:%.*]] = call <2 x float> @llvm.pow.v2f32(<2 x float> <float 5.000000e-01, float 5.000000e-01>, <2 x float> [[X:%.*]])
128+
; ANY-NEXT: ret <2 x float> [[RETVAL]]
129+
;
130+
%retval = call <2 x float> @llvm.pow.v2f32(<2 x float> <float 0.5, float 0.5>, <2 x float> %x)
131+
ret <2 x float> %retval
132+
}
133+
94134
; Check pow(x, 0.0) -> 1.0.
95135

96136
define float @test_simplify5(float %x) {
@@ -332,4 +372,3 @@ define double @test_simplify19(double %x) {
332372
}
333373

334374
; CHECK-EXP10: attributes [[NUW_RO]] = { nounwind readonly }
335-

‎llvm/test/Transforms/InstCombine/pow-exp.ll

+55-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt < %s -instcombine -S | FileCheck %s
33

4+
; TODO: Should result in expf(x * y).
5+
define float @powf_expf(float %x, float %y) {
6+
; CHECK-LABEL: @powf_expf(
7+
; CHECK-NEXT: [[CALL:%.*]] = call fast float @expf(float [[X:%.*]]) #1
8+
; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]])
9+
; CHECK-NEXT: ret float [[POW]]
10+
;
11+
%call = call fast float @expf(float %x) nounwind readnone
12+
%pow = call fast float @llvm.pow.f32(float %call, float %y)
13+
ret float %pow
14+
}
15+
16+
; TODO: Should result in intrinsic call to exp().
417
define double @pow_exp(double %x, double %y) {
518
; CHECK-LABEL: @pow_exp(
619
; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
@@ -12,6 +25,19 @@ define double @pow_exp(double %x, double %y) {
1225
ret double %pow
1326
}
1427

28+
; TODO: Should result in exp2f(x * y).
29+
define float @powf_exp2f(float %x, float %y) {
30+
; CHECK-LABEL: @powf_exp2f(
31+
; CHECK-NEXT: [[CALL:%.*]] = call fast float @exp2f(float [[X:%.*]]) #1
32+
; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]])
33+
; CHECK-NEXT: ret float [[POW]]
34+
;
35+
%call = call fast float @exp2f(float %x) nounwind readnone
36+
%pow = call fast float @llvm.pow.f32(float %call, float %y)
37+
ret float %pow
38+
}
39+
40+
; TODO: Should result in intrinsic call to exp2().
1541
define double @pow_exp2(double %x, double %y) {
1642
; CHECK-LABEL: @pow_exp2(
1743
; CHECK-NEXT: [[MUL:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
@@ -23,6 +49,30 @@ define double @pow_exp2(double %x, double %y) {
2349
ret double %pow
2450
}
2551

52+
; TODO: exp10() is not widely enabled by many targets yet.
53+
54+
define float @powf_exp10f(float %x, float %y) {
55+
; CHECK-LABEL: @powf_exp10f(
56+
; CHECK-NEXT: [[CALL:%.*]] = call fast float @exp10f(float [[X:%.*]]) #1
57+
; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]])
58+
; CHECK-NEXT: ret float [[POW]]
59+
;
60+
%call = call fast float @exp10f(float %x) nounwind readnone
61+
%pow = call fast float @llvm.pow.f32(float %call, float %y)
62+
ret float %pow
63+
}
64+
65+
define double @pow_exp10(double %x, double %y) {
66+
; CHECK-LABEL: @pow_exp10(
67+
; CHECK-NEXT: [[CALL:%.*]] = call fast double @exp10(double [[X:%.*]]) #1
68+
; CHECK-NEXT: [[POW:%.*]] = call fast double @llvm.pow.f64(double [[CALL]], double [[Y:%.*]])
69+
; CHECK-NEXT: ret double [[POW]]
70+
;
71+
%call = call fast double @exp10(double %x) nounwind readnone
72+
%pow = call fast double @llvm.pow.f64(double %call, double %y)
73+
ret double %pow
74+
}
75+
2676
define double @pow_exp_not_fast(double %x, double %y) {
2777
; CHECK-LABEL: @pow_exp_not_fast(
2878
; CHECK-NEXT: [[CALL:%.*]] = call double @exp(double [[X:%.*]])
@@ -46,6 +96,10 @@ define double @function_pointer(double ()* %fptr, double %p1) {
4696
}
4797

4898
declare double @exp(double)
99+
declare float @expf(float)
49100
declare double @exp2(double)
101+
declare float @exp2f(float)
102+
declare double @exp10(double)
103+
declare float @exp10f(float)
50104
declare double @llvm.pow.f64(double, double)
51-
105+
declare float @llvm.pow.f32(float, float)

0 commit comments

Comments
 (0)
Please sign in to comment.