[InstSimplify] move minnum/maxnum with same arg fold from instcombine
llvm-svn: 338652
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 7fc7c15..b1601bf 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4764,6 +4764,9 @@
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;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index cbfbd8a..77c5a06 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1137,10 +1137,6 @@
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
diff --git a/llvm/test/Transforms/InstCombine/maxnum.ll b/llvm/test/Transforms/InstCombine/maxnum.ll
index 11bff42..ff415aa 100644
--- a/llvm/test/Transforms/InstCombine/maxnum.ll
+++ b/llvm/test/Transforms/InstCombine/maxnum.ll
@@ -129,14 +129,6 @@
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:%.*]]
diff --git a/llvm/test/Transforms/InstCombine/minnum.ll b/llvm/test/Transforms/InstCombine/minnum.ll
index a05ce8c..7cf9d1b 100644
--- a/llvm/test/Transforms/InstCombine/minnum.ll
+++ b/llvm/test/Transforms/InstCombine/minnum.ll
@@ -131,14 +131,6 @@
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:%.*]]
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
index afd375f..ca9226d 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -463,14 +463,15 @@
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 @@
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
+}
+