-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueTracking: Recognize fcmp ole/ugt with inf as a class test #79095
Conversation
These were missed and hopefully avoids assertions when dc3faf0 is recommitted.
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-analysis Author: Matt Arsenault (arsenm) ChangesThese were missed and hopefully avoids assertions when dc3faf0 is recommitted. Full diff: https://github.com/llvm/llvm-project/pull/79095.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 34d501032098888..5f880e8694dc7a5 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4065,7 +4065,7 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
case FCmpInst::FCMP_ULE: // isnan(x) || x <= 0
return {LHS, fcNegative | fcPosZero | fcNan};
default:
- break;
+ llvm_unreachable("all compare types are handled");
}
return {nullptr, fcAllFlags};
@@ -4184,8 +4184,22 @@ llvm::fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS,
Mask = fcNone;
break;
}
+ case FCmpInst::FCMP_OLE:
+ case FCmpInst::FCMP_UGT: {
+ if (ConstRHS->isNegative()) {
+ Mask = fcNone;
+ break;
+ }
+
+ // fcmp ole x, +inf -> fcmp ord x, x
+ // fcmp ole fabs(x), +inf -> fcmp ord x, x
+ // fcmp ole x, -inf -> false
+ // fcmp ole fabs(x), -inf -> false
+ Mask = ~fcNan;
+ break;
+ }
default:
- return {nullptr, fcAllFlags};
+ llvm_unreachable("all compare types are handled");
}
} else if (ConstRHS->isSmallestNormalized() && !ConstRHS->isNegative()) {
// Match pattern that's used in __builtin_isnormal.
diff --git a/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll b/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll
index ccd01de458c3c4d..54b879ee1dea741 100644
--- a/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass-implied-by-fcmp.ll
@@ -2400,8 +2400,8 @@ define float @assume_oeq_smallest_normal_known_pos(float nofpclass(ninf nsub nno
;---------------------------------------------------------------------
define float @assume_ole_pinf(float %arg) {
-; CHECK-LABEL: define float @assume_ole_pinf(
-; CHECK-SAME: float returned [[ARG:%.*]]) #[[ATTR3]] {
+; CHECK-LABEL: define nofpclass(nan) float @assume_ole_pinf(
+; CHECK-SAME: float returned nofpclass(nan) [[ARG:%.*]]) #[[ATTR3]] {
; CHECK-NEXT: [[FCMP:%.*]] = fcmp ole float [[ARG]], 0x7FF0000000000000
; CHECK-NEXT: call void @llvm.assume(i1 noundef [[FCMP]]) #[[ATTR5]]
; CHECK-NEXT: ret float [[ARG]]
@@ -2412,10 +2412,9 @@ define float @assume_ole_pinf(float %arg) {
}
define float @assume_ole_ninf(float %arg) {
-; CHECK-LABEL: define float @assume_ole_ninf(
-; CHECK-SAME: float returned [[ARG:%.*]]) #[[ATTR3]] {
-; CHECK-NEXT: [[FCMP:%.*]] = fcmp ole float [[ARG]], 0xFFF0000000000000
-; CHECK-NEXT: call void @llvm.assume(i1 noundef [[FCMP]]) #[[ATTR5]]
+; CHECK-LABEL: define nofpclass(all) float @assume_ole_ninf(
+; CHECK-SAME: float returned nofpclass(all) [[ARG:%.*]]) #[[ATTR3]] {
+; CHECK-NEXT: call void @llvm.assume(i1 noundef false) #[[ATTR5]]
; CHECK-NEXT: ret float [[ARG]]
;
%fcmp = fcmp ole float %arg, 0xFFF0000000000000
@@ -2424,8 +2423,8 @@ define float @assume_ole_ninf(float %arg) {
}
define float @assume_ugt_pinf(float %arg) {
-; CHECK-LABEL: define float @assume_ugt_pinf(
-; CHECK-SAME: float returned [[ARG:%.*]]) #[[ATTR3]] {
+; CHECK-LABEL: define nofpclass(inf zero sub norm) float @assume_ugt_pinf(
+; CHECK-SAME: float returned nofpclass(inf zero sub norm) [[ARG:%.*]]) #[[ATTR3]] {
; CHECK-NEXT: [[FCMP:%.*]] = fcmp ugt float [[ARG]], 0x7FF0000000000000
; CHECK-NEXT: call void @llvm.assume(i1 noundef [[FCMP]]) #[[ATTR5]]
; CHECK-NEXT: ret float [[ARG]]
@@ -2438,8 +2437,7 @@ define float @assume_ugt_pinf(float %arg) {
define float @assume_ugt_ninf(float %arg) {
; CHECK-LABEL: define float @assume_ugt_ninf(
; CHECK-SAME: float returned [[ARG:%.*]]) #[[ATTR3]] {
-; CHECK-NEXT: [[FCMP:%.*]] = fcmp ugt float [[ARG]], 0xFFF0000000000000
-; CHECK-NEXT: call void @llvm.assume(i1 noundef [[FCMP]]) #[[ATTR5]]
+; CHECK-NEXT: call void @llvm.assume(i1 noundef true) #[[ATTR5]]
; CHECK-NEXT: ret float [[ARG]]
;
%fcmp = fcmp ugt float %arg, 0xFFF0000000000000
@@ -2448,8 +2446,8 @@ define float @assume_ugt_ninf(float %arg) {
}
define float @assume_fabs_ole_pinf(float %arg) {
-; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float @assume_fabs_ole_pinf(
-; CHECK-SAME: float returned nofpclass(ninf nzero nsub nnorm) [[ARG:%.*]]) #[[ATTR3]] {
+; CHECK-LABEL: define nofpclass(nan ninf nzero nsub nnorm) float @assume_fabs_ole_pinf(
+; CHECK-SAME: float returned nofpclass(nan ninf nzero nsub nnorm) [[ARG:%.*]]) #[[ATTR3]] {
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[ARG]]) #[[ATTR4]]
; CHECK-NEXT: [[FCMP:%.*]] = fcmp ole float [[FABS]], 0x7FF0000000000000
; CHECK-NEXT: call void @llvm.assume(i1 noundef [[FCMP]]) #[[ATTR5]]
@@ -2462,8 +2460,8 @@ define float @assume_fabs_ole_pinf(float %arg) {
}
define float @assume_fabs_ole_ninf(float %arg) {
-; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float @assume_fabs_ole_ninf(
-; CHECK-SAME: float returned nofpclass(ninf nzero nsub nnorm) [[ARG:%.*]]) #[[ATTR3]] {
+; CHECK-LABEL: define nofpclass(all) float @assume_fabs_ole_ninf(
+; CHECK-SAME: float returned nofpclass(all) [[ARG:%.*]]) #[[ATTR3]] {
; CHECK-NEXT: call void @llvm.assume(i1 noundef false) #[[ATTR5]]
; CHECK-NEXT: ret float [[ARG]]
;
@@ -2474,8 +2472,8 @@ define float @assume_fabs_ole_ninf(float %arg) {
}
define float @assume_fabs_ugt_pinf(float %arg) {
-; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float @assume_fabs_ugt_pinf(
-; CHECK-SAME: float returned nofpclass(ninf nzero nsub nnorm) [[ARG:%.*]]) #[[ATTR3]] {
+; CHECK-LABEL: define nofpclass(inf zero sub norm) float @assume_fabs_ugt_pinf(
+; CHECK-SAME: float returned nofpclass(inf zero sub norm) [[ARG:%.*]]) #[[ATTR3]] {
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[ARG]]) #[[ATTR4]]
; CHECK-NEXT: [[FCMP:%.*]] = fcmp ugt float [[FABS]], 0x7FF0000000000000
; CHECK-NEXT: call void @llvm.assume(i1 noundef [[FCMP]]) #[[ATTR5]]
|
llvm/lib/Analysis/ValueTracking.cpp
Outdated
case FCmpInst::FCMP_OLE: | ||
case FCmpInst::FCMP_UGT: { | ||
if (ConstRHS->isNegative()) { | ||
Mask = fcNone; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fcNegInf, surely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
These were missed and hopefully avoids assertions when dc3faf0 is recommitted.