[PATCH] [InstCombine/InstSimplify] Move ashr optimization from Instcombine to Instsimplify

suyog suyog.sarda at samsung.com
Wed Jun 11 06:20:45 PDT 2014


Hi rafael, majnemer, bkramer,

This patch moves the following optimization from visitAShr to SimplifyAShrInst :

  // Arithmetic shifting an all-sign-bit value is a no-op.
  unsigned NumSignBits = ComputeNumSignBits(Op0);
  if (NumSignBits == Op0->getType()->getScalarSizeInBits())
    return Op0;

No regression observed. No functionality change.
This patch is part of refactoring code which i have planned along with Rahul Jain.

Primarily, we are targeting code which returns simply value instead of new instruction.

Any suggestions/help/pointers on the same will be very much appreciated.

Please help review this patch.

Thanks,
Suyog

http://reviews.llvm.org/D4102

Files:
  lib/Analysis/InstructionSimplify.cpp
  lib/Transforms/InstCombine/InstCombineShifts.cpp

Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -1436,6 +1436,11 @@
       cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap())
     return X;
 
+  // Arithmetic shifting an all-sign-bit value is a no-op.
+  unsigned NumSignBits = ComputeNumSignBits(Op0);
+  if (NumSignBits == Op0->getType()->getScalarSizeInBits())
+    return Op0;
+
   return nullptr;
 }
 
Index: lib/Transforms/InstCombine/InstCombineShifts.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -820,10 +820,5 @@
                         APInt::getSignBit(I.getType()->getScalarSizeInBits())))
     return BinaryOperator::CreateLShr(Op0, Op1);
 
-  // Arithmetic shifting an all-sign-bit value is a no-op.
-  unsigned NumSignBits = ComputeNumSignBits(Op0);
-  if (NumSignBits == Op0->getType()->getScalarSizeInBits())
-    return ReplaceInstUsesWith(I, Op0);
-
   return nullptr;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4102.10321.patch
Type: text/x-patch
Size: 1134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140611/a4640a70/attachment.bin>


More information about the llvm-commits mailing list