From 2e0fb39d87ab4c1bed122e5c4cb6a31b832d9bb7 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 8 Oct 2002 16:16:40 +0000 Subject: [PATCH] Fold ashr -1, X into -1 llvm-svn: 4070 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 6 ++++++ 1 file changed, 6 insertions(+) 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; }