[PATCH] [InstCombine/InstSimplify] Move ashr optimization from Instcombine to Instsimplify
suyog
suyog.sarda at samsung.com
Wed Jun 18 06:19:04 PDT 2014
Hi Nick,
Added supporting testcase.
Please if you could commit it for me if it looks
good to you.
Thanks,
Suyog
http://reviews.llvm.org/D4102
Files:
lib/Analysis/InstructionSimplify.cpp
lib/Transforms/InstCombine/InstCombineShifts.cpp
test/Transforms/InstSimplify/ashr-nop.ll
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;
}
Index: test/Transforms/InstSimplify/ashr-nop.ll
===================================================================
--- test/Transforms/InstSimplify/ashr-nop.ll
+++ test/Transforms/InstSimplify/ashr-nop.ll
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instsimplify -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
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4102.10560.patch
Type: text/x-patch
Size: 1521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140618/ce8521b5/attachment.bin>
More information about the llvm-commits
mailing list