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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 05:01:59 PDT 2018


lebedev.ri added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2026-2036
+  // 1st: Check for desired pattern
+  if (match(&I, m_c_Or(m_And(m_OneUse(m_Shift(m_Value(X), m_APInt(ShftAmt))),
+                             m_APInt(ShAndC)),
+                       m_And(m_Deferred(X), m_APInt(AndC))))) {
+    // 2nd: Find out which AND is which
+    BinaryOperator *And = cast<BinaryOperator>(A), *Shift, *ShtAnd;
+    if (And->getOperand(0) != X) {
----------------
See `m_CombineAnd()`.


================
Comment at: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2042-2046
+      OtherMask = AndC->shl(ShftAmt->getZExtValue());
+    else if (Instruction::LShr == Opcode)
+      OtherMask = AndC->lshr(ShftAmt->getZExtValue());
+    else
+      OtherMask = AndC->ashr(ShftAmt->getZExtValue());
----------------
This will miscompile with types larger than i64.
Please add tests.


https://reviews.llvm.org/D49229





More information about the llvm-commits mailing list