[PATCH] D49229: [InstCombine] Fold redundant masking operations of shifted value

Diogo N. Sampaio via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 02:23:55 PDT 2018


dnsampaio added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2028
+  // 1st: Check for desired pattern
+  if (match(&I, m_c_Or(m_And(m_OneUse(m_CombineAnd(
+                                 m_Shift(m_Value(X), m_APInt(ShftAmt)),
----------------
dnsampaio wrote:
> dnsampaio wrote:
> > lebedev.ri wrote:
> > > We create two new instructions, but we only make sure that one instruction (`Shift`, i think?) goes away.
> > > The outermost `m_And()` should too be `m_OneUse()`, i think.
> > Actually no. We are eliminating one of the and operations.
> > ```
> > x1 = v & 0xFF00
> > x2 = v >> 8
> > x3 = x2 & 0xFF
> > or  = x1 | x3
> > x4 = x1 + 5;
> > ```
> > We eliminate x3 and it becomes
> > ```
> > x1 = v & 0xFF00
> > x3' = x1 >> 8
> > or'  = x3 | x1
> > x4 = x1 + 5;
> > ```
> > x1 can have more than 1 user. x3 will be remove by dead-code elimination. We replace or.
> Small correction:
> ```
> x1 = v & 0xFF00
> x3' = x1 >> 8
> or'  = x3' | x1
> x4 = x1 + 5
> ```
But indeed, we must replace all uses of the innermost AND with the new shift.


https://reviews.llvm.org/D49229





More information about the llvm-commits mailing list