diff options
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 5 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/sub.ll | 10 |
2 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index ae7d08149c6..34a5e1955b6 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -747,8 +747,9 @@ Value *InstCombiner::SimplifySelectsFeedingBinaryOp(BinaryOperator &I, /// 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)) diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll index 299633b25ac..dd9fadf2023 100644 --- a/llvm/test/Transforms/InstCombine/sub.ll +++ b/llvm/test/Transforms/InstCombine/sub.ll @@ -132,7 +132,7 @@ define <2 x i32> @neg_nsw_sub_nsw_vec(<2 x i32> %x, <2 x i32> %y) { 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 i32> %x, <2 x i32> %y) { 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(<2 x i32> %x, <2 x i32> %y) { 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(<2 x i32> %x, <2 x i32> %y) { 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 |

