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 | 175e7aec1347be3469b0838e5380d424228aa48f (patch) | |
tree | cc708cb1dead7db7ceeefa74140fabb5091bbc4a /lib/VMCore | |
parent | 337c0811381a48b75aec204d96090779fec6606e (diff) | |
download | external_llvm-175e7aec1347be3469b0838e5380d424228aa48f.zip external_llvm-175e7aec1347be3469b0838e5380d424228aa48f.tar.gz external_llvm-175e7aec1347be3469b0838e5380d424228aa48f.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124547 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 3fea1910f..c3be119 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/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; } |