[PATCH] D42032: [LLVM][PASSES][InstCombine] Fix (a + a + ...) / a cases

Anton Bikineev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 13 20:45:49 PST 2018


AntonBikineev created this revision.

This quickly fixes 35709 <https://bugs.llvm.org/show_bug.cgi?id=35709> . Please note that this is my first patch to the llvm passes infrastructure, so take it easy - I'm pretty sure I've done something dumb in this 3-liner :)


Repository:
  rL LLVM

https://reviews.llvm.org/D42032

Files:
  lib/Analysis/InstructionSimplify.cpp


Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -992,6 +992,11 @@
         return X;
   }
 
+  // (X << C1) / X -> 1 << C1
+  const APInt *C = nullptr;
+  if (match(Op0, m_Shl(m_Value(X), m_APInt(C))) && X == Op1)
+    return ConstantInt::get(X->getType(), APInt(C->getBitWidth(), 1).shl(*C));
+
   // (X rem Y) / Y -> 0
   if ((IsSigned && match(Op0, m_SRem(m_Value(), m_Specific(Op1)))) ||
       (!IsSigned && match(Op0, m_URem(m_Value(), m_Specific(Op1)))))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42032.129773.patch
Type: text/x-patch
Size: 611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180114/98f19b80/attachment.bin>


More information about the llvm-commits mailing list