diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index ec3ea074d929..f0e639742dc2 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -503,6 +503,12 @@ Instruction *InstCombiner::visitShiftInst(Instruction &I) { return BinaryOperator::create(Instruction::Add, Op0, Op0, I.getName()); } + + // shr int -1, X = -1 (for any arithmetic shift rights of ~0) + if (ConstantSInt *CSI = dyn_cast(Op0)) + if (I.getOpcode() == Instruction::Shr && CSI->isAllOnesValue()) + return ReplaceInstUsesWith(I, CSI); + return 0; }