aboutsummaryrefslogtreecommitdiffstats
path: root/test/CodeGen/X86/copysign-constant-magnitude.ll
blob: 537d6298ddf46627aff949fcf4159fa7dabee4bf (plain)
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
; RUN: llc < %s | FileCheck %s

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.10.0"

define void @test_copysign_const_magnitude_d(double %X) {
; CHECK: [[SIGNMASK:L.+]]:
; CHECK-NEXT:   .quad -9223372036854775808    ## double -0.000000e+00
; CHECK-NEXT:   .quad 0                       ## double 0.000000e+00
; CHECK: [[ZERO:L.+]]:
; CHECK-NEXT:   .space 16
; CHECK: [[ONE:L.+]]:
; CHECK-NEXT:   .quad 4607182418800017408     ## double 1.000000e+00
; CHECK-NEXT:   .quad 0                       ## double 0.000000e+00
; CHECK-LABEL: test_copysign_const_magnitude_d:

; CHECK: id
  %iX = call double @id_d(double %X)

; CHECK-NEXT: andpd [[SIGNMASK]](%rip), %xmm0
  %d0 = call double @copysign(double 0.000000e+00, double %iX)

; CHECK-NEXT: id
  %id0 = call double @id_d(double %d0)

; CHECK-NEXT: andpd [[SIGNMASK]](%rip), %xmm0
; CHECK-NEXT: orpd [[ZERO]](%rip), %xmm0
  %dn0 = call double @copysign(double -0.000000e+00, double %id0)

; CHECK-NEXT: id
  %idn0 = call double @id_d(double %dn0)

; CHECK-NEXT: andpd [[SIGNMASK]](%rip), %xmm0
; CHECK-NEXT: orpd [[ONE]](%rip), %xmm0
  %d1 = call double @copysign(double 1.000000e+00, double %idn0)

; CHECK-NEXT: id
  %id1 = call double @id_d(double %d1)

; CHECK-NEXT: andpd [[SIGNMASK]](%rip), %xmm0
; CHECK-NEXT: orpd [[ONE]](%rip), %xmm0
  %dn1 = call double @copysign(double -1.000000e+00, double %id1)

; CHECK-NEXT: id
  %idn1 = call double @id_d(double %dn1)

; CHECK: retq
  ret void
}

define void @test_copysign_const_magnitude_f(float %X) {
; CHECK: [[SIGNMASK:L.+]]:
; CHECK-NEXT:   .long	2147483648              ## float -0.000000e+00
; CHECK-NEXT:   .long	0                       ## float 0.000000e+00
; CHECK-NEXT:   .long	0                       ## float 0.000000e+00
; CHECK-NEXT:   .long	0                       ## float 0.000000e+00
; CHECK: [[ZERO:L.+]]:
; CHECK-NEXT:   .space 16
; CHECK: [[ONE:L.+]]:
; CHECK-NEXT:   .long	1065353216              ## float 1.000000e+00
; CHECK-NEXT:   .long	0                       ## float 0.000000e+00
; CHECK-NEXT:   .long	0                       ## float 0.000000e+00
; CHECK-NEXT:   .long	0                       ## float 0.000000e+00
; CHECK-LABEL: test_copysign_const_magnitude_f:

; CHECK: id
  %iX = call float @id_f(float %X)

; CHECK-NEXT: andps [[SIGNMASK]](%rip), %xmm0
  %d0 = call float @copysignf(float 0.000000e+00, float %iX)

; CHECK-NEXT: id
  %id0 = call float @id_f(float %d0)

; CHECK-NEXT: andps [[SIGNMASK]](%rip), %xmm0
; CHECK-NEXT: orps [[ZERO]](%rip), %xmm0
  %dn0 = call float @copysignf(float -0.000000e+00, float %id0)

; CHECK-NEXT: id
  %idn0 = call float @id_f(float %dn0)

; CHECK-NEXT: andps [[SIGNMASK]](%rip), %xmm0
; CHECK-NEXT: orps [[ONE]](%rip), %xmm0
  %d1 = call float @copysignf(float 1.000000e+00, float %idn0)

; CHECK-NEXT: id
  %id1 = call float @id_f(float %d1)

; CHECK-NEXT: andps [[SIGNMASK]](%rip), %xmm0
; CHECK-NEXT: orps [[ONE]](%rip), %xmm0
  %dn1 = call float @copysignf(float -1.000000e+00, float %id1)

; CHECK-NEXT: id
  %idn1 = call float @id_f(float %dn1)

; CHECK: retq
  ret void
}

declare double @copysign(double, double) nounwind readnone
declare float @copysignf(float, float) nounwind readnone

; Dummy identity functions, so we always have xmm0, and prevent optimizations.
declare double @id_d(double)
declare float @id_f(float)