[PATCH] D75801: [InstCombine] Remove known bits constant folding (WIP)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 7 02:12:42 PST 2020


nikic created this revision.
nikic added reviewers: spatel, lebedev.ri, xbolva00.
Herald added subscribers: llvm-commits, arphaman.
Herald added a project: LLVM.

If ExpensiveCombines is enabled (which is the case with `-O3` on the legacy PM and always on the new PM), InstCombine tries to compute the known bits of all instructions in the hope that all bits end up being known. This is the most expensive individual part of InstCombine.

How effective is it? If we add some statistics on how often the constant folding succeeds and how many KnownBits calculations are performed and run test-suite we get:

  "instcombine.NumConstPropKnownBits": 642,
  "instcombine.NumConstPropKnownBitsComputed": 18744965,

In other words, we get one fold for every 30000 KnownBits calculations. However, the truth is actually much worse: Currently, known bits are computed before performing other folds, so there is a high chance that cases that get folded by known bits would also have been handled by other folds.

What happens if we compute known bits after all other folds (hacky implementation: https://gist.github.com/nikic/751f25b3b9d9e0860db5dde934f70f46)?

  "instcombine.NumConstPropKnownBits": 0,
  "instcombine.NumConstPropKnownBitsComputed": 18105547,

So it turns out despite doing 18 million known bits calculations, the known bits fold does not do anything useful on test-suite. I was originally planning to move this into AggressiveInstCombine so it only runs once in the pipeline, but seeing this, I think we're better off removing it entirely.

There are some regressions in LLVM tests that should be addressed though (thus WIP). I'll comment on them inline.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75801

Files:
  lib/Transforms/InstCombine/InstructionCombining.cpp
  test/Transforms/InstCombine/all-bits-shift.ll
  test/Transforms/InstCombine/assume.ll
  test/Transforms/InstCombine/expensive-combines.ll
  test/Transforms/InstCombine/out-of-bounds-indexes.ll
  test/Transforms/InstCombine/phi-shifts.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75801.248914.patch
Type: text/x-patch
Size: 9436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200307/3000e465/attachment.bin>


More information about the llvm-commits mailing list