blob: 1c29884753a4f4ba8283825397057b581b161bca [file] [log] [blame]
Michael Ilsemanbb6f6912012-12-12 00:27:46 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
2
Benjamin Kramerf5b2a472016-02-29 11:12:23 +00003; fsub -0.0, (fsub -0.0, X) ==> X
4; CHECK-LABEL: @fsub_-0_-0_x(
5define float @fsub_-0_-0_x(float %a) {
Michael Ilsemanbb6f6912012-12-12 00:27:46 +00006 %t1 = fsub float -0.0, %a
7 %ret = fsub float -0.0, %t1
8
9; CHECK: ret float %a
10 ret float %ret
11}
12
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000013; fsub 0.0, (fsub -0.0, X) != X
14; CHECK-LABEL: @fsub_0_-0_x(
15define float @fsub_0_-0_x(float %a) {
16 %t1 = fsub float 0.0, %a
17 %ret = fsub float -0.0, %t1
18
19; CHECK-NOT: ret float %a
20 ret float %ret
21}
22
23; fsub -0.0, (fsub 0.0, X) != X
24; CHECK-LABEL: @fsub_-0_0_x(
25define float @fsub_-0_0_x(float %a) {
26 %t1 = fsub float -0.0, %a
27 %ret = fsub float 0.0, %t1
28
29; CHECK-NOT: ret float %a
30 ret float %ret
31}
32
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000033; fsub X, 0 ==> X
Stephen Linc1c7a132013-07-14 01:42:54 +000034; CHECK-LABEL: @fsub_x_0(
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000035define float @fsub_x_0(float %a) {
36 %ret = fsub float %a, 0.0
Benjamin Kramerb50682e2013-04-11 12:41:41 +000037; CHECK: ret float %a
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000038 ret float %ret
39}
40
41; fadd X, -0 ==> X
Stephen Linc1c7a132013-07-14 01:42:54 +000042; CHECK-LABEL: @fadd_x_n0(
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000043define float @fadd_x_n0(float %a) {
44 %ret = fadd float %a, -0.0
Benjamin Kramerb50682e2013-04-11 12:41:41 +000045; CHECK: ret float %a
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000046 ret float %ret
47}
48
49; fmul X, 1.0 ==> X
Stephen Linc1c7a132013-07-14 01:42:54 +000050; CHECK-LABEL: @fmul_X_1(
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000051define double @fmul_X_1(double %a) {
52 %b = fmul double 1.000000e+00, %a ; <double> [#uses=1]
53 ; CHECK: ret double %a
54 ret double %b
55}
Sanjay Patel40eaa8d2015-02-25 18:00:15 +000056
57; We can't optimize away the fadd in this test because the input
58; value to the function and subsequently to the fadd may be -0.0.
59; In that one special case, the result of the fadd should be +0.0
60; rather than the first parameter of the fadd.
61
62; Fragile test warning: We need 6 sqrt calls to trigger the bug
63; because the internal logic has a magic recursion limit of 6.
64; This is presented without any explanation or ability to customize.
65
66declare float @sqrtf(float)
67
68define float @PR22688(float %x) {
69 %1 = call float @sqrtf(float %x)
70 %2 = call float @sqrtf(float %1)
71 %3 = call float @sqrtf(float %2)
72 %4 = call float @sqrtf(float %3)
73 %5 = call float @sqrtf(float %4)
74 %6 = call float @sqrtf(float %5)
75 %7 = fadd float %6, 0.0
76 ret float %7
77
78; CHECK-LABEL: @PR22688(
79; CHECK: fadd float %6, 0.0
80}
81