From: Chris Lattner Date: Thu, 9 May 2002 20:11:54 +0000 (+0000) Subject: Handle setcc , 0 instructions, Global pointers are never null! X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=53a5b57737818244515351cf4d147fd2bdd0bc51;p=oota-llvm.git Handle setcc , 0 instructions, Global pointers are never null! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2582 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 9625398017a..385c07004d4 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -343,17 +343,31 @@ Instruction *InstCombiner::visitXor(BinaryOperator *I) { return Changed ? I : 0; } +// isTrueWhenEqual - Return true if the specified setcondinst instruction is +// true when both operands are equal... +// +static bool isTrueWhenEqual(Instruction *I) { + return I->getOpcode() == Instruction::SetEQ || + I->getOpcode() == Instruction::SetGE || + I->getOpcode() == Instruction::SetLE; +} + Instruction *InstCombiner::visitSetCondInst(BinaryOperator *I) { if (I->use_empty()) return 0; // Don't fix dead instructions... bool Changed = SimplifyBinOp(I); // setcc X, X if (I->getOperand(0) == I->getOperand(1)) { - bool NewVal = I->getOpcode() == Instruction::SetEQ || - I->getOpcode() == Instruction::SetGE || - I->getOpcode() == Instruction::SetLE; AddUsesToWorkList(I); // Add all modified instrs to worklist - I->replaceAllUsesWith(ConstantBool::get(NewVal)); + I->replaceAllUsesWith(ConstantBool::get(isTrueWhenEqual(I))); + return I; + } + + // setcc , 0 - Global value addresses are never null! + if (isa(I->getOperand(0)) && + isa(I->getOperand(1))) { + AddUsesToWorkList(I); // Add all modified instrs to worklist + I->replaceAllUsesWith(ConstantBool::get(!isTrueWhenEqual(I))); return I; }