[llvm] dbca874 - ValueTracking: Teach CannotBeOrderedLessThanZero about trivial ops
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 5 05:39:18 PST 2022
Author: Matt Arsenault
Date: 2022-12-05T08:39:07-05:00
New Revision: dbca874faa503f22110ed848eea019c8da90b7f4
URL: https://github.com/llvm/llvm-project/commit/dbca874faa503f22110ed848eea019c8da90b7f4
DIFF: https://github.com/llvm/llvm-project/commit/dbca874faa503f22110ed848eea019c8da90b7f4.diff
LOG: ValueTracking: Teach CannotBeOrderedLessThanZero about trivial ops
Handle canonicalize and arithmetic.fence
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index e86e9d1502d3..0e4ca6a99d43 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3653,6 +3653,9 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
switch (IID) {
default:
break;
+ case Intrinsic::canonicalize:
+ case Intrinsic::arithmetic_fence:
+ return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly, Depth + 1);
case Intrinsic::maxnum: {
Value *V0 = I->getOperand(0), *V1 = I->getOperand(1);
auto isPositiveNum = [&](Value *V) {
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
index 3529da68a140..0c0f7b6b509f 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -277,6 +277,8 @@ define float @PR22688(float %x) {
}
declare float @llvm.fabs.f32(float)
+declare float @llvm.canonicalize.f32(float)
+declare float @llvm.arithmetic.fence.f32(float)
declare <2 x float> @llvm.fabs.v2f32(<2 x float>)
declare float @llvm.sqrt.f32(float)
declare float @llvm.maxnum.f32(float, float)
@@ -913,3 +915,43 @@ define double @fsub_inf_op0(double %x) {
%r = fsub double 0x7ff0000000000000, %x
ret double %r
}
+
+define i1 @canonicalize_known_positive(float %a) {
+; CHECK-LABEL: @canonicalize_known_positive(
+; CHECK-NEXT: ret i1 true
+;
+ %fabs = call float @llvm.fabs.f32(float %a)
+ %known.positive = call float @llvm.canonicalize.f32(float %fabs)
+ %cmp = fcmp nnan oge float %known.positive, 0.0
+ ret i1 %cmp
+}
+
+define i1 @canonicalize_unknown_positive(float %unknown) {
+; CHECK-LABEL: @canonicalize_unknown_positive(
+; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oge float [[UNKNOWN:%.*]], 0.000000e+00
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = fcmp nnan oge float %unknown, 0.0
+ ret i1 %cmp
+}
+
+define i1 @arithmetic_fence_known_positive(float %a) {
+; CHECK-LABEL: @arithmetic_fence_known_positive(
+; CHECK-NEXT: ret i1 true
+;
+ %fabs = call float @llvm.fabs.f32(float %a)
+ %known.positive = call float @llvm.arithmetic.fence.f32(float %fabs)
+ %cmp = fcmp nnan oge float %known.positive, 0.0
+ ret i1 %cmp
+}
+
+define i1 @arithmetic_fence_unknown_positive(float %unknown) {
+; CHECK-LABEL: @arithmetic_fence_unknown_positive(
+; CHECK-NEXT: [[KNOWN_POSITIVE:%.*]] = call float @llvm.arithmetic.fence.f32(float [[UNKNOWN:%.*]])
+; CHECK-NEXT: [[CMP:%.*]] = fcmp nnan oge float [[KNOWN_POSITIVE]], 0.000000e+00
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %known.positive = call float @llvm.arithmetic.fence.f32(float %unknown)
+ %cmp = fcmp nnan oge float %known.positive, 0.0
+ ret i1 %cmp
+}
More information about the llvm-commits
mailing list