[PATCH] D65147: [SimplifyCFG] FoldTwoEntryPHINode(): don't bailout on i1 PHI's if we can hoist a 'not' from incoming values

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 07:24:42 PDT 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: craig.topper, spatel, fhahn, nikic.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.
lebedev.ri added a parent revision: D65144: [InstCombine] Fold '((%x * %y) u/ %x) != %y' to '@llvm.umul.with.overflow' + overflow bit extraction.
lebedev.ri added a child revision: D65148: [SimplifyCFG] Bump phi-node-folding-threshold from 2 to 3.

As it can be seen in the tests in D65143 <https://reviews.llvm.org/D65143>, even though we have formed an '@llvm.umul.with.overflow'
and got rid of potential for division-by-zero, the control flow remains, we still have that branch.

We have this condition:

  // Don't fold i1 branches on PHIs which contain binary operators
  // These can often be turned into switches and other things.
  if (PN->getType()->isIntegerTy(1) &&
      (isa<BinaryOperator>(PN->getIncomingValue(0)) ||
       isa<BinaryOperator>(PN->getIncomingValue(1)) ||
       isa<BinaryOperator>(IfCond)))
    return false;

which was added back in rL121764 <https://reviews.llvm.org/rL121764> to help with `select` formation i think?

Ignoring the `-phi-node-folding-threshold` issue, that check prevents
us to flatten the CFG here, even though we know we no longer need that guard
and will be able to drop everything but the '@llvm.umul.with.overflow' + `not`.

As it can be seen from tests, we end here because the `not` is being
sinked into the PHI's incoming values by InstCombine,
so we can't workaround this by hoisting it to after PHI.

Thus i suggest that we relax that check to not bailout if we'd get to hoist the `not`.
The `-phi-node-folding-threshold` issue is to be resolved in a follow-up.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65147

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/PhaseOrdering/unsigned-multiply-overflow-check.ll
  llvm/test/Transforms/SimplifyCFG/unsigned-multiplication-will-overflow.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65147.211289.patch
Type: text/x-patch
Size: 7937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190723/3cc07603/attachment.bin>


More information about the llvm-commits mailing list