diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2011-01-29 20:35:06 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2011-01-29 20:35:06 +0000 |
| commit | 97a2895e73a0288d9edc896ce3f09674c6f4c61f (patch) | |
| tree | b1bb14affe2bfbcb257d42229612629542ed9ddd /llvm/lib | |
| parent | 265aa7c070bdb019c880aca348381cc27189ea03 (diff) | |
| download | bcm5719-llvm-97a2895e73a0288d9edc896ce3f09674c6f4c61f.tar.gz bcm5719-llvm-97a2895e73a0288d9edc896ce3f09674c6f4c61f.zip | |
Add the select optimization recently added to instcombine to constant folding.
This is the one where one of the branches of the select is another select on
the same condition.
llvm-svn: 124547
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index 3fea1910ffe..c3be1197d3c 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -693,6 +693,18 @@ Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond, if (isa<UndefValue>(V2)) return V1; if (isa<UndefValue>(Cond)) return V1; if (V1 == V2) return V1; + + if (ConstantExpr *TrueVal = dyn_cast<ConstantExpr>(V1)) { + if (TrueVal->getOpcode() == Instruction::Select) + if (TrueVal->getOperand(0) == Cond) + return ConstantExpr::getSelect(Cond, TrueVal->getOperand(1), V2); + } + if (ConstantExpr *FalseVal = dyn_cast<ConstantExpr>(V2)) { + if (FalseVal->getOpcode() == Instruction::Select) + if (FalseVal->getOperand(0) == Cond) + return ConstantExpr::getSelect(Cond, V1, FalseVal->getOperand(2)); + } + return 0; } |

