1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 define float @fdiv_constant_fold() {
5 ; CHECK-LABEL: @fdiv_constant_fold(
6 ; CHECK-NEXT: ret float 1.500000e+00
8 %f = fdiv float 3.0, 2.0
12 define float @frem_constant_fold() {
13 ; CHECK-LABEL: @frem_constant_fold(
14 ; CHECK-NEXT: ret float 1.000000e+00
16 %f = frem float 3.0, 2.0
20 define double @fmul_fdiv_common_operand(double %x, double %y) {
21 ; CHECK-LABEL: @fmul_fdiv_common_operand(
22 ; CHECK-NEXT: ret double [[X:%.*]]
24 %m = fmul double %x, %y
25 %d = fdiv reassoc nnan double %m, %y
29 ; Negative test - the fdiv must be reassociative and not allow NaNs.
31 define double @fmul_fdiv_common_operand_too_strict(double %x, double %y) {
32 ; CHECK-LABEL: @fmul_fdiv_common_operand_too_strict(
33 ; CHECK-NEXT: [[M:%.*]] = fmul fast double [[X:%.*]], [[Y:%.*]]
34 ; CHECK-NEXT: [[D:%.*]] = fdiv reassoc double [[M]], [[Y]]
35 ; CHECK-NEXT: ret double [[D]]
37 %m = fmul fast double %x, %y
38 %d = fdiv reassoc double %m, %y
42 ; Commute the fmul operands. Use a vector type to verify that works too.
44 define <2 x float> @fmul_fdiv_common_operand_commute_vec(<2 x float> %x, <2 x float> %y) {
45 ; CHECK-LABEL: @fmul_fdiv_common_operand_commute_vec(
46 ; CHECK-NEXT: ret <2 x float> [[X:%.*]]
48 %m = fmul <2 x float> %y, %x
49 %d = fdiv fast <2 x float> %m, %y
53 ; The constant expression version of this used to crash llvm-as.
54 define <2 x i1> @pr6096() {
55 ; CHECK-LABEL: @pr6096(
56 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
58 %fdiv = fdiv <2 x float> undef, <float 1.000000e+00, float 1.000000e+00>
59 %fcmp = fcmp ole <2 x float> %fdiv, zeroinitializer
64 ; https://alive2.llvm.org/ce/z/JxX5in
65 define float @fdiv_nnan_ninf_by_zero_f32(float %x) {
66 ; CHECK-LABEL: @fdiv_nnan_ninf_by_zero_f32(
67 ; CHECK-NEXT: ret float poison
69 %fdiv = fdiv nnan ninf float %x, 0.0
73 define float @fdiv_nnan_ninf_by_negzero_f32(float %x) {
74 ; CHECK-LABEL: @fdiv_nnan_ninf_by_negzero_f32(
75 ; CHECK-NEXT: ret float poison
77 %fdiv = fdiv nnan ninf float %x, -0.0
81 define float @fdiv_nnan_ninf_by_undef_f32(float %x) {
82 ; CHECK-LABEL: @fdiv_nnan_ninf_by_undef_f32(
83 ; CHECK-NEXT: ret float poison
85 %fdiv = fdiv nnan ninf float %x, undef
89 define float @fdiv_nnan_ninf_by_poison_f32(float %x) {
90 ; CHECK-LABEL: @fdiv_nnan_ninf_by_poison_f32(
91 ; CHECK-NEXT: ret float poison
93 %fdiv = fdiv nnan ninf float %x, poison
97 define <2 x float> @fdiv_nnan_ninf_by_zero_v2f32(<2 x float> %x) {
98 ; CHECK-LABEL: @fdiv_nnan_ninf_by_zero_v2f32(
99 ; CHECK-NEXT: ret <2 x float> poison
101 %fdiv = fdiv nnan ninf <2 x float> %x, zeroinitializer
102 ret <2 x float> %fdiv
105 define <2 x float> @fdiv_nnan_ninf_by_undef_v2f32(<2 x float> %x) {
106 ; CHECK-LABEL: @fdiv_nnan_ninf_by_undef_v2f32(
107 ; CHECK-NEXT: ret <2 x float> poison
109 %fdiv = fdiv nnan ninf <2 x float> %x, undef
110 ret <2 x float> %fdiv
113 define <2 x float> @fdiv_nnan_ninf_by_zero_undef_v2f32(<2 x float> %x) {
114 ; CHECK-LABEL: @fdiv_nnan_ninf_by_zero_undef_v2f32(
115 ; CHECK-NEXT: ret <2 x float> poison
117 %fdiv = fdiv nnan ninf <2 x float> %x, <float 0.0, float undef>
118 ret <2 x float> %fdiv
121 ; https://alive2.llvm.org/ce/z/wRV28p
122 define float @fdiv_nnan_nsz_ninf_by_zero_f32(float %x) {
123 ; CHECK-LABEL: @fdiv_nnan_nsz_ninf_by_zero_f32(
124 ; CHECK-NEXT: [[FDIV:%.*]] = fdiv nnan nsz float [[X:%.*]], 0.000000e+00
125 ; CHECK-NEXT: ret float [[FDIV]]
127 %fdiv = fdiv nnan nsz float %x, 0.0
131 define float @fdiv_nnan_nsz_ninf_by_negzero_f32(float %x) {
132 ; CHECK-LABEL: @fdiv_nnan_nsz_ninf_by_negzero_f32(
133 ; CHECK-NEXT: [[FDIV:%.*]] = fdiv nnan nsz float [[X:%.*]], -0.000000e+00
134 ; CHECK-NEXT: ret float [[FDIV]]
136 %fdiv = fdiv nnan nsz float %x, -0.0
140 define <2 x float> @fdiv_nnan_nsz_ninf_by_zero_v2f32(<2 x float> %x) {
141 ; CHECK-LABEL: @fdiv_nnan_nsz_ninf_by_zero_v2f32(
142 ; CHECK-NEXT: [[FDIV:%.*]] = fdiv nnan nsz <2 x float> [[X:%.*]], zeroinitializer
143 ; CHECK-NEXT: ret <2 x float> [[FDIV]]
145 %fdiv = fdiv nnan nsz <2 x float> %x, zeroinitializer
146 ret <2 x float> %fdiv
149 define <2 x float> @fdiv_nnan_nsz_ninf_by_negzero_v2f32(<2 x float> %x) {
150 ; CHECK-LABEL: @fdiv_nnan_nsz_ninf_by_negzero_v2f32(
151 ; CHECK-NEXT: [[FDIV:%.*]] = fdiv nnan nsz <2 x float> [[X:%.*]], <float -0.000000e+00, float -0.000000e+00>
152 ; CHECK-NEXT: ret <2 x float> [[FDIV]]
154 %fdiv = fdiv nnan nsz <2 x float> %x, <float -0.0, float -0.0>
155 ret <2 x float> %fdiv