Skip to content

Commit f95bdfc

Browse files
Rajveer100dtcxzyw
andcommitted
Apply suggestions from code review
Co-authored-by: Yingwei Zheng <[email protected]>
1 parent c06a312 commit f95bdfc

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,43 +1827,28 @@ static Value *simplifyAndOrOfFCmpsWithConstants(FCmpInst *Cmp0, FCmpInst *Cmp1,
18271827
!match(Cmp1->getOperand(1), m_APFloat(C1)))
18281828
return nullptr;
18291829

1830-
auto Range0 = ConstantFPRange::makeExactFCmpRegion(Cmp0->getPredicate(), *C0);
1831-
auto Range1 = ConstantFPRange::makeExactFCmpRegion(Cmp1->getPredicate(), *C1);
1830+
auto Range0 = ConstantFPRange::makeExactFCmpRegion(
1831+
IsAnd ? Cmp0->getPredicate() : Cmp0->getInversePredicate(), *C0);
1832+
auto Range1 = ConstantFPRange::makeExactFCmpRegion(
1833+
IsAnd ? Cmp1->getPredicate() : Cmp1->getInversePredicate(), *C1);
18321834

18331835
if (!Range0 || !Range1)
18341836
return nullptr;
18351837

18361838
// For and-of-compares, check if the intersection is empty:
18371839
// (fcmp X, C0) && (fcmp X, C1) --> empty set --> false
1838-
if (IsAnd && (*Range0).intersectWith(*Range1).isEmptySet())
1839-
return getFalse(Cmp0->getType());
1840-
1841-
// For or-of-compares, check if the union is full:
1842-
// (fcmp X, C0) || (fcmp X, C1) --> full set --> true
1843-
//
1844-
// TODO: `unionWith` is not precise at the moment, so
1845-
// we can invert the predicate and check:
1846-
// inv(fcmp X, C0) && inv(fcmp X, C1) --> empty set --> false
1847-
if (!IsAnd) {
1848-
auto Range0Inv = ConstantFPRange::makeExactFCmpRegion(
1849-
FCmpInst::getInversePredicate(Cmp0->getPredicate()), *C0);
1850-
auto Range1Inv = ConstantFPRange::makeExactFCmpRegion(
1851-
FCmpInst::getInversePredicate(Cmp1->getPredicate()), *C1);
1852-
if (Range0Inv && Range1Inv) {
1853-
if ((*Range0Inv).intersectWith(*Range1Inv).isEmptySet())
1854-
return getFalse(Cmp0->getType());
1855-
}
1856-
}
1840+
if (Range0->intersectWith(*Range1).isEmptySet())
1841+
return ConstantInt::getBool(Cmp0->getType(), !IsAnd);
18571842

18581843
// Is one range a superset of the other?
18591844
// If this is and-of-compares, take the smaller set:
18601845
// (fcmp ogt X, 4) && (fcmp ogt X, 42) --> fcmp ogt X, 42
18611846
// If this is or-of-compares, take the larger set:
18621847
// (fcmp ogt X, 4) || (fcmp ogt X, 42) --> fcmp ogt X, 4
1863-
if ((*Range0).contains(*Range1))
1864-
return IsAnd ? Cmp1 : Cmp0;
1865-
if ((*Range1).contains(*Range0))
1866-
return IsAnd ? Cmp0 : Cmp1;
1848+
if (Range0->contains(*Range1))
1849+
return Cmp1;
1850+
if (Range1->contains(*Range0))
1851+
return Cmp0;
18671852

18681853
return nullptr;
18691854
}

