summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-03-03 17:53:25 +0000
committerSanjay Patel <spatel@rotateright.com>2018-03-03 17:53:25 +0000
commit1a8d5c3d1f43ebf7b07f1f009797e7d3eccebc60 (patch)
treed0e252005e765d494b52480803e9eb14238216f3
parent73eb2d255529c83e94b2e36d67060a14f60ce1a0 (diff)
downloadbcm5719-llvm-1a8d5c3d1f43ebf7b07f1f009797e7d3eccebc60.tar.gz
bcm5719-llvm-1a8d5c3d1f43ebf7b07f1f009797e7d3eccebc60.zip
[InstCombine] (~X) - (~Y) --> Y - X
llvm-svn: 326660
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp5
-rw-r--r--llvm/test/Transforms/InstCombine/sub.ll6
2 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index c47ebb34087..b37b201ff25 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1511,6 +1511,11 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
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
diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll
index 595748674d0..405320ba74c 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -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>
OpenPOWER on IntegriCloud