[llvm] r326660 - [InstCombine] (~X) - (~Y) --> Y - X
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 3 09:53:25 PST 2018
Author: spatel
Date: Sat Mar 3 09:53:25 2018
New Revision: 326660
URL: http://llvm.org/viewvc/llvm-project?rev=326660&view=rev
Log:
[InstCombine] (~X) - (~Y) --> Y - X
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/test/Transforms/InstCombine/sub.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=326660&r1=326659&r2=326660&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Sat Mar 3 09:53:25 2018
@@ -1511,6 +1511,11 @@ Instruction *InstCombiner::visitSub(Bina
if (match(Op0, m_AllOnes()))
return BinaryOperator::CreateNot(Op1);
+ // (~X) - (~Y) --> Y - X
+ Value *X, *Y;
+ if (match(Op0, m_Not(m_Value(X))) && match(Op1, m_Not(m_Value(Y))))
+ return BinaryOperator::CreateSub(Y, X);
+
if (Constant *C = dyn_cast<Constant>(Op0)) {
Value *X;
// C - zext(bool) -> bool ? C - 1 : C
Modified: llvm/trunk/test/Transforms/InstCombine/sub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sub.ll?rev=326660&r1=326659&r2=326660&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sub.ll Sat Mar 3 09:53:25 2018
@@ -50,7 +50,7 @@ define i8 @notnotsub(i8 %x, i8 %y) {
; CHECK-LABEL: @notnotsub(
; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
-; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[NX]], [[NY]]
+; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[Y]], [[X]]
; CHECK-NEXT: call void @use8(i8 [[NX]])
; CHECK-NEXT: call void @use8(i8 [[NY]])
; CHECK-NEXT: ret i8 [[SUB]]
@@ -65,9 +65,7 @@ define i8 @notnotsub(i8 %x, i8 %y) {
define <2 x i8> @notnotsub_vec(<2 x i8> %x, <2 x i8> %y) {
; CHECK-LABEL: @notnotsub_vec(
-; CHECK-NEXT: [[NX:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
-; CHECK-NEXT: [[NY:%.*]] = xor <2 x i8> [[Y:%.*]], <i8 -1, i8 -1>
-; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[NX]], [[NY]]
+; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret <2 x i8> [[SUB]]
;
%nx = xor <2 x i8> %x, <i8 -1, i8 -1>
More information about the llvm-commits
mailing list