Fold ashr -1, X into -1
authorChris Lattner <sabre@nondot.org>
Tue, 8 Oct 2002 16:16:40 +0000 (16:16 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 8 Oct 2002 16:16:40 +0000 (16:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4070 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index ec3ea074d929fb084aaa34efd537092ac27b28c9..f0e639742dc2a97dc71ff9da1a133b2fa304a2ac 100644 (file)
@@ -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<ConstantSInt>(Op0))
+    if (I.getOpcode() == Instruction::Shr && CSI->isAllOnesValue())
+      return ReplaceInstUsesWith(I, CSI);
+  
   return 0;
 }