[InstCombine] simplify code for distributive property; NFCI

llvm-svn: 330096
This commit is contained in:
Sanjay Patel 2018-04-15 15:39:57 +00:00
parent 525d4122c9
commit f1aa0d7af2
1 changed files with 3 additions and 19 deletions

View File

@ -487,28 +487,12 @@ static bool RightDistributesOverLeft(Instruction::BinaryOps LOp,
if (Instruction::isCommutative(ROp))
return LeftDistributesOverRight(ROp, LOp);
switch (LOp) {
default:
return false;
// (X >> Z) & (Y >> Z) -> (X&Y) >> Z for all shifts.
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
// (X >> Z) ^ (Y >> Z) -> (X^Y) >> Z for all shifts.
case Instruction::And:
case Instruction::Or:
case Instruction::Xor:
switch (ROp) {
default:
return false;
case Instruction::Shl:
case Instruction::LShr:
case Instruction::AShr:
return true;
}
}
// (X {&|^} Y) >> Z --> (X >> Z) {&|^} (Y >> Z) for all shifts.
return Instruction::isBitwiseLogicOp(LOp) && Instruction::isShift(ROp);
// TODO: It would be nice to handle division, aka "(X + Y)/Z = X/Z + Y/Z",
// but this requires knowing that the addition does not overflow and other
// such subtleties.
return false;
}
/// This function returns identity value for given opcode, which can be used to