blob: b825ac80b6d66391695b9dc0034590b4032c4e77 [file] [log] [blame]
Sanjay Patel69632442016-03-25 20:12:25 +00001; NOTE: Assertions have been autogenerated by update_test_checks.py
Michael Ilsemanbb6f6912012-12-12 00:27:46 +00002; RUN: opt < %s -instsimplify -S | FileCheck %s
3
Benjamin Kramerf5b2a472016-02-29 11:12:23 +00004; fsub -0.0, (fsub -0.0, X) ==> X
Benjamin Kramerf5b2a472016-02-29 11:12:23 +00005define float @fsub_-0_-0_x(float %a) {
Sanjay Patel69632442016-03-25 20:12:25 +00006; CHECK-LABEL: @fsub_-0_-0_x(
7; CHECK: ret float %a
8;
Michael Ilsemanbb6f6912012-12-12 00:27:46 +00009 %t1 = fsub float -0.0, %a
10 %ret = fsub float -0.0, %t1
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000011 ret float %ret
12}
13
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000014; fsub 0.0, (fsub -0.0, X) != X
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000015define float @fsub_0_-0_x(float %a) {
Sanjay Patel69632442016-03-25 20:12:25 +000016; CHECK-LABEL: @fsub_0_-0_x(
17; CHECK: [[T1:%.*]] = fsub float 0.000000e+00, %a
18; CHECK-NEXT: [[RET:%.*]] = fsub float -0.000000e+00, [[T1]]
19; CHECK-NEXT: ret float [[RET]]
20;
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000021 %t1 = fsub float 0.0, %a
22 %ret = fsub float -0.0, %t1
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000023 ret float %ret
24}
25
26; fsub -0.0, (fsub 0.0, X) != X
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000027define float @fsub_-0_0_x(float %a) {
Sanjay Patel69632442016-03-25 20:12:25 +000028; CHECK-LABEL: @fsub_-0_0_x(
29; CHECK: [[T1:%.*]] = fsub float -0.000000e+00, %a
30; CHECK-NEXT: [[RET:%.*]] = fsub float 0.000000e+00, [[T1]]
31; CHECK-NEXT: ret float [[RET]]
32;
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000033 %t1 = fsub float -0.0, %a
34 %ret = fsub float 0.0, %t1
Benjamin Kramerf5b2a472016-02-29 11:12:23 +000035 ret float %ret
36}
37
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000038; fsub X, 0 ==> X
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000039define float @fsub_x_0(float %a) {
Sanjay Patel69632442016-03-25 20:12:25 +000040; CHECK-LABEL: @fsub_x_0(
41; CHECK: ret float %a
42;
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000043 %ret = fsub float %a, 0.0
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000044 ret float %ret
45}
46
47; fadd X, -0 ==> X
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000048define float @fadd_x_n0(float %a) {
Sanjay Patel69632442016-03-25 20:12:25 +000049; CHECK-LABEL: @fadd_x_n0(
50; CHECK: ret float %a
51;
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000052 %ret = fadd float %a, -0.0
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000053 ret float %ret
54}
55
56; fmul X, 1.0 ==> X
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000057define double @fmul_X_1(double %a) {
Sanjay Patel69632442016-03-25 20:12:25 +000058; CHECK-LABEL: @fmul_X_1(
59; CHECK: ret double %a
60;
61 %b = fmul double 1.000000e+00, %a
Michael Ilsemanbb6f6912012-12-12 00:27:46 +000062 ret double %b
63}
Sanjay Patel40eaa8d2015-02-25 18:00:15 +000064
65; We can't optimize away the fadd in this test because the input
Sanjay Patel69632442016-03-25 20:12:25 +000066; value to the function and subsequently to the fadd may be -0.0.
Sanjay Patel40eaa8d2015-02-25 18:00:15 +000067; In that one special case, the result of the fadd should be +0.0
68; rather than the first parameter of the fadd.
69
Sanjay Patel69632442016-03-25 20:12:25 +000070; Fragile test warning: We need 6 sqrt calls to trigger the bug
71; because the internal logic has a magic recursion limit of 6.
Sanjay Patel40eaa8d2015-02-25 18:00:15 +000072; This is presented without any explanation or ability to customize.
73
74declare float @sqrtf(float)
75
76define float @PR22688(float %x) {
Sanjay Patel69632442016-03-25 20:12:25 +000077; CHECK-LABEL: @PR22688(
78; CHECK: [[TMP7:%.*]] = fadd float {{%.*}}, 0.000000e+00
79; CHECK-NEXT: ret float [[TMP7]]
80;
Sanjay Patel40eaa8d2015-02-25 18:00:15 +000081 %1 = call float @sqrtf(float %x)
82 %2 = call float @sqrtf(float %1)
83 %3 = call float @sqrtf(float %2)
84 %4 = call float @sqrtf(float %3)
85 %5 = call float @sqrtf(float %4)
86 %6 = call float @sqrtf(float %5)
87 %7 = fadd float %6, 0.0
88 ret float %7
Sanjay Patel40eaa8d2015-02-25 18:00:15 +000089}
90