Commit Graph

7275 Commits

Author SHA1 Message Date
Chris Lattner
fcf8d7c73d remove a fixed fixme
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120474 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 22:18:11 +00:00
Chris Lattner
7c80c15a8b Make DeleteDeadInstruction be a static function, move some code around.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120471 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 21:58:14 +00:00
Chris Lattner
d8d35316de switch RemoveAccessedObjects to use AliasAnalysis::Location to simplify
the code.  We now get accurate sizes on Loads, though it surely doesn't
matter in practice.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120469 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 21:47:58 +00:00
Chris Lattner
42cb684f8d two improvements to RemoveAccessedObjects:
1. if the underlying pointer passed in can be resolved
   to any argument or alloca, then we don't need to scan.
   Previously we would only avoid the scan if the alloca
   or byval was actually considered dead.
2. The dead store processing code is itself completely
   dead and didn't handle volatile stores right anyway,
   so delete it.  This allows simplifying the interface
   to RemoveAccessedObjects.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120467 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 21:38:30 +00:00
Chris Lattner
5fb0fb397c remove the "undead" terminology, which is nonstandard and never
made sense to me.  We now have a set of dead stack objects, and
they become live when loaded.  Fix a theoretical problem where
we'd pass in the wrong pointer to the alias query.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120465 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 21:32:12 +00:00
Chris Lattner
86dc6c08cf move call handling in handleEndBlock up a bit, and simplify it.
If the call might read all the allocas, stop scanning early.
Convert a vector to smallvector, shrink SmallPtrSet to 16 instead
of 64 to avoid crazy linear scans.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120463 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 21:18:46 +00:00
Dale Johannesen
f619b5a665 Avoid exponential growth of a table. It feels like
there should be a better way to do this.  PR 8679.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120457 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 20:23:21 +00:00
Chris Lattner
83d6759403 various cleanups and code simplification
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120454 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 19:48:15 +00:00
Chris Lattner
e3c611085e make getPointerSize a static function. Add ivars to DSE for
AA and MD pass info instead of using getAnalysis<> all over.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120453 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 19:34:42 +00:00
Chris Lattner
9801651193 reduce indentation, clean up TD use a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120452 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 19:28:23 +00:00
Chris Lattner
55ee75d571 enhance isRemovable to refuse to delete volatile mem transfers
now that DSE hacks on them.  This fixes a regression I introduced,
by generalizing DSE to hack on transfers.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120445 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 19:12:10 +00:00
Chris Lattner
cf82dc376a Rewrite the main DSE loop to be written in terms of reasoning
about pairs of AA::Location's instead of looking for MemDep's
"Def" predicate.  This is more powerful and general, handling
memset/memcpy/store all uniformly, and implementing PR8701 and
probably obsoleting parts of memcpyoptimizer.

This also fixes an obscure bug with init.trampoline and i8
stores, but I'm not surprised it hasn't been hit yet.  Enhancing
init.trampoline to carry the size that it stores would allow
DSE to be much more aggressive about optimizing them.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120406 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 07:23:21 +00:00
Anders Carlsson
303023d9ff Add a puts optimization that converts puts() to putchar('\n').
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120398 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 06:19:18 +00:00
Chris Lattner
bbdc3703a3 rename a function and reduce some indentation, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120391 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 05:30:45 +00:00
Chris Lattner
d6f02d1fff remove the pointless check of MemoryUseIntrinsic from
is trivially dead, since these have side effects.  This makes the
(misnamed) MemoryUseIntrinsic class dead, so remove it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120382 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 02:03:47 +00:00
Chris Lattner
72987a2742 rename doesClobberMemory -> hasMemoryWrite to be more specific, and
remove an actively-wrong comment.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120378 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 01:37:52 +00:00
Chris Lattner
1ab4285b72 clean up handling of 'free', detangling it from everything else.
It can be seriously improved, but at least now it isn't intertwined
with the other logic.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120377 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 01:28:33 +00:00
Chris Lattner
201d1e56bb Teach basicaa that memset's modref set is at worst "mod" and never
contains "ref".

