[llvm] r338652 - [InstSimplify] move minnum/maxnum with same arg fold from instcombine
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 1 16:05:55 PDT 2018
Author: spatel
Date: Wed Aug 1 16:05:55 2018
New Revision: 338652
URL: http://llvm.org/viewvc/llvm-project?rev=338652&view=rev
Log:
[InstSimplify] move minnum/maxnum with same arg fold from instcombine
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/maxnum.ll
llvm/trunk/test/Transforms/InstCombine/minnum.ll
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=338652&r1=338651&r2=338652&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Aug 1 16:05:55 2018
@@ -4764,6 +4764,9 @@ static Value *simplifyBinaryIntrinsic(Fu
break;
case Intrinsic::maxnum:
case Intrinsic::minnum:
+ // If the arguments are the same, this is a no-op.
+ if (Op0 == Op1) return Op0;
+
// If one argument is NaN, return the other argument.
if (match(Op0, m_NaN())) return Op1;
if (match(Op1, m_NaN())) return Op0;
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=338652&r1=338651&r2=338652&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Wed Aug 1 16:05:55 2018
@@ -1137,10 +1137,6 @@ static Value *simplifyMinnumMaxnum(const
Value *Arg0 = II.getArgOperand(0);
Value *Arg1 = II.getArgOperand(1);
- // fmin(x, x) -> x
- if (Arg0 == Arg1)
- return Arg0;
-
const auto *C1 = dyn_cast<ConstantFP>(Arg1);
// fmin(x, nan) -> x
Modified: llvm/trunk/test/Transforms/InstCombine/maxnum.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/maxnum.ll?rev=338652&r1=338651&r2=338652&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/maxnum.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/maxnum.ll Wed Aug 1 16:05:55 2018
@@ -129,14 +129,6 @@ define float @canonicalize_constant_maxn
ret float %y
}
-define float @noop_maxnum_f32(float %x) {
-; CHECK-LABEL: @noop_maxnum_f32(
-; CHECK-NEXT: ret float [[X:%.*]]
-;
- %y = call float @llvm.maxnum.f32(float %x, float %x)
- ret float %y
-}
-
define float @maxnum_f32_nan_val(float %x) {
; CHECK-LABEL: @maxnum_f32_nan_val(
; CHECK-NEXT: ret float [[X:%.*]]
Modified: llvm/trunk/test/Transforms/InstCombine/minnum.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/minnum.ll?rev=338652&r1=338651&r2=338652&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/minnum.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/minnum.ll Wed Aug 1 16:05:55 2018
@@ -131,14 +131,6 @@ define float @canonicalize_constant_minn
ret float %y
}
-define float @noop_minnum_f32(float %x) {
-; CHECK-LABEL: @noop_minnum_f32(
-; CHECK-NEXT: ret float [[X:%.*]]
-;
- %y = call float @llvm.minnum.f32(float %x, float %x)
- ret float %y
-}
-
define float @minnum_f32_nan_val(float %x) {
; CHECK-LABEL: @minnum_f32_nan_val(
; CHECK-NEXT: ret float [[X:%.*]]
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=338652&r1=338651&r2=338652&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Wed Aug 1 16:05:55 2018
@@ -463,14 +463,15 @@ define float @fabs_select_positive_const
ret float %fabs
}
+declare float @llvm.minnum.f32(float, float)
+declare float @llvm.maxnum.f32(float, float)
declare double @llvm.minnum.f64(double, double)
declare double @llvm.maxnum.f64(double, double)
declare <2 x double> @llvm.minnum.v2f64(<2 x double>, <2 x double>)
declare <2 x double> @llvm.maxnum.v2f64(<2 x double>, <2 x double>)
; From the LangRef for minnum/maxnum:
-; "follows the IEEE-754 semantics for maxNum, which also match for libmâs fmax.
-; If either operand is a NaN, returns the other non-NaN operand."
+; "If either operand is a NaN, returns the other non-NaN operand."
define double @maxnum_nan_op0(double %x) {
; CHECK-LABEL: @maxnum_nan_op0(
@@ -536,3 +537,19 @@ define <2 x double> @minnum_nan_op1_vec(
ret <2 x double> %r
}
+define float @minnum_same_args(float %x) {
+; CHECK-LABEL: @minnum_same_args(
+; CHECK-NEXT: ret float [[X:%.*]]
+;
+ %y = call float @llvm.minnum.f32(float %x, float %x)
+ ret float %y
+}
+
+define float @maxnum_same_args(float %x) {
+; CHECK-LABEL: @maxnum_same_args(
+; CHECK-NEXT: ret float [[X:%.*]]
+;
+ %y = call float @llvm.maxnum.f32(float %x, float %x)
+ ret float %y
+}
+
More information about the llvm-commits
mailing list