diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2008-07-05 21:19:34 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2008-07-05 21:19:34 +0000 |
| commit | 1265a7d9f6cd6453ba3b6c8fe3a54f17204da233 (patch) | |
| tree | 7ea527d2834ad2b34a0b21793981a1f5302c1a50 /lib | |
| parent | 55854cc1b3acd8103c1dc674dad5de4b7a41d33d (diff) | |
| download | external_llvm-1265a7d9f6cd6453ba3b6c8fe3a54f17204da233.zip external_llvm-1265a7d9f6cd6453ba3b6c8fe3a54f17204da233.tar.gz external_llvm-1265a7d9f6cd6453ba3b6c8fe3a54f17204da233.tar.bz2 | |
Fix missed optimization opportunity when analyzing cast of mul and select.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53151 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 5d75489..8c3f2d5 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -6917,6 +6917,7 @@ bool InstCombiner::CanEvaluateInDifferentType(Value *V, const IntegerType *Ty, switch (I->getOpcode()) { case Instruction::Add: case Instruction::Sub: + case Instruction::Mul: case Instruction::And: case Instruction::Or: case Instruction::Xor: @@ -6926,14 +6927,6 @@ bool InstCombiner::CanEvaluateInDifferentType(Value *V, const IntegerType *Ty, CanEvaluateInDifferentType(I->getOperand(1), Ty, CastOpc, NumCastsRemoved); - case Instruction::Mul: - // A multiply can be truncated by truncating its operands. - return Ty->getBitWidth() < OrigTy->getBitWidth() && - CanEvaluateInDifferentType(I->getOperand(0), Ty, CastOpc, - NumCastsRemoved) && - CanEvaluateInDifferentType(I->getOperand(1), Ty, CastOpc, - NumCastsRemoved); - case Instruction::Shl: // If we are truncating the result of this SHL, and if it's a shift of a // constant amount, we can always perform a SHL in a smaller type. @@ -6970,7 +6963,13 @@ bool InstCombiner::CanEvaluateInDifferentType(Value *V, const IntegerType *Ty, if (I->getOpcode() == CastOpc) return true; break; - + case Instruction::Select: { + SelectInst *SI = cast<SelectInst>(I); + return CanEvaluateInDifferentType(SI->getTrueValue(), Ty, CastOpc, + NumCastsRemoved) && + CanEvaluateInDifferentType(SI->getFalseValue(), Ty, CastOpc, + NumCastsRemoved); + } case Instruction::PHI: { // We can change a phi if we can change all operands. PHINode *PN = cast<PHINode>(I); @@ -7028,6 +7027,12 @@ Value *InstCombiner::EvaluateInDifferentType(Value *V, const Type *Ty, Res = CastInst::Create(cast<CastInst>(I)->getOpcode(), I->getOperand(0), Ty); break; + case Instruction::Select: { + Value *True = EvaluateInDifferentType(I->getOperand(1), Ty, isSigned); + Value *False = EvaluateInDifferentType(I->getOperand(2), Ty, isSigned); + Res = SelectInst::Create(I->getOperand(0), True, False); + break; + } case Instruction::PHI: { PHINode *OPN = cast<PHINode>(I); PHINode *NPN = PHINode::Create(Ty); |
