From: Chris Lattner Date: Wed, 4 Jun 2003 05:10:11 +0000 (+0000) Subject: Clean up previous code. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=40f5d70db4759e9babc2fe2e827ac326cac9016a;hp=9dad6d741104209e8ee5fe916639035e127c3c27 Clean up previous code. Add new combination to turn seteq X, 0 -> not(cast X to bool) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6604 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 2a5856ae37c..cfeada349bd 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -683,8 +683,16 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { // integers at the end of their ranges... // if (ConstantInt *CI = dyn_cast(Op1)) { - if (CI->isNullValue() && I.getOpcode() == Instruction::SetNE) - return new CastInst(Op0, Type::BoolTy, I.getName()); + if (CI->isNullValue()) { + if (I.getOpcode() == Instruction::SetNE) + return new CastInst(Op0, Type::BoolTy, I.getName()); + else if (I.getOpcode() == Instruction::SetEQ) { + // seteq X, 0 -> not (cast X to bool) + Instruction *Val = new CastInst(Op0, Type::BoolTy, I.getName()+".not"); + InsertNewInstBefore(Val, I); + return BinaryOperator::createNot(Val, I.getName()); + } + } // Check to see if we are comparing against the minimum or maximum value... if (CI->isMinValue()) { @@ -1064,15 +1072,16 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { Instruction *InstCombiner::visitBranchInst(BranchInst &BI) { // Change br (not X), label True, label False to: br X, label False, True - if (BI.isConditional() && BinaryOperator::isNot(BI.getCondition())) { - BasicBlock *TrueDest = BI.getSuccessor(0); - BasicBlock *FalseDest = BI.getSuccessor(1); - // Swap Destinations and condition... - BI.setCondition(BinaryOperator::getNotArgument(cast(BI.getCondition()))); - BI.setSuccessor(0, FalseDest); - BI.setSuccessor(1, TrueDest); - return &BI; - } + if (BI.isConditional()) + if (Value *V = dyn_castNotVal(BI.getCondition())) { + BasicBlock *TrueDest = BI.getSuccessor(0); + BasicBlock *FalseDest = BI.getSuccessor(1); + // Swap Destinations and condition... + BI.setCondition(V); + BI.setSuccessor(0, FalseDest); + BI.setSuccessor(1, TrueDest); + return &BI; + } return 0; }