2019-11-28 00:11:28 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
|
|
; RUN: opt -S -instcombine < %s | FileCheck %s
|
|
|
|
|
2019-12-18 05:46:42 +08:00
|
|
|
declare float @llvm.fabs.f32(float)
|
2019-11-28 00:11:28 +08:00
|
|
|
declare float @llvm.copysign.f32(float, float)
|
2020-07-14 04:02:10 +08:00
|
|
|
declare float @llvm.maxnum.f32(float, float)
|
2019-11-28 00:11:28 +08:00
|
|
|
declare <3 x double> @llvm.copysign.v3f64(<3 x double>, <3 x double>)
|
|
|
|
|
|
|
|
define float @positive_sign_arg(float %x) {
|
|
|
|
; CHECK-LABEL: @positive_sign_arg(
|
2019-12-02 22:21:59 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call arcp float @llvm.fabs.f32(float [[X:%.*]])
|
|
|
|
; CHECK-NEXT: ret float [[TMP1]]
|
2019-11-28 00:11:28 +08:00
|
|
|
;
|
|
|
|
%r = call arcp float @llvm.copysign.f32(float %x, float 0.0)
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define <3 x double> @positive_sign_arg_vec_splat(<3 x double> %x) {
|
|
|
|
; CHECK-LABEL: @positive_sign_arg_vec_splat(
|
2019-12-02 22:21:59 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call ninf <3 x double> @llvm.fabs.v3f64(<3 x double> [[X:%.*]])
|
|
|
|
; CHECK-NEXT: ret <3 x double> [[TMP1]]
|
2019-11-28 00:11:28 +08:00
|
|
|
;
|
|
|
|
%r = call ninf <3 x double> @llvm.copysign.v3f64(<3 x double> %x, <3 x double> <double 42.0, double 42.0, double 42.0>)
|
|
|
|
ret <3 x double> %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define float @negative_sign_arg(float %x) {
|
|
|
|
; CHECK-LABEL: @negative_sign_arg(
|
2019-12-02 22:21:59 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call nnan float @llvm.fabs.f32(float [[X:%.*]])
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = fneg nnan float [[TMP1]]
|
|
|
|
; CHECK-NEXT: ret float [[TMP2]]
|
2019-11-28 00:11:28 +08:00
|
|
|
;
|
|
|
|
%r = call nnan float @llvm.copysign.f32(float %x, float -0.0)
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define <3 x double> @negative_sign_arg_vec_splat(<3 x double> %x) {
|
|
|
|
; CHECK-LABEL: @negative_sign_arg_vec_splat(
|
2019-12-02 22:21:59 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call fast <3 x double> @llvm.fabs.v3f64(<3 x double> [[X:%.*]])
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = fneg fast <3 x double> [[TMP1]]
|
|
|
|
; CHECK-NEXT: ret <3 x double> [[TMP2]]
|
2019-11-28 00:11:28 +08:00
|
|
|
;
|
|
|
|
%r = call fast <3 x double> @llvm.copysign.v3f64(<3 x double> %x, <3 x double> <double -42.0, double -42.0, double -42.0>)
|
|
|
|
ret <3 x double> %r
|
|
|
|
}
|
2019-12-18 05:46:42 +08:00
|
|
|
|
|
|
|
define float @known_positive_sign_arg(float %x, float %y) {
|
|
|
|
; CHECK-LABEL: @known_positive_sign_arg(
|
2019-12-22 23:05:28 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call ninf float @llvm.fabs.f32(float [[X:%.*]])
|
|
|
|
; CHECK-NEXT: ret float [[TMP1]]
|
2019-12-18 05:46:42 +08:00
|
|
|
;
|
|
|
|
%fabs = call float @llvm.fabs.f32(float %y)
|
|
|
|
%r = call ninf float @llvm.copysign.f32(float %x, float %fabs)
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
|
|
|
define <3 x double> @known_positive_sign_arg_vec(<3 x double> %x, <3 x i32> %y) {
|
|
|
|
; CHECK-LABEL: @known_positive_sign_arg_vec(
|
2019-12-22 23:05:28 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%.*]] = call arcp <3 x double> @llvm.fabs.v3f64(<3 x double> [[X:%.*]])
|
|
|
|
; CHECK-NEXT: ret <3 x double> [[TMP1]]
|
2019-12-18 05:46:42 +08:00
|
|
|
;
|
|
|
|
%yf = uitofp <3 x i32> %y to <3 x double>
|
|
|
|
%r = call arcp <3 x double> @llvm.copysign.v3f64(<3 x double> %x, <3 x double> %yf)
|
|
|
|
ret <3 x double> %r
|
|
|
|
}
|
2019-12-24 06:54:31 +08:00
|
|
|
|
2020-07-14 19:42:43 +08:00
|
|
|
; maxnum(-0.0, 0.0) can return -0.0.
|
2020-07-14 04:02:10 +08:00
|
|
|
|
|
|
|
define float @not_known_positive_sign_arg(float %x, float %y) {
|
|
|
|
; CHECK-LABEL: @not_known_positive_sign_arg(
|
2020-07-14 19:42:43 +08:00
|
|
|
; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 0.000000e+00)
|
|
|
|
; CHECK-NEXT: [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[Y:%.*]], float [[MAX]])
|
|
|
|
; CHECK-NEXT: ret float [[R]]
|
2020-07-14 04:02:10 +08:00
|
|
|
;
|
|
|
|
%max = call float @llvm.maxnum.f32(float %x, float 0.0)
|
|
|
|
%r = call ninf float @llvm.copysign.f32(float %y, float %max)
|
|
|
|
ret float %r
|
|
|
|
}
|
|
|
|
|
2019-12-31 01:38:49 +08:00
|
|
|
; The magnitude operand of the 1st copysign is irrelevant.
|
2019-12-24 06:54:31 +08:00
|
|
|
; copysign(x, copysign(y, z)) --> copysign(x, z)
|
|
|
|
|
|
|
|
define float @copysign_sign_arg(float %x, float %y, float %z) {
|
|
|
|
; CHECK-LABEL: @copysign_sign_arg(
|
2019-12-31 00:04:00 +08:00
|
|
|
; CHECK-NEXT: [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[X:%.*]], float [[Z:%.*]])
|
2019-12-24 06:54:31 +08:00
|
|
|
; CHECK-NEXT: ret float [[R]]
|
|
|
|
;
|
|
|
|
%s = call reassoc float @llvm.copysign.f32(float %y, float %z)
|
|
|
|
%r = call ninf float @llvm.copysign.f32(float %x, float %s)
|
|
|
|
ret float %r
|
|
|
|
}
|