Skip to content

Commit 34caf53

Browse files
committed
[Reassociate] Use early returns in a couple places to reduce indentation and improve readability. NFC
llvm-svn: 305946
1 parent 99a2e89 commit 34caf53

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,19 +1136,19 @@ static Value *OptimizeAndOrXor(unsigned Opcode,
11361136
/// instruction. There are two special cases: 1) if the constant operand is 0,
11371137
/// it will return NULL. 2) if the constant is ~0, the symbolic operand will
11381138
/// be returned.
1139-
static Value *createAndInstr(Instruction *InsertBefore, Value *Opnd,
1139+
static Value *createAndInstr(Instruction *InsertBefore, Value *Opnd,
11401140
const APInt &ConstOpnd) {
1141-
if (!ConstOpnd.isNullValue()) {
1142-
if (!ConstOpnd.isAllOnesValue()) {
1143-
Instruction *I = BinaryOperator::CreateAnd(
1144-
Opnd, ConstantInt::get(Opnd->getType(), ConstOpnd), "and.ra",
1145-
InsertBefore);
1146-
I->setDebugLoc(InsertBefore->getDebugLoc());
1147-
return I;
1148-
}
1141+
if (ConstOpnd.isNullValue())
1142+
return nullptr;
1143+
1144+
if (ConstOpnd.isAllOnesValue())
11491145
return Opnd;
1150-
}
1151-
return nullptr;
1146+
1147+
Instruction *I = BinaryOperator::CreateAnd(
1148+
Opnd, ConstantInt::get(Opnd->getType(), ConstOpnd), "and.ra",
1149+
InsertBefore);
1150+
I->setDebugLoc(InsertBefore->getDebugLoc());
1151+
return I;
11521152
}
11531153

11541154
// Helper function of OptimizeXor(). It tries to simplify "Opnd1 ^ ConstOpnd"
@@ -1164,24 +1164,24 @@ bool ReassociatePass::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1,
11641164
// = ((x | c1) ^ c1) ^ (c1 ^ c2)
11651165
// = (x & ~c1) ^ (c1 ^ c2)
11661166
// It is useful only when c1 == c2.
1167-
if (Opnd1->isOrExpr() && !Opnd1->getConstPart().isNullValue()) {
1168-
if (!Opnd1->getValue()->hasOneUse())
1169-
return false;
1167+
if (!Opnd1->isOrExpr() || Opnd1->getConstPart().isNullValue())
1168+
return false;
11701169

1171-
const APInt &C1 = Opnd1->getConstPart();
1172-
if (C1 != ConstOpnd)
1173-
return false;
1170+
if (!Opnd1->getValue()->hasOneUse())
1171+
return false;
11741172

1175-
Value *X = Opnd1->getSymbolicPart();
1176-
Res = createAndInstr(I, X, ~C1);
1177-
// ConstOpnd was C2, now C1 ^ C2.
1178-
ConstOpnd ^= C1;
1173+
const APInt &C1 = Opnd1->getConstPart();
1174+
if (C1 != ConstOpnd)
1175+
return false;
11791176

1180-
if (Instruction *T = dyn_cast<Instruction>(Opnd1->getValue()))
1181-
RedoInsts.insert(T);
1182-
return true;
1183-
}
1184-
return false;
1177+
Value *X = Opnd1->getSymbolicPart();
1178+
Res = createAndInstr(I, X, ~C1);
1179+
// ConstOpnd was C2, now C1 ^ C2.
1180+
ConstOpnd ^= C1;
1181+
1182+
if (Instruction *T = dyn_cast<Instruction>(Opnd1->getValue()))
1183+
RedoInsts.insert(T);
1184+
return true;
11851185
}
11861186

11871187

0 commit comments

Comments
 (0)