Enhance DSE to use a modref query instead of a store-specific hack
to generalize the "ignore may-alias stores" optimization to handle
memset and memcpy.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120368 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 00:28:45 +00:00
Chris Lattner
184d1ba738 my previous patch would cause us to start deleting some volatile
stores, fix and add a testcase.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120363 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 00:12:39 +00:00
Chris Lattner
0f53f592ad two changes to DSE that shouldn't affect anything:
1. Don't bother trying to optimize:

lifetime.end(ptr)
store(ptr)

as it is undefined, and therefore shouldn't exist.

2. Move the 'storing a loaded pointer' xform up, simplifying
  the may-aliased store code.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120359 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 00:01:19 +00:00
Chris Lattner
7a0b4fdd14 prune an llvmcontext include and simplify some code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120347 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-29 23:35:33 +00:00
Chris Lattner
e9e973018a fix PR8677, patch by Jakub Staszak!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120325 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-29 21:59:31 +00:00
Frits van Bommel
34ceb4db22 Transform (extractvalue (load P), ...) to (load (gep P, 0, ...)) if the load has no other uses, shrinking the load.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120323 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-29 21:56:20 +00:00
Owen Anderson
35bf4d6d80 Second attempt at fixing the performance regressions introduced
by my recent GVN improvement.  Looking through a single layer of
PHI nodes when attempting to sink GEPs, we need to iteratively
look through arbitrary PHI nests.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120202 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-27 08:15:55 +00:00
Nick Lewycky
081f80078d Treat a call of function pointer like a load of the pointer when considering
whether the pointer can be replaced with the global variable it is a copy of.
Fixes PR8680.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120126 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-24 22:04:20 +00:00
Duncan Sands
50f2625b22 Rename SimplifyDistributed to the more meaningfull name SimplifyByFactorizing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120051 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 20:42:39 +00:00
Benjamin Kramer
c21a821e9f The srem -> urem transform is not safe for any divisor that's not a power of two.
E.g. -5 % 5 is 0 with srem and 1 with urem.

Also addresses Frits van Bommel's comments.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120049 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 20:33:57 +00:00
Duncan Sands
b6133d1483 Replace calls to ConstantFoldInstruction with calls to SimplifyInstruction
in two places that are really interested in simplified instructions, not
constants.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120044 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 20:26:33 +00:00
Duncan Sands
0f827639df Constant folding here is pointless, because InstructionSimplify
(which does constant folding and more) is called a few lines
later.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120042 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 20:24:21 +00:00
Benjamin Kramer
b70ebd2aa3 InstCombine: Reduce "X shift (A srem B)" to "X shift (A urem B)" iff B is positive.
This allows to transform the rem in "1 << ((int)x % 8);" to an and.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120028 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 18:52:42 +00:00
Duncan Sands
e104f1bccb Propagate LeftDistributes and RightDistributes into their only uses.
Stylistic improvement suggested by Frits van Bommel.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120026 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 15:28:14 +00:00
Duncan Sands
c2b1c0b85d Fix typo pointed out by Frits van Bommel and Marius Wachtler.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120025 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 15:25:34 +00:00
Duncan Sands
5057f38141 Exploit distributive laws (eg: And distributes over Or, Mul over Add, etc) in a
fairly systematic way in instcombine.  Some of these cases were already dealt
with, in which case I removed the existing code.  The case of Add has a bunch of
funky logic which covers some of this plus a few variants (considers shifts to be
a form of multiplication), which I didn't touch.  The simplification performed is:
A*B+A*C -> A*(B+C).  The improvement is to do this in cases that were not already
handled [such as A*B-A*C -> A*(B-C), which was reported on the mailing list], and
also to do it more often by not checking for "only one use" if "B+C" simplifies.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120024 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 14:23:47 +00:00
Chris Lattner
79b967bd9f duncan's spider sense was right, I completely reversed the condition
on this instcombine xform.  This fixes a miscompilation of 403.gcc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119988 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 02:42:04 +00:00
Benjamin Kramer
93f8455d73 InstCombine: Implement X - A*-B -> X + A*B.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119984 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 20:31:27 +00:00
Duncan Sands
a63395a30f If a GEP index simply advances by multiples of a type of zero size,
then replace the index with zero.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119974 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 16:32:50 +00:00
Duncan Sands
85bbff6c94 Move the "gep undef" -> "undef" transform from instcombine to
InstructionSimplify.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119970 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 13:42:49 +00:00
Duncan Sands
b05099bf42 Don't keep track of inserted phis in PromoteMemoryToRegister: the information
is never used.  Patch by Cameron Zwarich.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119963 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 09:41:24 +00:00
Chris Lattner
6ffdd45d86 fix comment
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119948 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 19:05:34 +00:00
Chris Lattner
604f6fe553 rework some DSE paths to use the newly-public "getPointerDependencyFrom"
method in MemDep instead of inserting an instruction, doing a query,
then removing it.  Neither operation is effectively cached.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119930 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 08:06:10 +00:00
Chris Lattner
f6f1f062cc implement PR8576, deleting dead stores with intervening may-alias stores.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119927 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 07:34:32 +00:00
Chris Lattner
75d8f599e7 optimize:
void a(int x) { if (((1<<x)&8)==0) b(); }

