• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -instcombine < %s | FileCheck %s
3
4declare float @llvm.fabs.f32(float)
5declare float @llvm.copysign.f32(float, float)
6declare float @llvm.maxnum.f32(float, float)
7declare <3 x double> @llvm.copysign.v3f64(<3 x double>, <3 x double>)
8
9define 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]]
13;
14  %r = call arcp float @llvm.copysign.f32(float %x, float 0.0)
15  ret float %r
16}
17
18define <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]]
22;
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>)
24  ret <3 x double> %r
25}
26
27define 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]]
32;
33  %r = call nnan float @llvm.copysign.f32(float %x, float -0.0)
34  ret float %r
35}
36
37define <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]]
42;
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>)
44  ret <3 x double> %r
45}
46
47define 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]]
51;
52  %fabs = call float @llvm.fabs.f32(float %y)
53  %r = call ninf float @llvm.copysign.f32(float %x, float %fabs)
54  ret float %r
55}
56
57define <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]]
61;
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)
64  ret <3 x double> %r
65}
66
67; maxnum(-0.0, 0.0) can return -0.0.
68
69define 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]]
74;
75  %max = call float @llvm.maxnum.f32(float %x, float 0.0)
76  %r = call ninf float @llvm.copysign.f32(float %y, float %max)
77  ret float %r
78}
79
80; The magnitude operand of the 1st copysign is irrelevant.
81; copysign(x, copysign(y, z)) --> copysign(x, z)
82
83define 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]]
87;
88  %s = call reassoc float @llvm.copysign.f32(float %y, float %z)
89  %r = call ninf float @llvm.copysign.f32(float %x, float %s)
90  ret float %r
91}
92
93define 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]]
97;
98  %n = fneg float %x
99  %r = call float @llvm.copysign.f32(float %n, float %y)
100  ret float %r
101}
102
103define 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]]
107;
108  %a = call float @llvm.fabs.f32(float %x)
109  %r = call float @llvm.copysign.f32(float %a, float %y)
110  ret float %r
111}
112