[llvm] r344793 - [InstCombine] use m_Neg() in dyn_castNegVal() to match vectors with undef elts

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 19 10:54:53 PDT 2018


Author: spatel
Date: Fri Oct 19 10:54:53 2018
New Revision: 344793

URL: http://llvm.org/viewvc/llvm-project?rev=344793&view=rev
Log:
[InstCombine] use m_Neg() in dyn_castNegVal() to match vectors with undef elts

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
    llvm/trunk/test/Transforms/InstCombine/sub.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=344793&r1=344792&r2=344793&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Fri Oct 19 10:54:53 2018
@@ -747,8 +747,9 @@ Value *InstCombiner::SimplifySelectsFeed
 /// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a
 /// constant zero (which is the 'negate' form).
 Value *InstCombiner::dyn_castNegVal(Value *V) const {
-  if (BinaryOperator::isNeg(V))
-    return BinaryOperator::getNegArgument(V);
+  Value *NegV;
+  if (match(V, m_Neg(m_Value(NegV))))
+    return NegV;
 
   // Constants can be considered to be negated values if they can be folded.
   if (ConstantInt *C = dyn_cast<ConstantInt>(V))

Modified: llvm/trunk/test/Transforms/InstCombine/sub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sub.ll?rev=344793&r1=344792&r2=344793&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sub.ll Fri Oct 19 10:54:53 2018
@@ -132,7 +132,7 @@ define <2 x i32> @neg_nsw_sub_nsw_vec(<2
 
 define <2 x i32> @neg_sub_vec_undef(<2 x i32> %x, <2 x i32> %y) {
 ; CHECK-LABEL: @neg_sub_vec_undef(
-; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
 ; CHECK-NEXT:    ret <2 x i32> [[R]]
 ;
   %neg = sub <2 x i32> <i32 0, i32 undef>, %x
@@ -142,7 +142,7 @@ define <2 x i32> @neg_sub_vec_undef(<2 x
 
 define <2 x i32> @neg_nsw_sub_vec_undef(<2 x i32> %x, <2 x i32> %y) {
 ; CHECK-LABEL: @neg_nsw_sub_vec_undef(
-; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
 ; CHECK-NEXT:    ret <2 x i32> [[R]]
 ;
   %neg = sub nsw <2 x i32> <i32 undef, i32 0>, %x
@@ -152,7 +152,7 @@ define <2 x i32> @neg_nsw_sub_vec_undef(
 
 define <2 x i32> @neg_sub_nsw_vec_undef(<2 x i32> %x, <2 x i32> %y) {
 ; CHECK-LABEL: @neg_sub_nsw_vec_undef(
-; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[Y:%.*]], [[X:%.*]]
 ; CHECK-NEXT:    ret <2 x i32> [[R]]
 ;
   %neg = sub <2 x i32> <i32 undef, i32 0>, %x
@@ -160,11 +160,11 @@ define <2 x i32> @neg_sub_nsw_vec_undef(
   ret <2 x i32> %r
 }
 
-; TODO: This should not drop 'nsw'.
+; This should not drop 'nsw'.
 
 define <2 x i32> @neg_nsw_sub_nsw_vec_undef(<2 x i32> %x, <2 x i32> %y) {
 ; CHECK-LABEL: @neg_nsw_sub_nsw_vec_undef(
-; CHECK-NEXT:    [[R:%.*]] = add <2 x i32> [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT:    [[R:%.*]] = add nsw <2 x i32> [[Y:%.*]], [[X:%.*]]
 ; CHECK-NEXT:    ret <2 x i32> [[R]]
 ;
   %neg = sub nsw <2 x i32> <i32 0, i32 undef>, %x




More information about the llvm-commits mailing list