1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instcombine < %s | FileCheck %s
4 declare float @llvm.fabs.f32(float)
5 declare float @llvm.copysign.f32(float, float)
6 declare float @llvm.maxnum.f32(float, float)
7 declare <3 x double> @llvm.copysign.v3f64(<3 x double>, <3 x double>)
9 define float @positive_sign_arg(float %x) {
10 ; CHECK-LABEL: @positive_sign_arg(
11 ; CHECK-NEXT: [[TMP1:%.*]] = call arcp float @llvm.fabs.f32(float [[X:%.*]])
12 ; CHECK-NEXT: ret float [[TMP1]]
14 %r = call arcp float @llvm.copysign.f32(float %x, float 0.0)
18 define <3 x double> @positive_sign_arg_vec_splat(<3 x double> %x) {
19 ; CHECK-LABEL: @positive_sign_arg_vec_splat(
20 ; CHECK-NEXT: [[TMP1:%.*]] = call ninf <3 x double> @llvm.fabs.v3f64(<3 x double> [[X:%.*]])
21 ; CHECK-NEXT: ret <3 x double> [[TMP1]]
23 %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>)
27 define float @negative_sign_arg(float %x) {
28 ; CHECK-LABEL: @negative_sign_arg(
29 ; CHECK-NEXT: [[TMP1:%.*]] = call nnan float @llvm.fabs.f32(float [[X:%.*]])
30 ; CHECK-NEXT: [[TMP2:%.*]] = fneg nnan float [[TMP1]]
31 ; CHECK-NEXT: ret float [[TMP2]]
33 %r = call nnan float @llvm.copysign.f32(float %x, float -0.0)
37 define <3 x double> @negative_sign_arg_vec_splat(<3 x double> %x) {
38 ; CHECK-LABEL: @negative_sign_arg_vec_splat(
39 ; CHECK-NEXT: [[TMP1:%.*]] = call fast <3 x double> @llvm.fabs.v3f64(<3 x double> [[X:%.*]])
40 ; CHECK-NEXT: [[TMP2:%.*]] = fneg fast <3 x double> [[TMP1]]
41 ; CHECK-NEXT: ret <3 x double> [[TMP2]]
43 %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>)
47 define float @known_positive_sign_arg(float %x, float %y) {
48 ; CHECK-LABEL: @known_positive_sign_arg(
49 ; CHECK-NEXT: [[TMP1:%.*]] = call ninf float @llvm.fabs.f32(float [[X:%.*]])
50 ; CHECK-NEXT: ret float [[TMP1]]
52 %fabs = call float @llvm.fabs.f32(float %y)
53 %r = call ninf float @llvm.copysign.f32(float %x, float %fabs)
57 define <3 x double> @known_positive_sign_arg_vec(<3 x double> %x, <3 x i32> %y) {
58 ; CHECK-LABEL: @known_positive_sign_arg_vec(
59 ; CHECK-NEXT: [[TMP1:%.*]] = call arcp <3 x double> @llvm.fabs.v3f64(<3 x double> [[X:%.*]])
60 ; CHECK-NEXT: ret <3 x double> [[TMP1]]
62 %yf = uitofp <3 x i32> %y to <3 x double>
63 %r = call arcp <3 x double> @llvm.copysign.v3f64(<3 x double> %x, <3 x double> %yf)
67 ; maxnum(-0.0, 0.0) can return -0.0.
69 define float @not_known_positive_sign_arg(float %x, float %y) {
70 ; CHECK-LABEL: @not_known_positive_sign_arg(
71 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 0.000000e+00)
72 ; CHECK-NEXT: [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[Y:%.*]], float [[MAX]])
73 ; CHECK-NEXT: ret float [[R]]
75 %max = call float @llvm.maxnum.f32(float %x, float 0.0)
76 %r = call ninf float @llvm.copysign.f32(float %y, float %max)
80 ; The magnitude operand of the 1st copysign is irrelevant.
81 ; copysign(x, copysign(y, z)) --> copysign(x, z)
83 define float @copysign_sign_arg(float %x, float %y, float %z) {
84 ; CHECK-LABEL: @copysign_sign_arg(
85 ; CHECK-NEXT: [[R:%.*]] = call ninf float @llvm.copysign.f32(float [[X:%.*]], float [[Z:%.*]])
86 ; CHECK-NEXT: ret float [[R]]
88 %s = call reassoc float @llvm.copysign.f32(float %y, float %z)
89 %r = call ninf float @llvm.copysign.f32(float %x, float %s)
93 define float @fneg_mag(float %x, float %y) {
94 ; CHECK-LABEL: @fneg_mag(
95 ; CHECK-NEXT: [[R:%.*]] = call float @llvm.copysign.f32(float [[X:%.*]], float [[Y:%.*]])
96 ; CHECK-NEXT: ret float [[R]]
99 %r = call float @llvm.copysign.f32(float %n, float %y)
103 define float @fabs_mag(float %x, float %y) {
104 ; CHECK-LABEL: @fabs_mag(
105 ; CHECK-NEXT: [[R:%.*]] = call float @llvm.copysign.f32(float [[X:%.*]], float [[Y:%.*]])
106 ; CHECK-NEXT: ret float [[R]]
108 %a = call float @llvm.fabs.f32(float %x)
109 %r = call float @llvm.copysign.f32(float %a, float %y)