llvm.org GIT mirror llvm / 8a87b86
[InstSimplify] enhance fcmp fold with never-nan operand This is another step towards correcting our usage of fast-math-flags when applied on an fcmp. In this case, we are checking for 'nnan' on the fcmp itself rather than the operand of the fcmp. But I'm leaving that clause in until we're more confident that we can stop relying on fcmp's FMF. By using the more general "isKnownNeverNaN()", we gain a simplification shown on the tests with 'uitofp' regardless of the FMF on the fcmp (uitofp never produces a NaN). On the tests with 'fabs', we are now relying on the FMF for the call fabs instruction in addition to the FMF on the fcmp. This is a continuation of D62979 / rL362879. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362903 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 months ago
2 changed file(s) with 6 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
34853485 return getTrue(RetTy);
34863486 break;
34873487 case FCmpInst::FCMP_ULT:
3488 // TODO: This should match 'oge'.
3489 if (FMF.noNaNs() && CannotBeOrderedLessThanZero(LHS, Q.TLI))
3488 if ((FMF.noNaNs() || isKnownNeverNaN(LHS, Q.TLI)) &&
3489 CannotBeOrderedLessThanZero(LHS, Q.TLI))
34903490 return getFalse(RetTy);
34913491 break;
34923492 case FCmpInst::FCMP_OLT:
312312
313313 define i1 @UIToFP_is_not_negative_or_nan(i32 %x) {
314314 ; CHECK-LABEL: @UIToFP_is_not_negative_or_nan(
315 ; CHECK-NEXT: [[A:%.*]] = uitofp i32 [[X:%.*]] to float
316 ; CHECK-NEXT: [[R:%.*]] = fcmp ult float [[A]], 0.000000e+00
317 ; CHECK-NEXT: ret i1 [[R]]
315 ; CHECK-NEXT: ret i1 false
318316 ;
319317 %a = uitofp i32 %x to float
320318 %r = fcmp ult float %a, 0.000000e+00
323321
324322 define <2 x i1> @UIToFP_is_not_negative_or_nan_vec(<2 x i32> %x) {
325323 ; CHECK-LABEL: @UIToFP_is_not_negative_or_nan_vec(
326 ; CHECK-NEXT: [[A:%.*]] = uitofp <2 x i32> [[X:%.*]] to <2 x float>
327 ; CHECK-NEXT: [[R:%.*]] = fcmp ult <2 x float> [[A]], zeroinitializer
328 ; CHECK-NEXT: ret <2 x i1> [[R]]
324 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
329325 ;
330326 %a = uitofp <2 x i32> %x to <2 x float>
331327 %r = fcmp ult <2 x float> %a, zeroinitializer
424420
425421 define i1 @fabs_nnan_is_not_negative(double %x) {
426422 ; CHECK-LABEL: @fabs_nnan_is_not_negative(
427 ; CHECK-NEXT: [[FABS:%.*]] = tail call nnan double @llvm.fabs.f64(double [[X:%.*]])
428 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ult double [[FABS]], 0.000000e+00
429 ; CHECK-NEXT: ret i1 [[CMP]]
423 ; CHECK-NEXT: ret i1 false
430424 ;
431425 %fabs = tail call nnan double @llvm.fabs.f64(double %x)
432426 %cmp = fcmp ult double %fabs, 0.0
435429
436430 define <2 x i1> @fabs_nnan_is_not_negative_vec(<2 x double> %x) {
437431 ; CHECK-LABEL: @fabs_nnan_is_not_negative_vec(
438 ; CHECK-NEXT: [[FABS:%.*]] = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> [[X:%.*]])
439 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ult <2 x double> [[FABS]], zeroinitializer
440 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
432 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
441433 ;
442434 %fabs = tail call nnan <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
443435 %cmp = fcmp ult <2 x double> %fabs, zeroinitializer