[PATCH] Compute known bits using invariants

hfinkel at anl.gov hfinkel at anl.gov
Sun Jul 13 16:41:12 PDT 2014


Hi chandlerc,

This is a large patch, but only because I had to add some (optional) parameters to computeKnownBits and friends. These functions now (optionally) take a "context" instruction pointer and also a DomTree pointer, and most of the changes are just to pass this new information when it is easily available from InstSimplify, InstCombine, etc.

The significant changes are all in ValueTracking. Two main changes: First, as with the rest of the code, new parameters need to be passed around. To make this easier, I grouped them into a structure, and I made internal static versions of the relevant functions that take this structure as a parameter. The new code does as you might expect, it looks for invariant expressions that make use of the value we're trying to learn something about, attempts to pattern match that expression, and uses the result if successful.

Part of the structure being passed around inside ValueTracking is a set of already-considered invariants. This is to prevent a query using, for example, the invariant(a == b), to recurse on itself. The context and DT params are used to find applicable invariants. An invariant needs to dominate the context instruction, or come after it deterministically. In this latter case we only handle the specific case where both the invariant and the context instruction are in the same block, and we need to exclude invariants from being used to simplify their own ephemeral values (those which contribute only to the invariant) because otherwise the invariant would prove its feeding comparison trivial and would be removed.

http://reviews.llvm.org/D4490

Files:
  include/llvm/Analysis/InstructionSimplify.h
  include/llvm/Analysis/ValueTracking.h
  include/llvm/Transforms/Utils/Local.h
  lib/Analysis/BasicAliasAnalysis.cpp
  lib/Analysis/InstructionSimplify.cpp
  lib/Analysis/Lint.cpp
  lib/Analysis/ScalarEvolution.cpp
  lib/Analysis/ValueTracking.cpp
  lib/Transforms/InstCombine/InstCombine.h
  lib/Transforms/InstCombine/InstCombineAddSub.cpp
  lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  lib/Transforms/InstCombine/InstCombineCasts.cpp
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  lib/Transforms/InstCombine/InstCombineShifts.cpp
  lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  lib/Transforms/InstCombine/InstructionCombining.cpp
  lib/Transforms/Scalar/MemCpyOptimizer.cpp
  lib/Transforms/Utils/InlineFunction.cpp
  lib/Transforms/Utils/Local.cpp
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/InstCombine/invariants-loop-align.ll
  test/Transforms/InstCombine/invariants.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4490.11359.patch
Type: text/x-patch
Size: 169383 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140713/b543fa65/attachment.bin>


More information about the llvm-commits mailing list