[PATCH] D41554: [InstSimplify] Missed optimization in math expression: (x+x)/x == 2

Dmitry Venikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 24 04:17:41 PST 2017


Quolyk added inline comments.


================
Comment at: lib/Analysis/InstructionSimplify.cpp:997
+  if ((IsSigned && match(Op0, m_NSWShl(m_Specific(Op1), m_One()))) ||
+      (!IsSigned && match(Op0, m_Shl(m_Specific(Op1), m_One())))) {
+    return ConstantInt::get(Op0->getType(), 2);
----------------
grandinj wrote:
> majnemer wrote:
> > I believe this needs to be m_NUWShl.
> Is that not trivially extendable to 
> 
>     (X << C) / X -> C
> 
> for any 
> 
>     C <= bitwidth(X)
> 
> ?
I think that would be pow(2, C), not just C


https://reviews.llvm.org/D41554





More information about the llvm-commits mailing list