llvm.org GIT mirror llvm / 1ef057d
[InstSimplify] fold 'fcmp nnan oge X, 0.0' when X is not negative This re-raises some of the open questions about how to apply and use fast-math-flags in IR from PR38086: https://bugs.llvm.org/show_bug.cgi?id=38086 ...but given the current implementation (no FMF on casts), this is likely the only way to predicate the transform. This is part of solving PR39475: https://bugs.llvm.org/show_bug.cgi?id=39475 Differential Revision: https://reviews.llvm.org/D53874 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345725 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 11 months ago
3 changed file(s) with 11 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
36113611 }
36123612 if (C->isZero()) {
36133613 switch (Pred) {
3614 case FCmpInst::FCMP_OGE:
3615 if (FMF.noNaNs() && CannotBeOrderedLessThanZero(LHS, Q.TLI))
3616 return getTrue(RetTy);
3617 break;
36143618 case FCmpInst::FCMP_UGE:
36153619 if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
36163620 return getTrue(RetTy);
54325432 break;
54335433 // fabs(x) < 0 --> false
54345434 case FCmpInst::FCMP_OLT:
5435 llvm_unreachable("handled by SimplifyFCmpInst");
5436 // fabs(x) > 0 --> x != 0
5435 llvm_unreachable("fcmp should have simplified");
5436 // fabs(x) > 0 --> x != 0
54375437 case FCmpInst::FCMP_OGT:
54385438 return new FCmpInst(FCmpInst::FCMP_ONE, CI->getArgOperand(0), RHSC);
54395439 // fabs(x) <= 0 --> x == 0
54415441 return new FCmpInst(FCmpInst::FCMP_OEQ, CI->getArgOperand(0), RHSC);
54425442 // fabs(x) >= 0 --> !isnan(x)
54435443 case FCmpInst::FCMP_OGE:
5444 assert(!I.hasNoNaNs() && "fcmp should have simplified");
54445445 return new FCmpInst(FCmpInst::FCMP_ORD, CI->getArgOperand(0), RHSC);
54455446 // fabs(x) == 0 --> x == 0
54465447 // fabs(x) != 0 --> x != 0
253253
254254 define i1 @UIToFP_nnan_is_positive_or_zero(i32 %x) {
255255 ; CHECK-LABEL: @UIToFP_nnan_is_positive_or_zero(
256 ; CHECK-NEXT: [[A:%.*]] = uitofp i32 [[X:%.*]] to float
257 ; CHECK-NEXT: [[R:%.*]] = fcmp nnan oge float [[A]], 0.000000e+00
258 ; CHECK-NEXT: ret i1 [[R]]
256 ; CHECK-NEXT: ret i1 true
259257 ;
260258 %a = uitofp i32 %x to float
261259 %r = fcmp nnan oge float %a, 0.000000e+00
264262
265263 define <2 x i1> @UIToFP_nnan_is_positive_or_zero_vec(<2 x i32> %x) {
266264 ; CHECK-LABEL: @UIToFP_nnan_is_positive_or_zero_vec(
267 ; CHECK-NEXT: [[A:%.*]] = uitofp <2 x i32> [[X:%.*]] to <2 x float>
268 ; CHECK-NEXT: [[R:%.*]] = fcmp nnan oge <2 x float> [[A]], zeroinitializer
269 ; CHECK-NEXT: ret <2 x i1> [[R]]
265 ; CHECK-NEXT: ret <2 x i1>
270266 ;
271267 %a = uitofp <2 x i32> %x to <2 x float>
272268 %r = fcmp nnan oge <2 x float> %a, zeroinitializer
333329
334330 define i1 @fabs_nnan_is_positive_or_zero(double %x) {
335331 ; CHECK-LABEL: @fabs_nnan_is_positive_or_zero(
336 ; CHECK-NEXT: [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]])
337 ; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oge double [[FABS]], 0.000000e+00
338 ; CHECK-NEXT: ret i1 [[CMP]]
332 ; CHECK-NEXT: ret i1 true
339333 ;
340334 %fabs = tail call double @llvm.fabs.f64(double %x)
341335 %cmp = fcmp nnan oge double %fabs, 0.0
344338
345339 define <2 x i1> @fabs_nnan_is_positive_or_zero_vec(<2 x double> %x) {
346340 ; CHECK-LABEL: @fabs_nnan_is_positive_or_zero_vec(
347 ; CHECK-NEXT: [[FABS:%.*]] = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> [[X:%.*]])
348 ; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oge <2 x double> [[FABS]], zeroinitializer
349 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
341 ; CHECK-NEXT: ret <2 x i1>
350342 ;
351343 %fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
352344 %cmp = fcmp nnan oge <2 x double> %fabs, zeroinitializer