Commit Graph

3215 Commits

Author SHA1 Message Date
Eric Christopher
6a3e305326 Temporarily revert r121100 as it's causing clang to fail
CodeGenCXX/virtual-base-ctor.cpp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121102 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-07 02:41:11 +00:00
Chris Lattner
fb431099c5 fix PR8710 - teach global opt that some constantexprs are too complex to
put in a global variable's initializer.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121100 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-07 01:59:32 +00:00
Frits van Bommel
6033b346e2 Implement jump threading of 'indirectbr' by keeping track of whether we're looking for ConstantInt*s or BlockAddress*s.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121066 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-06 23:36:56 +00:00
Chris Lattner
cc10244d77 Fix PR8728, a miscompilation I recently introduced. When optimizing
memcpy's like:
  memcpy(A, B)
  memcpy(A, C)

we cannot delete the first memcpy as dead if A and C might be aliases.
If so, we actually get:

  memcpy(A, B)
  memcpy(A, A)

which is not correct to transform into:

  memcpy(A, A)

This patch was heavily influenced by Jakub Staszak's patch in PR8728, thanks
Jakub!



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120974 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-06 01:48:06 +00:00
Frits van Bommel
7ac40c3ffa Teach SimplifyCFG to turn
(indirectbr (select cond, blockaddress(@fn, BlockA),
                            blockaddress(@fn, BlockB)))
into
  (br cond, BlockA, BlockB).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120943 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-05 18:29:03 +00:00
Chris Lattner
b5a3196f80 fix a bozo bug I introduced in r119930, causing a miscompile of
20040709-1.c from the gcc testsuite.  I was using the size of a
pointer instead of the pointee.  This fixes rdar://8713376


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120519 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-01 01:24:55 +00:00
Chris Lattner
3161ae1867 Enhance DSE to handle the variable index case in PR8657.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120498 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 23:43:23 +00:00
Chris Lattner
a04096580a teach DSE to use GetPointerBaseWithConstantOffset to analyze
may-aliasing stores that partially overlap with different base
pointers.  This implements PR6043 and the non-variable part of
PR8657


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120485 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 23:05:20 +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
Anders Carlsson
1d06295583 Fix a typo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120394 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 06:03:55 +00:00
Anders Carlsson
2703399041 Rename this test to FPuts.ll since it actually tests fputs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120393 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 05:59:26 +00:00
Chris Lattner
d7b6a989a7 remove a use of llvm-dis
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120383 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 02:04:15 +00:00
Chris Lattner
feea8fb6b4 merge one more away
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120375 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 01:06:43 +00:00
Chris Lattner
8a2dc0233f I already merged partial-overwrite.ll -> PartialStore.ll
Merge context-sensitive.ll -> simple.ll and upgrade it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120374 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 01:05:07 +00:00
Chris Lattner
75aa30bb1c clean up DSE tests, removing some poorly reduced and useless old test,
merging more into other larger .ll files, filecheckizing along the way.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120373 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 01:00:34 +00:00
Chris Lattner
13815d9d3e enhance basicaa to return "Mod" for a memcpy call when the
queried location doesn't overlap the source, and add a testcase.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120370 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-30 00:43:16 +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
Benjamin Kramer
8ad87ab166 Fix some broken CHECK lines.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120332 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-29 22:34:55 +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
Frits van Bommel
d2fe8e0acd Update this test to keep testing the -instcombine transform it's supposed to be testing instead of triggering the improved constant folding for insertvalue and extractvalue.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120319 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-29 20:55:40 +00:00
Frits van Bommel
3ee0af3584 Teach ConstantFoldInstruction() how to fold insertvalue and extractvalue.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120316 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-29 20:36:52 +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
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
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
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
e60d79faf7 Add a rather pointless InstructionSimplify transform, inspired by recent constant
folding improvements: if P points to a type of size zero, turn "gep P, N" into "P".
More generally, if a gep index type has size zero, instcombine could replace the
index with zero, but that is not done here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119942 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 13:53:09 +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
b7dfb970e6 file checkize
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119926 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 07:32:40 +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
Owen Anderson
563d9bdc84 Add a test for CodeGenPrepare's ability to look through PHI nodes when performing
addressing mode folding, introduced in r119853.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119857 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-19 22:34:53 +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
Dan Gohman
ce56262211 Add support for PHI-translating sext, zext, and trunc instructions,
enabling more PRE. PR8586.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119704 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 17:05:13 +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
Chris Lattner
7cac8e1691 filecheckize, this is still not optimal, see PR8643
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119693 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 07:49:32 +00:00
Chris Lattner
6248065194 allow eliminating an alloca that is just copied from an constant global
if it is passed as a byval argument.  The byval argument will just be a
read, so it is safe to read from the original global instead.  This allows
us to promote away the %agg.tmp alloca in PR8582


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119686 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 06:41:51 +00:00
Chris Lattner
a9be1df6d7 enhance the "alloca is just a memcpy from constant global"
to ignore calls that obviously can't modify the alloca
because they are readonly/readnone.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119683 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 06:26:49 +00:00
Chris Lattner
2e61849f45 fix a small oversight in the "eliminate memcpy from constant global"
optimization.  If the alloca that is "memcpy'd from constant" also has
a memcpy from *it*, ignore it: it is a load.  We now optimize the testcase to:

