[llvm] r360206 - [ValueTracking] add logic for known-never-nan with minnum/maxnum
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue May 7 15:58:31 PDT 2019
Author: spatel
Date: Tue May 7 15:58:31 2019
New Revision: 360206
URL: http://llvm.org/viewvc/llvm-project?rev=360206&view=rev
Log:
[ValueTracking] add logic for known-never-nan with minnum/maxnum
>From the LangRef: "Returns NaN only if both operands are NaN."
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=360206&r1=360205&r2=360206&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue May 7 15:58:31 2019
@@ -3136,6 +3136,11 @@ bool llvm::isKnownNeverNaN(const Value *
case Intrinsic::sqrt:
return isKnownNeverNaN(II->getArgOperand(0), TLI, Depth + 1) &&
CannotBeOrderedLessThanZero(II->getArgOperand(0), TLI);
+ case Intrinsic::minnum:
+ case Intrinsic::maxnum:
+ // If either operand is not NaN, the result is not NaN.
+ return isKnownNeverNaN(II->getArgOperand(0), TLI, Depth + 1) ||
+ isKnownNeverNaN(II->getArgOperand(1), TLI, Depth + 1);
default:
return false;
}
Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll?rev=360206&r1=360205&r2=360206&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-compare.ll Tue May 7 15:58:31 2019
@@ -487,9 +487,7 @@ define i1 @orderedLessZeroMaximum(float,
define i1 @minnum_non_nan(float %x) {
; CHECK-LABEL: @minnum_non_nan(
-; CHECK-NEXT: [[MIN:%.*]] = call float @llvm.minnum.f32(float 5.000000e-01, float [[X:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = fcmp ord float [[MIN]], 1.000000e+00
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%min = call float @llvm.minnum.f32(float 0.5, float %x)
%cmp = fcmp ord float %min, 1.0
@@ -498,9 +496,7 @@ define i1 @minnum_non_nan(float %x) {
define i1 @maxnum_non_nan(float %x) {
; CHECK-LABEL: @maxnum_non_nan(
-; CHECK-NEXT: [[MIN:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 4.200000e+01)
-; CHECK-NEXT: [[CMP:%.*]] = fcmp uno float [[MIN]], 1.200000e+01
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
%min = call float @llvm.maxnum.f32(float %x, float 42.0)
%cmp = fcmp uno float %min, 12.0
More information about the llvm-commits
mailing list