[Reassociate] Use early returns in a couple places to reduce indentation and improve readability. NFC

llvm-svn: 305946
This commit is contained in:
Craig Topper 2017-06-21 19:39:35 +00:00
parent 99a2e89920
commit 34caf5396f
1 changed files with 26 additions and 26 deletions

View File

@ -1136,19 +1136,19 @@ static Value *OptimizeAndOrXor(unsigned Opcode,
/// instruction. There are two special cases: 1) if the constant operand is 0,
/// it will return NULL. 2) if the constant is ~0, the symbolic operand will
/// be returned.
static Value *createAndInstr(Instruction *InsertBefore, Value *Opnd,
static Value *createAndInstr(Instruction *InsertBefore, Value *Opnd,
const APInt &ConstOpnd) {
if (!ConstOpnd.isNullValue()) {
if (!ConstOpnd.isAllOnesValue()) {
Instruction *I = BinaryOperator::CreateAnd(
Opnd, ConstantInt::get(Opnd->getType(), ConstOpnd), "and.ra",
InsertBefore);
I->setDebugLoc(InsertBefore->getDebugLoc());
return I;
}
if (ConstOpnd.isNullValue())
return nullptr;
if (ConstOpnd.isAllOnesValue())
return Opnd;
}
return nullptr;
Instruction *I = BinaryOperator::CreateAnd(
Opnd, ConstantInt::get(Opnd->getType(), ConstOpnd), "and.ra",
InsertBefore);
I->setDebugLoc(InsertBefore->getDebugLoc());
return I;
}
// Helper function of OptimizeXor(). It tries to simplify "Opnd1 ^ ConstOpnd"
@ -1164,24 +1164,24 @@ bool ReassociatePass::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1,
// = ((x | c1) ^ c1) ^ (c1 ^ c2)
// = (x & ~c1) ^ (c1 ^ c2)
// It is useful only when c1 == c2.
if (Opnd1->isOrExpr() && !Opnd1->getConstPart().isNullValue()) {
if (!Opnd1->getValue()->hasOneUse())
return false;
if (!Opnd1->isOrExpr() || Opnd1->getConstPart().isNullValue())
return false;
const APInt &C1 = Opnd1->getConstPart();
if (C1 != ConstOpnd)
return false;
if (!Opnd1->getValue()->hasOneUse())
return false;
Value *X = Opnd1->getSymbolicPart();
Res = createAndInstr(I, X, ~C1);
// ConstOpnd was C2, now C1 ^ C2.
ConstOpnd ^= C1;
const APInt &C1 = Opnd1->getConstPart();
if (C1 != ConstOpnd)
return false;
if (Instruction *T = dyn_cast<Instruction>(Opnd1->getValue()))
RedoInsts.insert(T);
return true;
}
return false;
Value *X = Opnd1->getSymbolicPart();
Res = createAndInstr(I, X, ~C1);
// ConstOpnd was C2, now C1 ^ C2.
ConstOpnd ^= C1;
if (Instruction *T = dyn_cast<Instruction>(Opnd1->getValue()))
RedoInsts.insert(T);
return true;
}