fabs-copysign.ll
4.26 KB
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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s
declare double @llvm.fabs.f64(double)
declare float @llvm.fabs.f32(float)
declare <4 x double> @llvm.fabs.v4f64(<4 x double>)
declare void @use(double)
declare double @llvm.copysign.f64(double, double)
declare float @llvm.copysign.f32(float, float)
define double @fabs_copysign(double %x) {
; CHECK-LABEL: @fabs_copysign(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf double @llvm.copysign.f64(double 1.000000e+00, double [[X:%.*]])
; CHECK-NEXT: ret double [[TMP1]]
;
%f = tail call double @llvm.fabs.f64(double %x)
%div = fdiv nnan ninf double %x, %f
ret double %div
}
define double @fabs_copysign_commuted(double %x) {
; CHECK-LABEL: @fabs_copysign_commuted(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf double @llvm.copysign.f64(double 1.000000e+00, double [[X:%.*]])
; CHECK-NEXT: ret double [[TMP1]]
;
%f = tail call double @llvm.fabs.f64(double %x)
%div = fdiv nnan ninf double %f, %x
ret double %div
}
define <4 x double> @fabs_copysign_vec(<4 x double> %x) {
; CHECK-LABEL: @fabs_copysign_vec(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf <4 x double> @llvm.copysign.v4f64(<4 x double> <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>, <4 x double> [[X:%.*]])
; CHECK-NEXT: ret <4 x double> [[TMP1]]
;
%f = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x)
%div = fdiv nnan ninf <4 x double> %x, %f
ret <4 x double> %div
}
define <4 x double> @fabs_copysign_vec_commuted(<4 x double> %x) {
; CHECK-LABEL: @fabs_copysign_vec_commuted(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf <4 x double> @llvm.copysign.v4f64(<4 x double> <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>, <4 x double> [[X:%.*]])
; CHECK-NEXT: ret <4 x double> [[TMP1]]
;
%f = call <4 x double> @llvm.fabs.v4f64(<4 x double> %x)
%div = fdiv nnan ninf <4 x double> %f, %x
ret <4 x double> %div
}
define float @fabs_copysignf(float %x) {
; CHECK-LABEL: @fabs_copysignf(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf float @llvm.copysign.f32(float 1.000000e+00, float [[X:%.*]])
; CHECK-NEXT: ret float [[TMP1]]
;
%f = tail call float @llvm.fabs.f32(float %x)
%div = fdiv nnan ninf float %x, %f
ret float %div
}
define double @fabs_copysign_use(double %x) {
; CHECK-LABEL: @fabs_copysign_use(
; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]])
; CHECK-NEXT: call void @use(double [[F]])
; CHECK-NEXT: [[TMP1:%.*]] = call nnan ninf double @llvm.copysign.f64(double 1.000000e+00, double [[X]])
; CHECK-NEXT: ret double [[TMP1]]
;
%f = tail call double @llvm.fabs.f64(double %x)
call void @use(double %f)
%div = fdiv nnan ninf double %x, %f
ret double %div
}
; Negative tests
define double @fabs_copysign_mismatch(double %x, double %y) {
; CHECK-LABEL: @fabs_copysign_mismatch(
; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[Y:%.*]])
; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[X:%.*]], [[F]]
; CHECK-NEXT: ret double [[DIV]]
;
%f = tail call double @llvm.fabs.f64(double %y)
%div = fdiv double %x, %f
ret double %div
}
define double @fabs_copysign_commuted_mismatch(double %x, double %y) {
; CHECK-LABEL: @fabs_copysign_commuted_mismatch(
; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[Y:%.*]])
; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[F]], [[X:%.*]]
; CHECK-NEXT: ret double [[DIV]]
;
%f = tail call double @llvm.fabs.f64(double %y)
%div = fdiv double %f, %x
ret double %div
}
define double @fabs_copysign_no_nnan(double %x) {
; CHECK-LABEL: @fabs_copysign_no_nnan(
; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]])
; CHECK-NEXT: [[DIV:%.*]] = fdiv ninf double [[X]], [[F]]
; CHECK-NEXT: ret double [[DIV]]
;
%f = tail call double @llvm.fabs.f64(double %x)
%div = fdiv ninf double %x, %f
ret double %div
}
define double @fabs_copysign_no_ninf(double %x) {
; CHECK-LABEL: @fabs_copysign_no_ninf(
; CHECK-NEXT: [[F:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]])
; CHECK-NEXT: [[DIV:%.*]] = fdiv nnan double [[X]], [[F]]
; CHECK-NEXT: ret double [[DIV]]
;
%f = tail call double @llvm.fabs.f64(double %x)
%div = fdiv nnan double %x, %f
ret double %div
}