llvm/test/Transforms/InstCombine/create-class-from-logic-fcmp.ll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,7 @@ define i1 @not_issubnormal_or_inf(half %x) {
567567

568568
define i1 @issubnormal_uge_or_inf(half %x) {
569569
; CHECK-LABEL: @issubnormal_uge_or_inf(
570-
; CHECK-NEXT: [[FABS:%.*]] = call half @llvm.fabs.f16(half [[X:%.*]])
571-
; CHECK-NEXT: [[CLASS:%.*]] = fcmp uge half [[FABS]], 0xH0400
570+
; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f16(half [[X:%.*]], i32 783)
572571
; CHECK-NEXT: ret i1 [[CLASS]]
573572
;
574573
%fabs = call half @llvm.fabs.f16(half %x)
@@ -610,8 +609,10 @@ define i1 @issubnormal_or_inf_neg_smallest_normal(half %x) {
610609
define i1 @fneg_fabs_olt_neg_smallest_normal_or_inf(half %x) {
611610
; CHECK-LABEL: @fneg_fabs_olt_neg_smallest_normal_or_inf(
612611
; CHECK-NEXT: [[FABS:%.*]] = call half @llvm.fabs.f16(half [[X:%.*]])
612+
; CHECK-NEXT: [[CMPINF:%.*]] = fcmp oeq half [[FABS]], 0xH7C00
613613
; CHECK-NEXT: [[CMP_SMALLEST_NORMAL:%.*]] = fcmp ogt half [[FABS]], 0xH0400
614-
; CHECK-NEXT: ret i1 [[CMP_SMALLEST_NORMAL]]
614+
; CHECK-NEXT: [[CLASS:%.*]] = or i1 [[CMP_SMALLEST_NORMAL]], [[CMPINF]]
615+
; CHECK-NEXT: ret i1 [[CLASS]]
615616
;
616617
%fabs = call half @llvm.fabs.f16(half %x)
617618
%cmpinf = fcmp oeq half %fabs, 0xH7C00
@@ -673,8 +674,7 @@ define i1 @not_zero_and_subnormal(half %x) {
673674

674675
define i1 @fcmp_fabs_uge_inf_or_fabs_uge_smallest_norm(half %x) {
675676
; CHECK-LABEL: @fcmp_fabs_uge_inf_or_fabs_uge_smallest_norm(
676-
; CHECK-NEXT: [[FABS:%.*]] = call half @llvm.fabs.f16(half [[X:%.*]])
677-
; CHECK-NEXT: [[OR:%.*]] = fcmp uge half [[FABS]], 0xH0400
677+
; CHECK-NEXT: [[OR:%.*]] = call i1 @llvm.is.fpclass.f16(half [[X:%.*]], i32 783)
678678
; CHECK-NEXT: ret i1 [[OR]]
679679
;
680680
%fabs = call half @llvm.fabs.f16(half %x)
@@ -868,8 +868,7 @@ define i1 @une_or_oge_smallest_normal(half %x) #0 {
868868
; -> normal | inf
869869
define i1 @isnormalinf_or_inf(half %x) #0 {
870870
; CHECK-LABEL: @isnormalinf_or_inf(
871-
; CHECK-NEXT: [[FABS:%.*]] = call half @llvm.fabs.f16(half [[X:%.*]])
872-
; CHECK-NEXT: [[OR:%.*]] = fcmp oge half [[FABS]], 0xH0400
871+
; CHECK-NEXT: [[OR:%.*]] = call i1 @llvm.is.fpclass.f16(half [[X:%.*]], i32 780)
873872
; CHECK-NEXT: ret i1 [[OR]]
874873
;
875874
%fabs = call half @llvm.fabs.f16(half %x)
@@ -1409,7 +1408,7 @@ define i1 @oeq_neginfinity_or_oeq_smallest_normal(half %x) #0 {
14091408
; -> ninf | fcZero | fcSubnormal
14101409
define i1 @oeq_neginfinity_or_olt_smallest_normal(half %x) #0 {
14111410
; CHECK-LABEL: @oeq_neginfinity_or_olt_smallest_normal(
1412-
; CHECK-NEXT: [[CLASS:%.*]] = fcmp olt half [[X:%.*]], 0xH0400
1411+
; CHECK-NEXT: [[CLASS:%.*]] = call i1 @llvm.is.fpclass.f16(half [[X:%.*]], i32 252)
14131412
; CHECK-NEXT: ret i1 [[CLASS]]
14141413
;
14151414
%oeq.neg.infinity = fcmp oeq half %x, 0xHFC00

llvm/test/Transforms/InstCombine/redundant-fcmp.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ define i1 @or_fcmp_redundant_or4(double %v0) {
4545
ret i1 %v3
4646
}
4747

48-
define i1 @or_fcmp_redundant_or_5(double %v0) {
49-
; CHECK-LABEL: @or_fcmp_redundant_or_5(
48+
define i1 @or_fcmp_redundant_or_neg1(double %v0) {
49+
; CHECK-LABEL: @or_fcmp_redundant_or_neg1(
5050
; CHECK-NEXT: [[V1:%.*]] = fcmp olt double [[V0:%.*]], 1.000000e-02
5151
; CHECK-NEXT: [[V2:%.*]] = fcmp ogt double [[V0]], 1.990000e+00
5252
; CHECK-NEXT: [[V3:%.*]] = or i1 [[V1]], [[V2]]
@@ -58,8 +58,8 @@ define i1 @or_fcmp_redundant_or_5(double %v0) {
5858
ret i1 %v3
5959
}
6060

61-
define i1 @or_fcmp_redundant_or_6(double %v0) {
62-
; CHECK-LABEL: @or_fcmp_redundant_or_6(
61+
define i1 @or_fcmp_redundant_or_neg2(double %v0) {
62+
; CHECK-LABEL: @or_fcmp_redundant_or_neg2(
6363
; CHECK-NEXT: [[V1:%.*]] = fcmp ogt double [[V0:%.*]], 1.000000e-02
6464
; CHECK-NEXT: [[V2:%.*]] = fcmp olt double [[V0]], 1.990000e+00
6565
; CHECK-NEXT: [[V3:%.*]] = or i1 [[V1]], [[V2]]
@@ -115,8 +115,8 @@ define i1 @or_fcmp_redundant_and4(double %v0) {
115115
ret i1 %v3
116116
}
117117

118-
define i1 @or_fcmp_redundant_and_5(double %v0) {
119-
; CHECK-LABEL: @or_fcmp_redundant_and_5(
118+
define i1 @or_fcmp_redundant_and_neg1(double %v0) {
119+
; CHECK-LABEL: @or_fcmp_redundant_and_neg1(
120120
; CHECK-NEXT: ret i1 false
121121
;
122122
%v1 = fcmp olt double %v0, 1.000000e-02
@@ -125,8 +125,8 @@ define i1 @or_fcmp_redundant_and_5(double %v0) {
125125
ret i1 %v3
126126
}
127127

128-
define i1 @or_fcmp_redundant_and_6(double %v0) {
129-
; CHECK-LABEL: @or_fcmp_redundant_and_6(
128+
define i1 @or_fcmp_redundant_and_neg2(double %v0) {
129+
; CHECK-LABEL: @or_fcmp_redundant_and_neg2(
130130
; CHECK-NEXT: [[V1:%.*]] = fcmp ogt double [[V0:%.*]], 1.000000e-02
131131
; CHECK-NEXT: [[V2:%.*]] = fcmp olt double [[V0]], 1.990000e+00
132132
; CHECK-NEXT: [[V3:%.*]] = and i1 [[V1]], [[V2]]

0 commit comments

Comments
 (0)