Skip to content

Commit 9cc669d

Browse files
committed
[InstCombine][InstSimplify] add tests for sign of maxnum; NFC
More coverage for D83601.
1 parent 84a1bc7 commit 9cc669d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

llvm/test/Transforms/InstCombine/copysign.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
declare float @llvm.fabs.f32(float)
55
declare float @llvm.copysign.f32(float, float)
6+
declare float @llvm.maxnum.f32(float, float)
67
declare <3 x double> @llvm.copysign.v3f64(<3 x double>, <3 x double>)
78

89
define float @positive_sign_arg(float %x) {
@@ -63,6 +64,18 @@ define <3 x double> @known_positive_sign_arg_vec(<3 x double> %x, <3 x i32> %y)
6364
ret <3 x double> %r
6465
}
6566

67+
; FIXME: maxnum(-0.0, 0.0) can return -0.0.
68+
69+
define float @not_known_positive_sign_arg(float %x, float %y) {
70+
; CHECK-LABEL: @not_known_positive_sign_arg(
71+
; CHECK-NEXT: [[TMP1:%.*]] = call ninf float @llvm.fabs.f32(float [[Y:%.*]])
72+
; CHECK-NEXT: ret float [[TMP1]]
73+
;
74+
%max = call float @llvm.maxnum.f32(float %x, float 0.0)
75+
%r = call ninf float @llvm.copysign.f32(float %y, float %max)
76+
ret float %r
77+
}
78+
6679
; The magnitude operand of the 1st copysign is irrelevant.
6780
; copysign(x, copysign(y, z)) --> copysign(x, z)
6881

llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,3 +1383,13 @@ define float @maxnum_with_negzero_op_commute(float %a) {
13831383
%fabs = call float @llvm.fabs.f32(float %max)
13841384
ret float %fabs
13851385
}
1386+
1387+
define float @maxnum_with_pos_one_op(float %a) {
1388+
; CHECK-LABEL: @maxnum_with_pos_one_op(
1389+
; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[A:%.*]], float 1.000000e+00)
1390+
; CHECK-NEXT: ret float [[MAX]]
1391+
;
1392+
%max = call float @llvm.maxnum.f32(float %a, float 1.0)
1393+
%fabs = call float @llvm.fabs.f32(float %max)
1394+
ret float %fabs
1395+
}

llvm/test/Transforms/InstSimplify/floating-point-compare.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ define i1 @orderedLessZero_fdiv(float %x) {
212212
ret i1 %uge
213213
}
214214

215+
define i1 @orderedLessZero_maxnum(float %x) {
216+
; CHECK-LABEL: @orderedLessZero_maxnum(
217+
; CHECK-NEXT: ret i1 true
218+
;
219+
%d = call float @llvm.maxnum.f32(float %x, float 0.0)
220+
%uge = fcmp uge float %d, 0.0
221+
ret i1 %uge
222+
}
223+
215224
define i1 @orderedLessZeroExpExt(float) {
216225
; CHECK-LABEL: @orderedLessZeroExpExt(
217226
; CHECK-NEXT: ret i1 true

0 commit comments

Comments
 (0)