llvm.org GIT mirror llvm / 8a8bb45
[InstSimplify] Allow folding of fdiv X, X with just NaNs ignored Any combination of +-inf/+-inf is NaN so it's already ignored with nnan and we can skip checking for ninf. Also rephrase logic in comments a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239821 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 4 years ago
2 changed file(s) with 29 addition(s) and 49 deletion(s). Raw diff Collapse all Expand all
11251125 if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZero()))
11261126 return Op0;
11271127
1128 if (FMF.noNaNs() && FMF.noInfs()) {
1129 // X / X -> 1.0 iff NaNs and infinities are ignored.
1128 if (FMF.noNaNs()) {
1129 // X / X -> 1.0 is legal when NaNs are ignored.
11301130 if (Op0 == Op1)
11311131 return ConstantFP::get(Op0->getType(), 1.0);
11321132
11331133 // -X / X -> -1.0 and
1134 // X / -X -> -1.0 iff NaNs and infinities are ignored.
1134 // X / -X -> -1.0 are legal when NaNs are ignored.
11351135 // We can ignore signed zeros because +-0.0/+-0.0 is NaN and ignored.
11361136 if ((BinaryOperator::isFNeg(Op0, /*IgnoreZeroSign=*/true) &&
11371137 BinaryOperator::getFNegArgument(Op0) == Op1) ||
114114 ; CHECK: ret double 0
115115 }
116116
117 define float @fdiv_self(float %f) {
118 %div = fdiv nnan ninf float %f, %f
117 define float @fdiv_self(float %f) {
118 %div = fdiv nnan float %f, %f
119119 ret float %div
120120 ; CHECK-LABEL: fdiv_self
121121 ; CHECK: ret float 1.000000e+00
122122 }
123123
124 define float @fdiv_self_invalid1(float %f) {
125 %div = fdiv ninf float %f, %f
126 ret float %div
127 ; CHECK-LABEL: fdiv_self_invalid1
128 ; CHECK: %div = fdiv ninf float %f, %f
129 ; CHECK-NEXT: ret float %div
130 }
131
132 define float @fdiv_self_invalid2(float %f) {
133 %div = fdiv nnan float %f, %f
134 ret float %div
135 ; CHECK-LABEL: fdiv_self_invalid2
136 ; CHECK: %div = fdiv nnan float %f, %f
137 ; CHECK-NEXT: ret float %div
138 }
139
140 define float @fdiv_self_invalid3(float %f) {
124 define float @fdiv_self_invalid(float %f) {
141125 %div = fdiv float %f, %f
142126 ret float %div
143 ; CHECK-LABEL: fdiv_self_invalid3
127 ; CHECK-LABEL: fdiv_self_invalid
144128 ; CHECK: %div = fdiv float %f, %f
145129 ; CHECK-NEXT: ret float %div
146130 }
147131
148 define float @fdiv_neg(float %f) {
132 define float @fdiv_neg1(float %f) {
149133 %neg = fsub fast float -0.000000e+00, %f
150 %div = fdiv nnan ninf float %neg, %f
134 %div = fdiv nnan float %neg, %f
151135 ret float %div
152 ; CHECK-LABEL: fdiv_neg
136 ; CHECK-LABEL: fdiv_neg1
153137 ; CHECK: ret float -1.000000e+00
154138 }
155139
156 define float @fdiv_neg_invalid1(float %f) {
157 %neg = fsub fast float -0.000000e+00, %f
158 %div = fdiv ninf float %neg, %f
140 define float @fdiv_neg2(float %f) {
141 %neg = fsub fast float 0.000000e+00, %f
142 %div = fdiv nnan float %neg, %f
159143 ret float %div
160 ; CHECK-LABEL: fdiv_neg_invalid1
161 ; CHECK: %neg = fsub fast float -0.000000e+00, %f
162 ; CHECK-NEXT: %div = fdiv ninf float %neg, %f
163 ; CHECK-NEXT: ret float %div
144 ; CHECK-LABEL: fdiv_neg2
145 ; CHECK: ret float -1.000000e+00
164146 }
165147
166 define float @fdiv_neg_invalid2(float %f) {
167 %neg = fsub fast float -0.000000e+00, %f
168 %div = fdiv nnan float %neg, %f
169 ret float %div
170 ; CHECK-LABEL: fdiv_neg_invalid2
171 ; CHECK: %neg = fsub fast float -0.000000e+00, %f
172 ; CHECK-NEXT: %div = fdiv nnan float %neg, %f
173 ; CHECK-NEXT: ret float %div
174 }
175
176 define float @fdiv_neg_invalid3(float %f) {
148 define float @fdiv_neg_invalid(float %f) {
177149 %neg = fsub fast float -0.000000e+00, %f
178150 %div = fdiv float %neg, %f
179151 ret float %div
180 ; CHECK-LABEL: fdiv_neg_invalid3
152 ; CHECK-LABEL: fdiv_neg_invalid
181153 ; CHECK: %neg = fsub fast float -0.000000e+00, %f
182154 ; CHECK-NEXT: %div = fdiv float %neg, %f
183155 ; CHECK-NEXT: ret float %div
184156 }
185157
186 define float @fdiv_neg_swapped(float %f) {
187 %neg = fsub float 0.000000e+00, %f
188 %div = fdiv nnan ninf float %f, %neg
158 define float @fdiv_neg_swapped1(float %f) {
159 %neg = fsub float -0.000000e+00, %f
160 %div = fdiv nnan float %f, %neg
189161 ret float %div
190 ; CHECK-LABEL: fdiv_neg_swapped
162 ; CHECK-LABEL: fdiv_neg_swapped1
191163 ; CHECK: ret float -1.000000e+00
192164 }
165
166 define float @fdiv_neg_swapped2(float %f) {
167 %neg = fsub float 0.000000e+00, %f
168 %div = fdiv nnan float %f, %neg
169 ret float %div
170 ; CHECK-LABEL: fdiv_neg_swapped2
171 ; CHECK: ret float -1.000000e+00
172 }