into "x != 3", which occurs over 100 times in 403.gcc but in no
other program in llvm-test.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119922 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 06:44:42 +00:00
Chris Lattner
2f5f90ad3e Implement PR8644: forwarding a memcpy value to a byval,
allowing the memcpy to be eliminated.

Unfortunately, the requirements on byval's without explicit 
alignment are really weak and impossible to predict in the 
mid-level optimizer, so this doesn't kick in much with current
frontends.  The fix is to change clang to set alignment on all
byval arguments.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119916 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 00:28:59 +00:00
Benjamin Kramer
f601d6df6f Simplify code. No change in functionality.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119908 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-20 18:43:35 +00:00
Owen Anderson
68c26396c0 Document the new GVN number table structure.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119865 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-19 22:48:40 +00:00
Owen Anderson
d2f4174fcc When folding addressing modes in CodeGenPrepare, attempt to look through PHI nodes
if all the operands of the PHI are equivalent.  This allows CodeGenPrepare to undo
unprofitable PRE transforms.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119853 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-19 22:15:03 +00:00
Duncan Sands
d0c6f3dafd Factor code for testing whether replacing one value with another
preserves LCSSA form out of ScalarEvolution and into the LoopInfo
class.  Use it to check that SimplifyInstruction simplifications
are not breaking LCSSA form.  Fixes PR8622.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119727 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 19:59:41 +00:00
Owen Anderson
a04a0649e1 Completely rework the datastructure GVN uses to represent the value number to leader mapping. Previously,
this was a tree of hashtables, and a query recursed into the table for the immediate dominator ad infinitum
if the initial lookup failed.  This led to really bad performance on tall, narrow CFGs.

We can instead replace it with what is conceptually a multimap of value numbers to leaders (actually
represented by a hashtable with a list of Value*'s as the value type), and then
determine which leader from that set to use very cheaply thanks to the DFS numberings maintained by
DominatorTree.  Because there are typically few duplicates of a given value, this scan tends to be
quite fast.  Additionally, we use a custom linked list and BumpPtr allocation to avoid any unnecessary
allocation in representing the value-side of the multimap.

This change brings with it a 15% (!) improvement in the total running time of GVN on 403.gcc, which I
think is pretty good considering that includes all the "real work" being done by MemDep as well.

The one downside to this approach is that we can no longer use GVN to perform simple conditional progation,
but that seems like an acceptable loss since we now have LVI and CorrelatedValuePropagation to pick up
the slack.  If you see conditional propagation that's not happening, please file bugs against LVI or CVP.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119714 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 18:32:40 +00:00
Chris Lattner
d528be6636 slightly simplify code and substantially improve comment. Instead of
saying "it would be bad", give an example of what is going on.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119695 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 08:07:09 +00:00
Chris Lattner
5a7aeaa019 remove a pointless restriction from memcpyopt. It was
refusing to optimize two memcpy's like this:

copy A <- B
copy C <- A

if it couldn't prove that noalias(B,C).  We can eliminate
the copy by producing a memmove instead of memcpy.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119694 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 08:00:57 +00:00