[llvm] 4023ca1 - Reapply "InstSimplify: Pass AssumptionCache to isKnownNeverInfinity"
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue May 23 00:48:38 PDT 2023
Author: Matt Arsenault
Date: 2023-05-23T08:48:25+01:00
New Revision: 4023ca12926ba857b07e4e781273e139f9287621
URL: https://github.com/llvm/llvm-project/commit/4023ca12926ba857b07e4e781273e139f9287621
DIFF: https://github.com/llvm/llvm-project/commit/4023ca12926ba857b07e4e781273e139f9287621.diff
LOG: Reapply "InstSimplify: Pass AssumptionCache to isKnownNeverInfinity"
This reverts commit 481191b0a8318e55ce467e983d78d2141e827db1.
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/pow-1.ll
llvm/test/Transforms/InstSimplify/floating-point-compare.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index e73b13f558ef3..c2c7929f69a86 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4085,16 +4085,20 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
}
// LHS == Inf
- if (Pred == FCmpInst::FCMP_OEQ && isKnownNeverInfinity(LHS, Q.DL, Q.TLI))
+ if (Pred == FCmpInst::FCMP_OEQ &&
+ isKnownNeverInfinity(LHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT))
return getFalse(RetTy);
// LHS != Inf
- if (Pred == FCmpInst::FCMP_UNE && isKnownNeverInfinity(LHS, Q.DL, Q.TLI))
+ if (Pred == FCmpInst::FCMP_UNE &&
+ isKnownNeverInfinity(LHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT))
return getTrue(RetTy);
// LHS == Inf || LHS == NaN
- if (Pred == FCmpInst::FCMP_UEQ && isKnownNeverInfOrNaN(LHS, Q.DL, Q.TLI))
+ if (Pred == FCmpInst::FCMP_UEQ &&
+ isKnownNeverInfOrNaN(LHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT))
return getFalse(RetTy);
// LHS != Inf && LHS != NaN
- if (Pred == FCmpInst::FCMP_ONE && isKnownNeverInfOrNaN(LHS, Q.DL, Q.TLI))
+ if (Pred == FCmpInst::FCMP_ONE &&
+ isKnownNeverInfOrNaN(LHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT))
return getTrue(RetTy);
}
if (C->isNegative() && !C->isNegZero()) {
diff --git a/llvm/test/Transforms/InstCombine/pow-1.ll b/llvm/test/Transforms/InstCombine/pow-1.ll
index d1f587f7ce089..16eca3d8f2d0f 100644
--- a/llvm/test/Transforms/InstCombine/pow-1.ll
+++ b/llvm/test/Transforms/InstCombine/pow-1.ll
@@ -281,9 +281,7 @@ define float @powf_libcall_half_assume_ninf(float %x) {
; ANY-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
; ANY-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X]])
; ANY-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[SQRTF]])
-; ANY-NEXT: [[ISINF:%.*]] = fcmp oeq float [[X]], 0xFFF0000000000000
-; ANY-NEXT: [[RETVAL:%.*]] = select i1 [[ISINF]], float 0x7FF0000000000000, float [[ABS]]
-; ANY-NEXT: ret float [[RETVAL]]
+; ANY-NEXT: ret float [[ABS]]
;
; VC32-LABEL: define float @powf_libcall_half_assume_ninf
; VC32-SAME: (float [[X:%.*]]) {
@@ -308,9 +306,7 @@ define float @powf_libcall_half_assume_ninf(float %x) {
; VC64-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
; VC64-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X]])
; VC64-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[SQRTF]])
-; VC64-NEXT: [[ISINF:%.*]] = fcmp oeq float [[X]], 0xFFF0000000000000
-; VC64-NEXT: [[RETVAL:%.*]] = select i1 [[ISINF]], float 0x7FF0000000000000, float [[ABS]]
-; VC64-NEXT: ret float [[RETVAL]]
+; VC64-NEXT: ret float [[ABS]]
;
; VC83-LABEL: define float @powf_libcall_half_assume_ninf
; VC83-SAME: (float [[X:%.*]]) {
@@ -319,9 +315,7 @@ define float @powf_libcall_half_assume_ninf(float %x) {
; VC83-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
; VC83-NEXT: [[SQRTF:%.*]] = call float @sqrtf(float [[X]])
; VC83-NEXT: [[ABS:%.*]] = call float @llvm.fabs.f32(float [[SQRTF]])
-; VC83-NEXT: [[ISINF:%.*]] = fcmp oeq float [[X]], 0xFFF0000000000000
-; VC83-NEXT: [[RETVAL:%.*]] = select i1 [[ISINF]], float 0x7FF0000000000000, float [[ABS]]
-; VC83-NEXT: ret float [[RETVAL]]
+; VC83-NEXT: ret float [[ABS]]
;
; NOLIB-LABEL: define float @powf_libcall_half_assume_ninf
; NOLIB-SAME: (float [[X:%.*]]) {
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
index bb95a8758d49c..c2a046509d9a2 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -1332,6 +1332,34 @@ define i1 @is_infinite(float %x) {
ret i1 %r
}
+define i1 @is_infinite_assumed_finite(float %x) {
+; CHECK-LABEL: @is_infinite_assumed_finite(
+; CHECK-NEXT: [[XABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: [[NOT_INF:%.*]] = fcmp one float [[XABS]], 0x7FF0000000000000
+; CHECK-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; CHECK-NEXT: ret i1 false
+;
+ %xabs = call float @llvm.fabs.f32(float %x)
+ %not.inf = fcmp one float %xabs, 0x7FF0000000000000
+ call void @llvm.assume(i1 %not.inf)
+ %r = fcmp oeq float %xabs, 0x7FF0000000000000
+ ret i1 %r
+}
+
+define i1 @une_inf_assumed_not_inf(float %x) {
+; CHECK-LABEL: @une_inf_assumed_not_inf(
+; CHECK-NEXT: [[XABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: [[NOT_INF:%.*]] = fcmp one float [[XABS]], 0x7FF0000000000000
+; CHECK-NEXT: call void @llvm.assume(i1 [[NOT_INF]])
+; CHECK-NEXT: ret i1 true
+;
+ %xabs = call float @llvm.fabs.f32(float %x)
+ %not.inf = fcmp one float %xabs, 0x7FF0000000000000
+ call void @llvm.assume(i1 %not.inf)
+ %r = fcmp une float %xabs, 0x7FF0000000000000
+ ret i1 %r
+}
+
define <2 x i1> @is_infinite_neg(<2 x float> %x) {
; CHECK-LABEL: @is_infinite_neg(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
@@ -1363,6 +1391,20 @@ define i1 @is_infinite_or_nan2(float %x) {
ret i1 %r
}
+define i1 @is_infinite_or_nan2_assume(float %x) {
+; CHECK-LABEL: @is_infinite_or_nan2_assume(
+; CHECK-NEXT: [[XABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: [[IS_INF_OR_NAN:%.*]] = fcmp one float [[XABS]], 0x7FF0000000000000
+; CHECK-NEXT: call void @llvm.assume(i1 [[IS_INF_OR_NAN]])
+; CHECK-NEXT: ret i1 false
+;
+ %xabs = call float @llvm.fabs.f32(float %x)
+ %is.inf.or.nan = fcmp one float %xabs, 0x7FF0000000000000
+ call void @llvm.assume(i1 %is.inf.or.nan)
+ %r = fcmp ueq float %xabs, 0x7FF0000000000000
+ ret i1 %r
+}
+
define <2 x i1> @is_infinite_neg_or_nan(<2 x float> %x) {
; CHECK-LABEL: @is_infinite_neg_or_nan(
; CHECK-NEXT: ret <2 x i1> zeroinitializer
@@ -1414,6 +1456,21 @@ define i1 @is_finite(i1 %c, double %x) {
ret i1 %r
}
+define i1 @is_finite_assume(i1 %c, double %x) {
+; CHECK-LABEL: @is_finite_assume(
+; CHECK-NEXT: [[XABS:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]])
+; CHECK-NEXT: [[IS_INF_OR_NAN:%.*]] = fcmp one double [[XABS]], 0x7FF0000000000000
+; CHECK-NEXT: call void @llvm.assume(i1 [[IS_INF_OR_NAN]])
+; CHECK-NEXT: ret i1 true
+;
+ %xabs = call double @llvm.fabs.f64(double %x)
+ %is.inf.or.nan = fcmp one double %xabs, 0x7FF0000000000000
+ call void @llvm.assume(i1 %is.inf.or.nan)
+ %s = select i1 %c, double 42.0, double %x
+ %r = fcmp one double %s, 0x7FF0000000000000
+ ret i1 %r
+}
+
define <2 x i1> @is_finite_commute(<2 x i8> %x) {
; CHECK-LABEL: @is_finite_commute(
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
More information about the llvm-commits
mailing list