From f1aa0d7af272f5d7198c706c60214f7555aca391 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 15 Apr 2018 15:39:57 +0000 Subject: [PATCH] [InstCombine] simplify code for distributive property; NFCI llvm-svn: 330096 --- .../InstCombine/InstructionCombining.cpp | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index a91950e..c749273 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -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 -- 2.7.4