diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2009-07-13 22:27:52 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2009-07-13 22:27:52 +0000 |
| commit | 7e1716dc9d5cbbadbcdaf8d68948eedb9fbf0c53 (patch) | |
| tree | b65e1a619c035db150ef4d90c28a0cfb0cd6be18 /llvm/lib/Transforms | |
| parent | dd707af3456fe9bd1ac44086e6ffe457b1ed6b2b (diff) | |
| download | bcm5719-llvm-7e1716dc9d5cbbadbcdaf8d68948eedb9fbf0c53.tar.gz bcm5719-llvm-7e1716dc9d5cbbadbcdaf8d68948eedb9fbf0c53.zip | |
Canonicalize boolean +/- a constant to a select.
(I think it's reasonably clear that we want to have a canonical form for
constructs like this; if anyone thinks that a select is not the best
canonical form, please tell me.)
llvm-svn: 75531
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 5b9659e2004..c93994ff56d 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2101,13 +2101,10 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { if (SimplifyDemandedInstructionBits(I)) return &I; - // zext(i1) - 1 -> select i1, 0, -1 + // zext(bool) + C -> bool ? C + 1 : C if (ZExtInst *ZI = dyn_cast<ZExtInst>(LHS)) - if (CI->isAllOnesValue() && - ZI->getOperand(0)->getType() == Type::Int1Ty) - return SelectInst::Create(ZI->getOperand(0), - Context->getNullValue(I.getType()), - Context->getAllOnesValue(I.getType())); + if (ZI->getSrcTy() == Type::Int1Ty) + return SelectInst::Create(ZI->getOperand(0), AddOne(CI, Context), CI); } if (isa<PHINode>(LHS)) @@ -2525,6 +2522,11 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { if (SelectInst *SI = dyn_cast<SelectInst>(Op1)) if (Instruction *R = FoldOpIntoSelect(I, SI, this)) return R; + + // C - zext(bool) -> bool ? C - 1 : C + if (ZExtInst *ZI = dyn_cast<ZExtInst>(Op1)) + if (ZI->getSrcTy() == Type::Int1Ty) + return SelectInst::Create(ZI->getOperand(0), SubOne(C, Context), C); } if (I.getType() == Type::Int1Ty) |

