diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-12-06 21:22:57 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-12-06 21:22:57 +0000 |
commit | b6404a8ca6e7d3a77894f3dcfdad89cda1eb6042 (patch) | |
tree | 9c24ea0afd42a259eed25375b6508b3c30683151 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | e363d2cebbc1b880059a372d69f6ddee587f9d2d (diff) | |
download | bcm5719-llvm-b6404a8ca6e7d3a77894f3dcfdad89cda1eb6042.tar.gz bcm5719-llvm-b6404a8ca6e7d3a77894f3dcfdad89cda1eb6042.zip |
[InstCombine] canonicalize constant-minus-boolean to select-of-constants
This restores the half of:
https://reviews.llvm.org/rL75531
that was reverted at:
https://reviews.llvm.org/rL159230
For the x86 case mentioned there, we now produce:
leal 1(%rdi), %eax
subl %esi, %eax
We have target hooks to invert this in DAGCombiner (and x86 is enabled) with:
https://reviews.llvm.org/rL296977
https://reviews.llvm.org/rL311731
AArch64 and possibly other targets would probably benefit from enabling those hooks too.
See PR30327:
https://bugs.llvm.org/show_bug.cgi?id=30327#c2
Differential Revision: https://reviews.llvm.org/D40612
llvm-svn: 319964
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index d28d615f47e..68889764484 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1520,8 +1520,13 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { return BinaryOperator::CreateNot(Op1); if (Constant *C = dyn_cast<Constant>(Op0)) { + Value *X; + // C - zext(bool) -> bool ? C - 1 : C + if (match(Op1, m_ZExt(m_Value(X))) && + X->getType()->getScalarSizeInBits() == 1) + return SelectInst::Create(X, SubOne(C), C); + // C - ~X == X + (1+C) - Value *X = nullptr; if (match(Op1, m_Not(m_Value(X)))) return BinaryOperator::CreateAdd(X, AddOne(C)); |