[llvm] r337127 - [InstSimplify] fold minnum/maxnum with NaN arg
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 15 07:52:16 PDT 2018
Author: spatel
Date: Sun Jul 15 07:52:16 2018
New Revision: 337127
URL: http://llvm.org/viewvc/llvm-project?rev=337127&view=rev
Log:
[InstSimplify] fold minnum/maxnum with NaN arg
This fold is repeated/misplaced in instcombine, but I'm
not sure if it's safe to remove that yet because some
other folds appear to be asserting that the transform
has occurred within instcombine itself.
This isn't the best fix for PR37776, but it probably
hides the bug with the given code example:
https://bugs.llvm.org/show_bug.cgi?id=37776
We have another test to demonstrate the more general bug.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=337127&r1=337126&r2=337127&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Jul 15 07:52:16 2018
@@ -4725,6 +4725,14 @@ static Value *SimplifyIntrinsic(Function
return LHS;
}
return nullptr;
+ case Intrinsic::maxnum:
+ case Intrinsic::minnum:
+ // If one argument is NaN, return the other argument.
+ if (match(LHS, m_NaN()))
+ return RHS;
+ if (match(RHS, m_NaN()))
+ return LHS;
+ return nullptr;
default:
return nullptr;
}
Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll?rev=337127&r1=337126&r2=337127&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Sun Jul 15 07:52:16 2018
@@ -474,8 +474,7 @@ declare <2 x double> @llvm.maxnum.v2f64(
define double @maxnum_nan_op0(double %x) {
; CHECK-LABEL: @maxnum_nan_op0(
-; CHECK-NEXT: [[R:%.*]] = call double @llvm.maxnum.f64(double 0x7FF8000000000000, double [[X:%.*]])
-; CHECK-NEXT: ret double [[R]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%r = call double @llvm.maxnum.f64(double 0x7ff8000000000000, double %x)
ret double %r
@@ -483,8 +482,7 @@ define double @maxnum_nan_op0(double %x)
define double @maxnum_nan_op1(double %x) {
; CHECK-LABEL: @maxnum_nan_op1(
-; CHECK-NEXT: [[R:%.*]] = call double @llvm.maxnum.f64(double [[X:%.*]], double 0x7FF800000000DEAD)
-; CHECK-NEXT: ret double [[R]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%r = call double @llvm.maxnum.f64(double %x, double 0x7ff800000000dead)
ret double %r
@@ -492,8 +490,7 @@ define double @maxnum_nan_op1(double %x)
define double @minnum_nan_op0(double %x) {
; CHECK-LABEL: @minnum_nan_op0(
-; CHECK-NEXT: [[R:%.*]] = call double @llvm.minnum.f64(double 0x7FF8000DEAD00000, double [[X:%.*]])
-; CHECK-NEXT: ret double [[R]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%r = call double @llvm.minnum.f64(double 0x7ff8000dead00000, double %x)
ret double %r
@@ -501,8 +498,7 @@ define double @minnum_nan_op0(double %x)
define double @minnum_nan_op1(double %x) {
; CHECK-LABEL: @minnum_nan_op1(
-; CHECK-NEXT: [[R:%.*]] = call double @llvm.minnum.f64(double [[X:%.*]], double 0x7FF800DEAD00DEAD)
-; CHECK-NEXT: ret double [[R]]
+; CHECK-NEXT: ret double [[X:%.*]]
;
%r = call double @llvm.minnum.f64(double %x, double 0x7ff800dead00dead)
ret double %r
@@ -510,8 +506,7 @@ define double @minnum_nan_op1(double %x)
define <2 x double> @maxnum_nan_op0_vec(<2 x double> %x) {
; CHECK-LABEL: @maxnum_nan_op0_vec(
-; CHECK-NEXT: [[R:%.*]] = call <2 x double> @llvm.maxnum.v2f64(<2 x double> <double 0x7FF8000000000000, double undef>, <2 x double> [[X:%.*]])
-; CHECK-NEXT: ret <2 x double> [[R]]
+; CHECK-NEXT: ret <2 x double> [[X:%.*]]
;
%r = call <2 x double> @llvm.maxnum.v2f64(<2 x double> <double 0x7ff8000000000000, double undef>, <2 x double> %x)
ret <2 x double> %r
@@ -519,8 +514,7 @@ define <2 x double> @maxnum_nan_op0_vec(
define <2 x double> @maxnum_nan_op1_vec(<2 x double> %x) {
; CHECK-LABEL: @maxnum_nan_op1_vec(
-; CHECK-NEXT: [[R:%.*]] = call <2 x double> @llvm.maxnum.v2f64(<2 x double> [[X:%.*]], <2 x double> <double 0x7FF800000000DEAD, double 0x7FF8FFFFFFFFFFFF>)
-; CHECK-NEXT: ret <2 x double> [[R]]
+; CHECK-NEXT: ret <2 x double> [[X:%.*]]
;
%r = call <2 x double> @llvm.maxnum.v2f64(<2 x double> %x, <2 x double> <double 0x7ff800000000dead, double 0x7ff8ffffffffffff>)
ret <2 x double> %r
@@ -528,8 +522,7 @@ define <2 x double> @maxnum_nan_op1_vec(
define <2 x double> @minnum_nan_op0_vec(<2 x double> %x) {
; CHECK-LABEL: @minnum_nan_op0_vec(
-; CHECK-NEXT: [[R:%.*]] = call <2 x double> @llvm.minnum.v2f64(<2 x double> <double undef, double 0x7FF8000DEAD00000>, <2 x double> [[X:%.*]])
-; CHECK-NEXT: ret <2 x double> [[R]]
+; CHECK-NEXT: ret <2 x double> [[X:%.*]]
;
%r = call <2 x double> @llvm.minnum.v2f64(<2 x double> <double undef, double 0x7ff8000dead00000>, <2 x double> %x)
ret <2 x double> %r
@@ -537,8 +530,7 @@ define <2 x double> @minnum_nan_op0_vec(
define <2 x double> @minnum_nan_op1_vec(<2 x double> %x) {
; CHECK-LABEL: @minnum_nan_op1_vec(
-; CHECK-NEXT: [[R:%.*]] = call <2 x double> @llvm.minnum.v2f64(<2 x double> [[X:%.*]], <2 x double> <double 0x7FF800DEAD00DEAD, double 0x7FF800DEAD00DEAD>)
-; CHECK-NEXT: ret <2 x double> [[R]]
+; CHECK-NEXT: ret <2 x double> [[X:%.*]]
;
%r = call <2 x double> @llvm.minnum.v2f64(<2 x double> %x, <2 x double> <double 0x7ff800dead00dead, double 0x7ff800dead00dead>)
ret <2 x double> %r
More information about the llvm-commits
mailing list