define void @test2() {
  %B = alloca %T
  %a = bitcast %T* @G to i8*
  %b = bitcast %T* %B to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %b, i8* %a, i64 124, i32 4, i1 false)
  call void @bar(i8* %b)
  ret void
}

previously we would generate:

define void @test() {
  %B = alloca %T
  %b = bitcast %T* %B to i8*
  %G.0 = getelementptr inbounds %T* @G, i32 0, i32 0
  %tmp3 = load i8* %G.0, align 4
  %G.1 = getelementptr inbounds %T* @G, i32 0, i32 1
  %G.15 = bitcast [123 x i8]* %G.1 to i8*
  %1 = bitcast [123 x i8]* %G.1 to i984*
  %srcval = load i984* %1, align 1
  %B.0 = getelementptr inbounds %T* %B, i32 0, i32 0
  store i8 %tmp3, i8* %B.0, align 4
  %B.1 = getelementptr inbounds %T* %B, i32 0, i32 1
  %B.12 = bitcast [123 x i8]* %B.1 to i8*
  %2 = bitcast [123 x i8]* %B.1 to i984*
  store i984 %srcval, i984* %2, align 1
  call void @bar(i8* %b)
  ret void
}



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119682 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 06:20:47 +00:00
Chris Lattner
d222e36b49 filecheckize
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119681 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-18 06:16:43 +00:00
Benjamin Kramer
1951a5b721 InstCombine: Add a missing irem identity (X % X -> 0).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119538 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-17 19:11:46 +00:00
Duncan Sands
1845009290 In which I discover the existence of loops. Threading an operation
over a phi node by applying it to each operand may be wrong if the
operation and the phi node are mutually interdependent (the testcase
has a simple example of this).  So only do this transform if it would
be correct to perform the operation in each predecessor of the block
containing the phi, i.e. if the other operands all dominate the phi.
This should fix the FFMPEG snow.c regression reported by İsmail Dönmez.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119347 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-16 12:16:38 +00:00
Duncan Sands
5520089465 Teach InstructionSimplify the trick of skipping incoming phi
values that are equal to the phi itself.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119161 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-15 17:52:45 +00:00
Duncan Sands
503dcc9822 Move PHI tests to phi.ll, out of select.ll.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119153 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-15 16:43:28 +00:00
Duncan Sands
cd6636c737 Teach InstructionSimplify about phi nodes. I chose to have it simply
offload the work to hasConstantValue rather than do something more
complicated (such handling mutually recursive phis) because (1) it is
not clear it is worth it; and (2) if it is worth it, maybe such logic
would be better placed in hasConstantValue.  Adjust some GVN tests
which are now cleaned up much further (eg: all phi nodes are removed).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119043 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-14 13:30:18 +00:00
Chris Lattner
6857373f44 rename test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119033 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-14 07:03:49 +00:00
Chris Lattner
2fe9b6a125 filecheckize, remove an old and useless test
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119032 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-14 07:03:38 +00:00
Chris Lattner
961e588e9d this test is pretty pointless and "propogation" isn't a word (or so Misha claims).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119031 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-14 07:02:03 +00:00
Duncan Sands
dd609e912b Testcase to go along with commit 118923 ("Have GVN simplify instructions
as it goes").  Before -std-compile-opts only got it down to
  %a = tail call i32 @foo(i32 0) readnone
  %x = tail call i32 @foo(i32 %a) readnone
  %y = tail call i32 @foo(i32 %a) readnone
  %z = icmp eq i32 %x, %y
  ret i1 %z
while now -basicaa -gvn alone reduce it to
  %a = call i32 @foo(i32 0) readnone
  %x = call i32 @foo(i32 %a) readnone
  ret i1 true



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119009 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-13 21:33:19 +00:00
Duncan Sands
096aa79276 Generalize the reassociation transform in SimplifyCommutative (now renamed to
SimplifyAssociativeOrCommutative) "(A op C1) op C2" -> "A op (C1 op C2)",
which previously was only done if C1 and C2 were constants, to occur whenever
"C1 op C2" simplifies (a la InstructionSimplify).  Since the simplifying operand
combination can no longer be assumed to be the right-hand terms, consider all of
the possible permutations.  When compiling "gcc as one big file", transform 2
(i.e. using right-hand operands) fires about 4000 times but it has to be said
that most of the time the simplifying operands are both constants.  Transforms
3, 4 and 5 each fired once.  Transform 6, which is an existing transform that
I didn't change, never fired.  With this change, the testcase is now optimized
perfectly with one run of instcombine (previously it required instcombine +
reassociate + instcombine, and it may just have been luck that this worked).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119002 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-13 15:10:37 +00:00
Dan Gohman
720a2ed6d9 Enhance DSE to handle the case where a free call makes more than
one store dead. This is especially noticeable in
SingleSource/Benchmarks/Shootout/objinst.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118875 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-12 02:19:17 +00:00
Dan Gohman
02df7e90cf Filecheckize.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118874 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-12 02:02:39 +00:00
Dan Gohman
4d70a29490 Factor out Instruction::isSafeToSpeculativelyExecute's code for
testing for dereferenceable pointers into a helper function,
isDereferenceablePointer.  Teach it how to reason about GEPs
with simple non-zero indices.

Also eliminate ArgumentPromtion's IsAlwaysValidPointer,
which didn't check for weak externals or out of range gep
indices.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118840 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-11 21:23:25 +00:00
Dan Gohman
075fb5d68f Enhance GVN to do more precise alias queries for non-local memory
references. For example, this allows gvn to eliminate the load in
this example:

  void foo(int n, int* p, int *q) {
    p[0] = 0;
    p[1] = 1;
    if (n) {
      *q = p[0];
    }
  }


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118714 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-10 20:37:15 +00:00
Duncan Sands
a74a58c83b Teach InstructionSimplify how to look through PHI nodes. Since PHI
nodes can be used in loops, this could result in infinite looping
if there is no recursion limit, so add such a limit.  It is also
used for the SelectInst case because in theory there could be an
infinite loop there too if the basic block is unreachable.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118694 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-10 18:23:01 +00:00
Dale Johannesen
201ab3acff When checking that the necessary bits are zero in
order to reduce ((x<<30)>>24) to x<<6, check the
correct bits.  PR 8547.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118665 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-10 01:30:56 +00:00
Dan Gohman
42c31a7073 Make ModRefBehavior a lattice. Use this to clean up AliasAnalysis
chaining and simplify FunctionAttrs' GetModRefBehavior logic.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118660 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-10 01:02:18 +00:00
Duncan Sands
1d32db4406 Add an additional test for icmp of select folding.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118441 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-08 20:56:28 +00:00
Dan Gohman
a25e5dbcc2 Extend the AliasAnalysis::pointsToConstantMemory interface to allow it
to optionally look for constant or local (alloca) memory.

Teach BasicAliasAnalysis::pointsToConstantMemory to look through Select
and Phi nodes, and to support looking for local memory.

Remove FunctionAttrs' PointsToLocalOrConstantMemory function, now that
AliasAnalysis knows all the tricks that it knew.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118412 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-08 16:45:26 +00:00
Dan Gohman
3c97f7af9e Make FunctionAttrs use AliasAnalysis::getModRefBehavior, now that it
knows about intrinsic functions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118410 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-08 16:10:15 +00:00
Duncan Sands
92826def59 Add simplification of floating point comparisons with the result
of a select instruction, the same as already exists for integer
comparisons.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118379 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-07 16:46:25 +00:00
Duncan Sands
1ac7c9979a Fix a README item: when doing a comparison with the result
of a select instruction, see if doing the compare with the
true and false values of the select gives the same result.
If so, that can be used as the value of the comparison.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118378 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-07 16:12:23 +00:00
Owen Anderson
648b20d5db When folding away a (shl (shr)) pair, we need to check that the bits that will BECOME the low
bits are zero, not that the current low bits are zero.  Fixes <rdar://problem/8606771>.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117953 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-01 21:08:20 +00:00
Duncan Sands
ad6f541840 If a function does a volatile load from a global constant, do not
consider it to be readonly.  In fact, don't even consider it to be
readonly if it does a volatile load from an AllocaInst either (it
is debatable as to whether readonly would be correct or not in this
case; play safe for the moment).  This fixes PR8279.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117783 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-30 12:59:44 +00:00
Bob Wilson
822cb58d08 Change instcombine's getShuffleMask to represent undef with negative values.
This code had previously used 2*N, where N is the mask length, to represent
undef.  That is not safe because the shufflevector operands may have more
than N elements -- they don't have to match the result type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117721 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-29 22:03:05 +00:00
Bob Wilson
4cac5facc3 Make instcombine a little more aggressive in combining vector shuffles.
Allow splats even if they don't match either of the original shuffles,
possibly due to undef entries in the shuffles masks.  Radar 8597790.
Also fix some 80-column violations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117719 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-29 22:02:50 +00:00
Owen Anderson
b20955f319 Update testcase since we're no longer doing the constant forwarding inline with correlated value propagation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117712 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-29 21:18:23 +00:00
NAKAMURA Takumi
abd9e01baf test/Transforms/SimplifyLibCalls/floor.ll: Mark as XFAIL:win32 due to lack of nearbyintf on MSVC. [PR8466]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117529 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-28 06:46:04 +00:00
Dale Johannesen
f514f52790 Teach InstCombine not to use Add and Neg on FP. PR 8490.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117510 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-27 23:45:18 +00:00
Dan Gohman
17a0bf996f Fix a case where instcombine was stripping metadata (and alignment)
from stores when folding in bitcasts.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117265 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-25 16:16:27 +00:00
Duncan Sands
5f28475b30 Fix PR8445: a block with no predecessors may be the entry block, in which case
it isn't unreachable and should not be zapped.  The check for the entry block
was missing in one case: a block containing a unwind instruction.  While there,
do some small cleanups: "M" is not a great name for a Function* (it would be
more appropriate for a Module*), change it to "Fn"; use Fn in more places.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117224 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-24 12:23:30 +00:00
Bob Wilson
364f17c471 Teach instcombine to set the alignment arguments for NEON load/store intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117154 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-22 21:41:48 +00:00
Mikhail Glushenkov
99fca5de96 GlobalOpt: EvaluateFunction() must not evaluate stores to weak_odr globals.
Fixes PR8389.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116812 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-19 16:47:23 +00:00
Dan Gohman
c1be92f3bb Make BasicAliasAnalysis a normal AliasAnalysis implementation which
does normal initialization and normal chaining. Change the default
AliasAnalysis implementation to NoAlias.

Update StandardCompileOpts.h and friends to explicitly request
BasicAliasAnalysis.

Update tests to explicitly request -basicaa.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116720 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-18 18:04:47 +00:00
Owen Anderson
6549121c66 Generalize MemCpyOpt's handling of call slot forwarding to function properly when the call slot
forwarding is implemented with a load/store pair rather than a memcpy.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116637 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-15 22:52:12 +00:00
Chris Lattner
a5bbde8efd fix a bug I introduced, no idea how this didn't repro right.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116462 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-14 00:30:00 +00:00
Chris Lattner
15ea094474 hack to unbreak buildbots
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116461 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-14 00:26:10 +00:00
Chris Lattner
eafc5cb80d add uadd_ov/usub_ov to apint, consolidate constant folding
logic to use the new APInt methods.  Among other things this
implements rdar://8501501 - llvm.smul.with.overflow.i32 should constant fold

which comes from "clang -ftrapv", originally brought to my attention from PR8221.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116457 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-14 00:05:07 +00:00
Kenneth Uildriks
74fa7327d6 Now using a variant of the existing inlining heuristics to decide whether to create a given specialization of a function in PartialSpecialization. If the total performance bonus across all callsites passing the same constant exceeds the specialization cost, we create the specialization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116158 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-09 22:06:36 +00:00
Devang Patel
d82e9e7d93 Remove LoopIndexSplit pass. It is neither maintained nor used by anyone.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116004 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-07 23:29:37 +00:00
Owen Anderson
7267e14327 Now that the profitable bits of EnableFullLoadPRE have been enabled by default, rip out the remainder.
Anyone interested in more general PRE would be better served by implementing it separately, to get real
anticipation calculation, etc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115337 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-01 20:02:55 +00:00
Chris Lattner
6eff75104e fix PR8267 - Instcombine shouldn't optimizer away volatile memcpy's.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115296 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-01 05:51:02 +00:00
Chris Lattner
e94aa76d2a upgrade this test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115295 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-01 05:47:16 +00:00
Owen Anderson
722cc1f414 We do want to allow LoadPRE to perform LICM-like transformations: we already consider PHI nodes to be negligible for
code size (making this transform code size neutral), and it allows us to hoist values out of loops, which is always
a good thing.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115205 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-30 20:53:04 +00:00
Benjamin Kramer
9510a2538b Add constant folding for strspn and strcspn to SimplifyLibCalls.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115116 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-30 00:58:35 +00:00
Benjamin Kramer
05f585e28b Add strpbrk folding to SimplifyLibCalls.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115111 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-29 23:52:12 +00:00
Benjamin Kramer
e260990fa1 Simplify the loop in StrChrOptimizer. FileCheckize test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115095 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-29 22:29:12 +00:00
Benjamin Kramer
06f25cfb33 Teach SimplifyLibCalls how to optimize strrchr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115091 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-29 21:50:51 +00:00
Owen Anderson
36c4debc94 Fix PR8247: JumpThreading can cause a block to become unreachable while still having predecessor, if it is part of a self-loop.
Because of this, we cannot use the Simplify* APIs, as they can assert-fail on unreachable code.  Since it's not easy to determine
if a given threading will cause a block to become unreachable, simply defer simplifying simplification to later InstCombine and/or
DCE passes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115082 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-29 20:34:41 +00:00
Jakob Stoklund Olesen
1f386c4ce1 Don't try to constant fold libm functions with non-finite arguments.
Usually we wouldn't do this anyway because llvm_fenv_testexcept would return an
exception, but we have seen some cases where neither errno nor fenv detect an
exception on arm-linux.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114893 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-27 21:29:20 +00:00
Owen Anderson
b0ba0f4170 LoadPRE was not properly checking that the load it was PRE'ing post-dominated the block it was being hoisted to.
Splitting critical edges at the merge point only addressed part of the issue; it is also possible for non-post-domination
to occur when the path from the load to the merge has branches in it.  Unfortunately, full anticipation analysis is
time-consuming, so for now approximate it.  This is strictly more conservative than real anticipation, so we will miss
some cases that real PRE would allow, but we also no longer insert loads into paths where they didn't exist before. :-)

This is a very slight net positive on SPEC for me (0.5% on average).  Most of the benchmarks are largely unaffected, but
when it pays off it pays off decently: 181.mcf improves by 4.5% on my machine.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114785 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-25 05:26:18 +00:00
Jakob Stoklund Olesen
ed37a64c46 Be more precise when trying to XFAIL this tester: http://google1.osuosl.org:8011/builders/llvm-arm-linux
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114755 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-24 20:34:49 +00:00
Dan Gohman
23110b3c16 Attempt to XFAIL this test on arm-linux, which is inexplicably failing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114241 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-18 00:04:37 +00:00