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

suyog suyog.sarda at samsung.com
Wed Jul 16 23:37:01 PDT 2014


Closed by commit rL213231 (authored by @suyog).

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D4102

Files:
  llvm/trunk/lib/Analysis/InstructionSimplify.cpp
  llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
  llvm/trunk/test/Transforms/InstCombine/ashr-nop.ll
  llvm/trunk/test/Transforms/InstSimplify/ashr-nop.ll

Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -815,10 +815,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;
 }
Index: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp
@@ -1346,6 +1346,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: llvm/trunk/test/Transforms/InstCombine/ashr-nop.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/ashr-nop.ll
+++ llvm/trunk/test/Transforms/InstCombine/ashr-nop.ll
@@ -1,8 +0,0 @@
-; RUN: opt < %s -instcombine -S | not grep ashr
-
-define i32 @foo(i32 %x) {
-  %o = and i32 %x, 1
-  %n = add i32 %o, -1
-  %t = ashr i32 %n, 17
-  ret i32 %t
-}
Index: llvm/trunk/test/Transforms/InstSimplify/ashr-nop.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/ashr-nop.ll
+++ llvm/trunk/test/Transforms/InstSimplify/ashr-nop.ll
@@ -0,0 +1,10 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+; CHECK-LABEL: @foo
+; CHECK-NOT: ashr
+define i32 @foo(i32 %x) {
+ %o = and i32 %x, 1
+ %n = add i32 %o, -1
+ %t = ashr i32 %n, 17
+ ret i32 %t
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4102.11559.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140717/c22dbfd4/attachment.bin>


More information about the llvm-commits mailing list