[llvm] r338719 - [InstSimplify] move minnum/maxnum with undef fold from instcombine

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 2 07:33:40 PDT 2018


Author: spatel
Date: Thu Aug  2 07:33:40 2018
New Revision: 338719

URL: http://llvm.org/viewvc/llvm-project?rev=338719&view=rev
Log:
[InstSimplify] move minnum/maxnum with undef 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=338719&r1=338718&r2=338719&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Thu Aug  2 07:33:40 2018
@@ -4767,9 +4767,10 @@ static Value *simplifyBinaryIntrinsic(Fu
     // 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;
+    // If one argument is NaN or undef, return the other argument.
+    if (match(Op0, m_CombineOr(m_NaN(), m_Undef()))) return Op1;
+    if (match(Op1, m_CombineOr(m_NaN(), m_Undef()))) return Op0;
+
     break;
   default:
     break;

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=338719&r1=338718&r2=338719&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu Aug  2 07:33:40 2018
@@ -1143,17 +1143,6 @@ static Value *simplifyMinnumMaxnum(const
   if (C1 && C1->isNaN())
     return Arg0;
 
-  // This is the value because if undef were NaN, we would return the other
-  // value and cannot return a NaN unless both operands are.
-  //
-  // fmin(undef, x) -> x
-  if (isa<UndefValue>(Arg0))
-    return Arg1;
-
-  // fmin(x, undef) -> x
-  if (isa<UndefValue>(Arg1))
-    return Arg0;
-
   Value *X = nullptr;
   Value *Y = nullptr;
   if (II.getIntrinsicID() == Intrinsic::minnum) {

Modified: llvm/trunk/test/Transforms/InstCombine/maxnum.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/maxnum.ll?rev=338719&r1=338718&r2=338719&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/maxnum.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/maxnum.ll Thu Aug  2 07:33:40 2018
@@ -153,22 +153,6 @@ define float @fold_maxnum_f32_undef_unde
   ret float %val
 }
 
-define float @fold_maxnum_f32_val_undef(float %x) {
-; CHECK-LABEL: @fold_maxnum_f32_val_undef(
-; CHECK-NEXT:    ret float [[X:%.*]]
-;
-  %val = call float @llvm.maxnum.f32(float %x, float undef)
-  ret float %val
-}
-
-define float @fold_maxnum_f32_undef_val(float %x) {
-; CHECK-LABEL: @fold_maxnum_f32_undef_val(
-; CHECK-NEXT:    ret float [[X:%.*]]
-;
-  %val = call float @llvm.maxnum.f32(float undef, float %x)
-  ret float %val
-}
-
 define float @maxnum_x_maxnum_x_y(float %x, float %y) {
 ; CHECK-LABEL: @maxnum_x_maxnum_x_y(
 ; CHECK-NEXT:    [[A:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float [[Y:%.*]])

Modified: llvm/trunk/test/Transforms/InstCombine/minnum.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/minnum.ll?rev=338719&r1=338718&r2=338719&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/minnum.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/minnum.ll Thu Aug  2 07:33:40 2018
@@ -155,22 +155,6 @@ define float @fold_minnum_f32_undef_unde
   ret float %val
 }
 
-define float @fold_minnum_f32_val_undef(float %x) {
-; CHECK-LABEL: @fold_minnum_f32_val_undef(
-; CHECK-NEXT:    ret float [[X:%.*]]
-;
-  %val = call float @llvm.minnum.f32(float %x, float undef)
-  ret float %val
-}
-
-define float @fold_minnum_f32_undef_val(float %x) {
-; CHECK-LABEL: @fold_minnum_f32_undef_val(
-; CHECK-NEXT:    ret float [[X:%.*]]
-;
-  %val = call float @llvm.minnum.f32(float undef, float %x)
-  ret float %val
-}
-
 define float @minnum_x_minnum_x_y(float %x, float %y) {
 ; CHECK-LABEL: @minnum_x_minnum_x_y(
 ; CHECK-NEXT:    [[A:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], float [[Y:%.*]])

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=338719&r1=338718&r2=338719&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Thu Aug  2 07:33:40 2018
@@ -537,6 +537,38 @@ define <2 x double> @minnum_nan_op1_vec(
   ret <2 x double> %r
 }
 
+define float @maxnum_undef_op1(float %x) {
+; CHECK-LABEL: @maxnum_undef_op1(
+; CHECK-NEXT:    ret float [[X:%.*]]
+;
+  %val = call float @llvm.maxnum.f32(float %x, float undef)
+  ret float %val
+}
+
+define float @maxnum_undef_op0(float %x) {
+; CHECK-LABEL: @maxnum_undef_op0(
+; CHECK-NEXT:    ret float [[X:%.*]]
+;
+  %val = call float @llvm.maxnum.f32(float undef, float %x)
+  ret float %val
+}
+
+define float @minnum_undef_op1(float %x) {
+; CHECK-LABEL: @minnum_undef_op1(
+; CHECK-NEXT:    ret float [[X:%.*]]
+;
+  %val = call float @llvm.minnum.f32(float %x, float undef)
+  ret float %val
+}
+
+define float @minnum_undef_op0(float %x) {
+; CHECK-LABEL: @minnum_undef_op0(
+; CHECK-NEXT:    ret float [[X:%.*]]
+;
+  %val = call float @llvm.minnum.f32(float undef, float %x)
+  ret float %val
+}
+
 define float @minnum_same_args(float %x) {
 ; CHECK-LABEL: @minnum_same_args(
 ; CHECK-NEXT:    ret float [[X:%.*]]




More information about the llvm-commits mailing list