[llvm] c9bbc64 - InstSimplify: Pass AssumptionCache through fcmp ord/uno simplification
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu May 18 16:48:15 PDT 2023
Author: Matt Arsenault
Date: 2023-05-19T00:48:04+01:00
New Revision: c9bbc64eeb6b500a94e82bce21d0403a5a30bf6b
URL: https://github.com/llvm/llvm-project/commit/c9bbc64eeb6b500a94e82bce21d0403a5a30bf6b
DIFF: https://github.com/llvm/llvm-project/commit/c9bbc64eeb6b500a94e82bce21d0403a5a30bf6b.diff
LOG: InstSimplify: Pass AssumptionCache through fcmp ord/uno simplification
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/floating-point-compare.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 3023b4459255..c2c7929f69a8 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4021,8 +4021,9 @@ static Value *simplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
// Fold (un)ordered comparison if we can determine there are no NaNs.
if (Pred == FCmpInst::FCMP_UNO || Pred == FCmpInst::FCMP_ORD)
- if (FMF.noNaNs() || (isKnownNeverNaN(LHS, Q.DL, Q.TLI) &&
- isKnownNeverNaN(RHS, Q.DL, Q.TLI)))
+ if (FMF.noNaNs() ||
+ (isKnownNeverNaN(LHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT) &&
+ isKnownNeverNaN(RHS, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT)))
return ConstantInt::get(RetTy, Pred == FCmpInst::FCMP_ORD);
// NaN is unordered; NaN is not ordered.
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
index 915e8afcd3ca..d004b7d4b38c 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -608,6 +608,88 @@ define i1 @maxnum_non_nan(float %x) {
ret i1 %cmp
}
+define i1 @assume_nonnan_ord(float %x) {
+; CHECK-LABEL: @assume_nonnan_ord(
+; CHECK-NEXT: [[ORD:%.*]] = fcmp ord float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[ORD]])
+; CHECK-NEXT: ret i1 true
+;
+ %ord = fcmp ord float %x, 0.0
+ call void @llvm.assume(i1 %ord)
+ %cmp = fcmp ord float %x, 1.0
+ ret i1 %cmp
+}
+
+define i1 @assume_nonnan_x2_ord(float %x, float %y) {
+; CHECK-LABEL: @assume_nonnan_x2_ord(
+; CHECK-NEXT: [[ORD_X:%.*]] = fcmp ord float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[ORD_X]])
+; CHECK-NEXT: [[ORD_Y:%.*]] = fcmp ord float [[Y:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[ORD_Y]])
+; CHECK-NEXT: ret i1 true
+;
+ %ord.x = fcmp ord float %x, 0.0
+ call void @llvm.assume(i1 %ord.x)
+ %ord.y = fcmp ord float %y, 0.0
+ call void @llvm.assume(i1 %ord.y)
+ %cmp = fcmp ord float %x, %y
+ ret i1 %cmp
+}
+
+define i1 @assume_nonan_x2_uno(float %x, float %y) {
+; CHECK-LABEL: @assume_nonan_x2_uno(
+; CHECK-NEXT: [[ORD_X:%.*]] = fcmp ord float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[ORD_X]])
+; CHECK-NEXT: [[ORD_Y:%.*]] = fcmp ord float [[Y:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[ORD_Y]])
+; CHECK-NEXT: ret i1 false
+;
+ %ord.x = fcmp ord float %x, 0.0
+ call void @llvm.assume(i1 %ord.x)
+ %ord.y = fcmp ord float %y, 0.0
+ call void @llvm.assume(i1 %ord.y)
+ %cmp = fcmp uno float %x, %y
+ ret i1 %cmp
+}
+
+define i1 @assume_nan_ord(float %x) {
+; CHECK-LABEL: @assume_nan_ord(
+; CHECK-NEXT: [[UNO:%.*]] = fcmp uno float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[UNO]])
+; CHECK-NEXT: [[CMP:%.*]] = fcmp ord float [[X]], 1.000000e+00
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %uno = fcmp uno float %x, 0.0
+ call void @llvm.assume(i1 %uno)
+ %cmp = fcmp ord float %x, 1.0
+ ret i1 %cmp
+}
+
+define i1 @assume_nonnan_uno(float %x) {
+; CHECK-LABEL: @assume_nonnan_uno(
+; CHECK-NEXT: [[ORD:%.*]] = fcmp ord float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[ORD]])
+; CHECK-NEXT: ret i1 false
+;
+ %ord = fcmp ord float %x, 0.0
+ call void @llvm.assume(i1 %ord)
+ %cmp = fcmp uno float %x, 1.0
+ ret i1 %cmp
+}
+
+define i1 @assume_nan_uno(float %x) {
+; CHECK-LABEL: @assume_nan_uno(
+; CHECK-NEXT: [[UNO:%.*]] = fcmp uno float [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: call void @llvm.assume(i1 [[UNO]])
+; CHECK-NEXT: [[CMP:%.*]] = fcmp uno float [[X]], 1.000000e+00
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %uno = fcmp uno float %x, 0.0
+ call void @llvm.assume(i1 %uno)
+ %cmp = fcmp uno float %x, 1.0
+ ret i1 %cmp
+}
+
; min(x, 0.5) == 1.0 --> false
define i1 @minnum_oeq_small_min_constant(float %x) {
More information about the llvm-commits
mailing list