Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 5406c80

Browse files
committed
[InstSimplify] fold 'fcmp nnan ult X, 0.0' when X is not negative
This is the inverted case for the transform added with D53874 / rL345725. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345728 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 123a45f commit 5406c80

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3620,8 +3620,11 @@ static Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
36203620
if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
36213621
return getTrue(RetTy);
36223622
break;
3623+
case FCmpInst::FCMP_ULT:
3624+
if (FMF.noNaNs() && CannotBeOrderedLessThanZero(LHS, Q.TLI))
3625+
return getFalse(RetTy);
3626+
break;
36233627
case FCmpInst::FCMP_OLT:
3624-
// X < 0
36253628
if (CannotBeOrderedLessThanZero(LHS, Q.TLI))
36263629
return getFalse(RetTy);
36273630
break;

test/Transforms/InstSimplify/floating-point-compare.ll

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ define <2 x i1> @UIToFP_is_not_negative_vec(<2 x i32> %x) {
290290

291291
define i1 @UIToFP_nnan_is_not_negative(i32 %x) {
292292
; CHECK-LABEL: @UIToFP_nnan_is_not_negative(
293-
; CHECK-NEXT: [[A:%.*]] = uitofp i32 [[X:%.*]] to float
294-
; CHECK-NEXT: [[R:%.*]] = fcmp nnan ult float [[A]], 0.000000e+00
295-
; CHECK-NEXT: ret i1 [[R]]
293+
; CHECK-NEXT: ret i1 false
296294
;
297295
%a = uitofp i32 %x to float
298296
%r = fcmp nnan ult float %a, 0.000000e+00
@@ -301,9 +299,7 @@ define i1 @UIToFP_nnan_is_not_negative(i32 %x) {
301299

302300
define <2 x i1> @UIToFP_nnan_is_not_negative_vec(<2 x i32> %x) {
303301
; CHECK-LABEL: @UIToFP_nnan_is_not_negative_vec(
304-
; CHECK-NEXT: [[A:%.*]] = uitofp <2 x i32> [[X:%.*]] to <2 x float>
305-
; CHECK-NEXT: [[R:%.*]] = fcmp nnan ult <2 x float> [[A]], zeroinitializer
306-
; CHECK-NEXT: ret <2 x i1> [[R]]
302+
; CHECK-NEXT: ret <2 x i1> zeroinitializer
307303
;
308304
%a = uitofp <2 x i32> %x to <2 x float>
309305
%r = fcmp nnan ult <2 x float> %a, zeroinitializer
@@ -366,9 +362,7 @@ define <2 x i1> @fabs_is_not_negative_vec(<2 x double> %x) {
366362

367363
define i1 @fabs_nnan_is_not_negative(double %x) {
368364
; CHECK-LABEL: @fabs_nnan_is_not_negative(
369-
; CHECK-NEXT: [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[X:%.*]])
370-
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ult double [[FABS]], 0.000000e+00
371-
; CHECK-NEXT: ret i1 [[CMP]]
365+
; CHECK-NEXT: ret i1 false
372366
;
373367
%fabs = tail call double @llvm.fabs.f64(double %x)
374368
%cmp = fcmp nnan ult double %fabs, 0.0
@@ -377,9 +371,7 @@ define i1 @fabs_nnan_is_not_negative(double %x) {
377371

378372
define <2 x i1> @fabs_nnan_is_not_negative_vec(<2 x double> %x) {
379373
; CHECK-LABEL: @fabs_nnan_is_not_negative_vec(
380-
; CHECK-NEXT: [[FABS:%.*]] = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> [[X:%.*]])
381-
; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan ult <2 x double> [[FABS]], zeroinitializer
382-
; CHECK-NEXT: ret <2 x i1> [[CMP]]
374+
; CHECK-NEXT: ret <2 x i1> zeroinitializer
383375
;
384376
%fabs = tail call <2 x double> @llvm.fabs.v2f64(<2 x double> %x)
385377
%cmp = fcmp nnan ult <2 x double> %fabs, zeroinitializer

0 commit comments

Comments
 (0)