[PATCH] D42341: [LLVM][PASSES][InstSimplify] Add (X << Y) % X -> 0
Anton Bikineev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 20 18:39:49 PST 2018
AntonBikineev created this revision.
AntonBikineev added reviewers: spatel, lebedev.ri.
@spatel
I've added that missing fold you mentioned in https://reviews.llvm.org/D42032. I'll also quickly add new tests in a separated patch and rebase this patch as soon as those tests get committed.
Repository:
rL LLVM
https://reviews.llvm.org/D42341
Files:
lib/Analysis/InstructionSimplify.cpp
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -1040,6 +1040,13 @@
match(Op0, m_URem(m_Value(), m_Specific(Op1)))))
return Op0;
+ // (X << Y) % X -> 0
+ if ((Opcode == Instruction::SRem &&
+ match(Op0, m_NSWShl(m_Specific(Op1), m_Value()))) ||
+ (Opcode == Instruction::URem &&
+ match(Op0, m_NUWShl(m_Specific(Op1), m_Value()))))
+ return Constant::getNullValue(Op0->getType());
+
// If the operation is with the result of a select instruction, check whether
// operating on either branch of the select always yields the same value.
if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42341.130788.patch
Type: text/x-patch
Size: 780 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180121/1e4540a5/attachment.bin>
More information about the llvm-commits
mailing list