diff options
| author | Chris Lattner <sabre@nondot.org> | 2005-04-23 15:31:55 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2005-04-23 15:31:55 +0000 |
| commit | 77c32c34d76de4ce0be3312b16a1e9bd749f5734 (patch) | |
| tree | c155f4d5d6376a73ebbdb30725afc713438c6c86 /llvm/lib/Transforms | |
| parent | 64a8a7f9b760c0d4bfa93b188e28a4ab3f0fb207 (diff) | |
| download | bcm5719-llvm-77c32c34d76de4ce0be3312b16a1e9bd749f5734.tar.gz bcm5719-llvm-77c32c34d76de4ce0be3312b16a1e9bd749f5734.zip | |
Generalize the setcc -> PHI and Select folding optimizations to work with
any constant RHS, not just a constant integer RHS. This implements
select.ll:test17
llvm-svn: 21470
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 5a2e4ef177e..7c5cfa823a4 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2450,10 +2450,6 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { if (Instruction *LHSI = dyn_cast<Instruction>(Op0)) switch (LHSI->getOpcode()) { - case Instruction::PHI: - if (Instruction *NV = FoldOpIntoPhi(I)) - return NV; - break; case Instruction::And: if (LHSI->hasOneUse() && isa<ConstantInt>(LHSI->getOperand(1)) && LHSI->getOperand(0)->hasOneUse()) { @@ -2705,32 +2701,6 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { } } break; - case Instruction::Select: - // If either operand of the select is a constant, we can fold the - // comparison into the select arms, which will cause one to be - // constant folded and the select turned into a bitwise or. - Value *Op1 = 0, *Op2 = 0; - if (LHSI->hasOneUse()) { - if (Constant *C = dyn_cast<Constant>(LHSI->getOperand(1))) { - // Fold the known value into the constant operand. - Op1 = ConstantExpr::get(I.getOpcode(), C, CI); - // Insert a new SetCC of the other select operand. - Op2 = InsertNewInstBefore(new SetCondInst(I.getOpcode(), - LHSI->getOperand(2), CI, - I.getName()), I); - } else if (Constant *C = dyn_cast<Constant>(LHSI->getOperand(2))) { - // Fold the known value into the constant operand. - Op2 = ConstantExpr::get(I.getOpcode(), C, CI); - // Insert a new SetCC of the other select operand. - Op1 = InsertNewInstBefore(new SetCondInst(I.getOpcode(), - LHSI->getOperand(1), CI, - I.getName()), I); - } - } - - if (Op1) - return new SelectInst(LHSI->getOperand(0), Op1, Op2); - break; } // Simplify seteq and setne instructions... @@ -2896,6 +2866,43 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { } } + // Handle setcc with constant RHS's that can be integer, FP or pointer. + if (Constant *RHSC = dyn_cast<Constant>(Op1)) { + if (Instruction *LHSI = dyn_cast<Instruction>(Op0)) + switch (LHSI->getOpcode()) { + case Instruction::PHI: + if (Instruction *NV = FoldOpIntoPhi(I)) + return NV; + break; + case Instruction::Select: + // If either operand of the select is a constant, we can fold the + // comparison into the select arms, which will cause one to be + // constant folded and the select turned into a bitwise or. + Value *Op1 = 0, *Op2 = 0; + if (LHSI->hasOneUse()) { + if (Constant *C = dyn_cast<Constant>(LHSI->getOperand(1))) { + // Fold the known value into the constant operand. + Op1 = ConstantExpr::get(I.getOpcode(), C, RHSC); + // Insert a new SetCC of the other select operand. + Op2 = InsertNewInstBefore(new SetCondInst(I.getOpcode(), + LHSI->getOperand(2), RHSC, + I.getName()), I); + } else if (Constant *C = dyn_cast<Constant>(LHSI->getOperand(2))) { + // Fold the known value into the constant operand. + Op2 = ConstantExpr::get(I.getOpcode(), C, RHSC); + // Insert a new SetCC of the other select operand. + Op1 = InsertNewInstBefore(new SetCondInst(I.getOpcode(), + LHSI->getOperand(1), RHSC, + I.getName()), I); + } + } + + if (Op1) + return new SelectInst(LHSI->getOperand(0), Op1, Op2); + break; + } + } + // If we can optimize a 'setcc GEP, P' or 'setcc P, GEP', do so now. if (User *GEP = dyn_castGetElementPtr(Op0)) if (Instruction *NI = FoldGEPSetCC(GEP, Op1, I.getOpcode(), I)) |

