Commit Graph

26061 Commits

Author SHA1 Message Date
Chris Lattner
09fb7dadf1 Eliminate use of setvector for the DeadInsts set, just use a smallvector.
This is a lot cheaper and conceptually simpler.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60332 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 06:27:41 +00:00
Chris Lattner
a68d4ca73e DeleteTriviallyDeadInstructions is always passed the
DeadInsts ivar, just use it directly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60330 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 06:14:28 +00:00
Chris Lattner
bfcee36cd7 simplify DeleteTriviallyDeadInstructions again, unlike my previous
buggy rewrite, this notifies ScalarEvolution of a pending instruction
about to be removed and then erases it, instead of erasing it then 
notifying.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60329 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 06:11:32 +00:00
Chris Lattner
d8aafcb200 simplify these patterns using m_Specific. No need to grep for
xor in testcase (or is a substring).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60328 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 05:16:26 +00:00
Chris Lattner
ef0c6744d5 Teach jump threading to clean up after itself, DCE and constfolding the
new instructions it simplifies.  Because we're threading jumps on edges
with constants coming in from PHI's, we inherently are exposing a lot more
constants to the new block.  Folding them and deleting dead conditions
allows the cost model in jump threading to be more accurate as it iterates.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60327 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 04:48:07 +00:00
Chris Lattner
11240d0fdd The PreVerifier pass preserves everything. In practice, this
prevents the passmgr from adding yet-another domtree invocation
for Verifier if there is already one live.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60326 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 03:58:38 +00:00
Chris Lattner
38b3dcc465 Change instcombine to use FoldPHIArgGEPIntoPHI to fold two operand PHIs
instead of using FoldPHIArgBinOpIntoPHI.  In addition to being more
obvious, this also fixes a problem where instcombine wouldn't merge two
phis that had different variable indices.  This prevented instcombine
from factoring big chunks of code in 403.gcc.  For example:

 insn_cuid.exit:                
-       %tmp336 = load i32** @uid_cuid, align 4      
-       %tmp337 = getelementptr %struct.rtx_def* %insn_addr.0.ph.i, i32 0, i32 3    
-       %tmp338 = bitcast [1 x %struct.rtunion]* %tmp337 to i32*               
-       %tmp339 = load i32* %tmp338, align 4           
-       %tmp340 = getelementptr i32* %tmp336, i32 %tmp339     
        br label %bb62
 
 bb61:       
-       %tmp341 = load i32** @uid_cuid, align 4     
-       %tmp342 = getelementptr %struct.rtx_def* %insn, i32 0, i32 3        
-       %tmp343 = bitcast [1 x %struct.rtunion]* %tmp342 to i32*           
-       %tmp344 = load i32* %tmp343, align 4        
-       %tmp345 = getelementptr i32* %tmp341, i32 %tmp344          
        br label %bb62
 
 bb62:      
-       %iftmp.62.0.in = phi i32* [ %tmp345, %bb61 ], [ %tmp340, %insn_cuid.exit ]         
+       %insn.pn2 = phi %struct.rtx_def* [ %insn, %bb61 ], [ %insn_addr.0.ph.i, %insn_cuid.exit ]         
+       %tmp344.pn.in.in = getelementptr %struct.rtx_def* %insn.pn2, i32 0, i32 3     
+       %tmp344.pn.in = bitcast [1 x %struct.rtunion]* %tmp344.pn.in.in to i32*  
+       %tmp341.pn = load i32** @uid_cuid     
+       %tmp344.pn = load i32* %tmp344.pn.in 
+       %iftmp.62.0.in = getelementptr i32* %tmp341.pn, i32 %tmp344.pn   
        %iftmp.62.0 = load i32* %iftmp.62.0.in     



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60325 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 03:42:51 +00:00
Chris Lattner
05f18920e1 Teach inst combine to merge GEPs through PHIs. This is really
important because it is sinking the loads using the GEPs, but
not the GEPs themselves.  This triggers 647 times on 403.gcc
and makes the .s file much much nicer.  For example before:

        je      LBB1_87 ## bb78
LBB1_62:        ## bb77
        leal    84(%esi), %eax
LBB1_63:        ## bb79
        movl    (%eax), %eax
...
LBB1_87:        ## bb78
        movl    $0, 4(%esp)
        movl    %esi, (%esp)
        call    L_make_decl_rtl$stub
        jmp     LBB1_62 ## bb77


after:

        jne     LBB1_63 ## bb79
LBB1_62:        ## bb78
        movl    $0, 4(%esp)
        movl    %esi, (%esp)
        call    L_make_decl_rtl$stub
LBB1_63:        ## bb79
        movl    84(%esi), %eax

The input code was (and the GEPs are merged and
the PHI is now eliminated by instcombine):

        br i1 %tmp233, label %bb78, label %bb77
bb77:           
        %tmp234 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22              
        br label %bb79
bb78:           
        call void @make_decl_rtl(%struct.tree_node* %t_addr.3, i8* null) nounwind
        %tmp235 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22              
        br label %bb79
bb79:           
        %iftmp.12.0.in = phi %struct.rtx_def** [ %tmp235, %bb78 ], [ %tmp234, %bb77 ]           
        %iftmp.12.0 = load %struct.rtx_def** %iftmp.12.0.in             



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60322 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 02:34:36 +00:00
Chris Lattner
978796eaad Make GVN be more intelligent about redundant load
elimination: when finding dependent load/stores, realize that
they are the same if aliasing claims must alias instead of relying
on the pointers to be exactly equal.  This makes load elimination
more aggressive.  For example, on 403.gcc, we had:

<     68 gvn    - Number of instructions PRE'd
< 152718 gvn    - Number of instructions deleted
<  49699 gvn    - Number of loads deleted
<   6153 memdep - Number of dirty cached non-local responses
< 169336 memdep - Number of fully cached non-local responses
< 162428 memdep - Number of uncached non-local responses

now we have:

>     64 gvn    - Number of instructions PRE'd
> 153623 gvn    - Number of instructions deleted
>  49856 gvn    - Number of loads deleted
>   5022 memdep - Number of dirty cached non-local responses
> 159030 memdep - Number of fully cached non-local responses
> 162443 memdep - Number of uncached non-local responses

That's an extra 157 loads deleted and extra 905 other instructions nuked.

This slows down GVN very slightly, from 3.91 to 3.96s.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60314 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 01:31:36 +00:00
Chris Lattner
bf145d6e2b Reimplement the non-local dependency data structure in terms of a sorted
vector instead of a densemap.  This shrinks the memory usage of this thing
substantially (the high water mark) as well as making operations like
scanning it faster.  This speeds up memdep slightly, gvn goes from
3.9376 to 3.9118s on 403.gcc

This also splits out the statistics for the cached non-local case to
differentiate between the dirty and clean cached case.  Here's the stats
for 403.gcc:

  6153 memdep - Number of dirty cached non-local responses
169336 memdep - Number of fully cached non-local responses
162428 memdep - Number of uncached non-local responses

yay for caching :)



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60313 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 01:15:42 +00:00
Bill Wendling
b3833d1eb9 Implement ((A|B)&1)|(B&-2) -> (A&1) | B transformation. This also takes care of
permutations of this pattern.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60312 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 01:07:11 +00:00
Chris Lattner
663e441a75 Cache analyses in ivars and add some useful DEBUG output.
This speeds up GVN from 4.0386s to 3.9376s.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60310 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 00:40:32 +00:00
Chris Lattner
1440ac5417 improve indentation, do cheap checks before expensive ones,
remove some fixme's.  This speeds up GVN very slightly on 403.gcc 
(4.06->4.03s)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60309 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 23:39:23 +00:00
Chris Lattner
fd3dcbea06 Eliminate the DepResultTy abstraction. It is now completely
redundant with MemDepResult, and MemDepResult has a nicer interface.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60308 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 23:17:19 +00:00
Eli Friedman
8b019c8a45 Minor cleanup: use getTrue and getFalse where appropriate. No
functional change.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60307 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 22:48:49 +00:00
Eli Friedman
d1fd1da143 Some minor cleanups to instcombine; no functionality change.
Note that the FoldOpIntoPhi call is dead because it's impossible for the 
first operand of a subtraction to be both a ConstantInt and a PHINode.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60306 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 21:09:11 +00:00
Chris Lattner
d777d405cd Cache TargetData/AliasAnalysis in the pass instead of calling
getAnalysis<>.  getAnalysis<> is apparently extremely expensive.
Doing this speeds up GVN on 403.gcc by 16%!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60304 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 19:24:31 +00:00
Bill Wendling
b01865c210 Add instruction combining for ((A&~B)|(~A&B)) -> A^B and all permutations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60291 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 13:52:49 +00:00
Bill Wendling
7f0ef6b325 Implement (A&((~A)|B)) -> A&B transformation in the instruction combiner. This
takes care of all permutations of this pattern.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60290 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 13:08:13 +00:00
Bill Wendling
7c7048ecc6 Forgot one remaining call to getSExtValue().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60289 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 12:41:09 +00:00
Bill Wendling
6e1783fb4a getSExtValue() doesn't work for ConstantInts with bitwidth > 64 bits. Use all
APInt calls instead.

This fixes PR3144.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60288 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 12:38:24 +00:00
Eli Friedman
d83ae7d698 Optimize memmove and memset into the LLVM builtins. Note that these
only show up in code from front-ends besides llvm-gcc, like clang.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60287 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 08:32:11 +00:00
Eli Friedman
91db5271d2 A couple small cleanups, plus a new potential optimization.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60286 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 07:52:27 +00:00
Eli Friedman
4e16b29a6b Moving potential optimizations out of PR2330 into lib/Target/README.txt.
Hopefully this isn't too much stuff to dump into this file.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60285 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 07:36:04 +00:00
Eli Friedman
fc69cb475f Followup to r60283: optimize arbitrary width signed divisions as well
as unsigned divisions.  Same caveats as before.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60284 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 06:35:39 +00:00
Eli Friedman
201c9776bd Fix for PR2164: allow transforming arbitrary-width unsigned divides into
multiplies.

Some more cleverness would be nice, though. It would be nice if we 
could do this transformation on illegal types.  Also, we would 
prefer a narrower constant when possible so that we can use a narrower
multiply, which can be cheaper.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60283 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 06:02:26 +00:00
Bill Wendling
3f93df5733 Don't make TwoToExp signed by default.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60279 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 05:29:33 +00:00
Bill Wendling
f0e44c4d7a From Hacker's Delight:
"For signed integers, the determination of overflow of x*y is not so simple. If
x and y have the same sign, then overflow occurs iff xy > 2**31 - 1. If they
have opposite signs, then overflow occurs iff xy < -2**31."

In this case, x == -1.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60278 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 05:01:05 +00:00
Eli Friedman
86f874d9bb APIntify a test which is potentially unsafe otherwise, and fix the
nearby FIXME.

I'm not sure what the right way to fix the Cell test was; if the 
approach I used isn't okay, please let me know.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60277 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 04:59:26 +00:00
Bill Wendling
e1196d6d3e Instcombine was illegally transforming -X/C into X/-C when either X or C
overflowed on negation. This commit checks to make sure that neithe C nor X
overflows. This requires that the RHS of X (a subtract instruction) be a
constant integer.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60275 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 03:42:12 +00:00
Chris Lattner
4a69bade23 Two changes: Make getDependency remove QueryInst for a dirty record's
ReverseLocalDeps when we update it.  This fixes a regression test
failure from my last commit.

Second, for each non-local cached information structure, keep a bit that
indicates whether it is dirty or not.  This saves us a scan over the whole
thing in the common case when it isn't dirty.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60274 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 02:52:26 +00:00
Chris Lattner
25f4b2b7a3 introduce a typedef, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60272 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 02:30:50 +00:00
Chris Lattner
f68f310386 Change NonLocalDeps to be a densemap of pointers to densemap
instead of containing them by value.  This increases the density
(!) of NonLocalDeps as well as making the reallocation case 
faster.  This speeds up gvn on 403.gcc by 2% and makes room for
future improvements.

I'm not super thrilled with having to explicitly manage the new/delete
of the map, but it is necesary for the next change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60271 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 02:28:25 +00:00
Chris Lattner
cfbb634225 calls never depend on allocations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60268 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 01:44:00 +00:00
Chris Lattner
237a828745 Fix a fixme by making memdep's handling of allocations more logical.
If we see that a load depends on the allocation of its memory with no
intervening stores, we now return a 'None' depedency instead of "Normal".
This tweaks GVN to do its optimization with the new result.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60267 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 01:39:32 +00:00
Chris Lattner
73ec3cdd71 implement a fixme by introducing a new getDependencyFromInternal
method that returns its result as a DepResultTy instead of as a
MemDepResult.  This reduces conversion back and forth.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60266 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 01:26:32 +00:00
Chris Lattner
37d041c25f Move the getNonLocalDependency method to a more logical place in
the file, no functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60265 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 01:18:27 +00:00
Chris Lattner
0e0a5b690c REmove an old fixme, resolve another fixme by adding liberal
comments about what this class does.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60264 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 01:17:08 +00:00
Chris Lattner
125ce36269 remove a bit of incorrect code that tried to be tricky about speeding up
dependencies.  The basic situation was this: consider if we had:

  store1
  ...
  store2
  ...
  store3

Where memdep thinks that store3 depends on store2 and store2 depends 
on store1.  The problem happens when we delete store2: The code in 
question was updating dep info for store3 to be store1.  This is a
spiffy optimization, but is not safe at all, because aliasing isn't
transitive.  This bug isn't exposed today with DSE because DSE will only
zap store2 if it is identifical to store 3, and in this case, it is 
safe to update it to depend on store1.  However, memcpyopt is not so
fortunate, which is presumably why the "dropInstruction" code used to
exist.

Since this doesn't actually provide a speedup in practice, just rip the
code out.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60263 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-30 01:09:30 +00:00
Chris Lattner
4f8c18c7c7 Eliminate the dropInstruction method, which is not needed any more.
Fix a subtle iterator invalidation bug I introduced in the last commit.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60258 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 23:30:39 +00:00
Chris Lattner
0ec48ddef2 implement some fixme's: when deleting an instruction with
an entry in the nonlocal deps map, don't reset entries
referencing that instruction to [dirty, null], instead, set
them to [dirty,next] where next is the instruction after the
deleted one.  Use this information in the non-local deps
code to avoid rescanning entire blocks.

This speeds up GVN slightly by avoiding pointless work.  On
403.gcc this makes GVN 1.5% faster. 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60256 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 22:02:15 +00:00
Chris Lattner
396a4a55e5 Change MemDep::getNonLocalDependency to return its results as
a smallvector instead of a DenseMap.  This speeds up GVN by 5%
on 403.gcc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60255 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 21:33:22 +00:00
Chris Lattner
729b23758a move MemoryDependenceAnalysis::verifyRemoved to the end of the file,
no functionality/code change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60254 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 21:25:10 +00:00
Chris Lattner
86b29ef64a reimplement getNonLocalDependency with a simpler worklist
formulation that is faster and doesn't require nonLazyHelper.
Much less code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60253 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 21:22:42 +00:00
Chris Lattner
3a76be584b Fix a thinko that manifested as a crash on clamav last night.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60251 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 20:29:04 +00:00
Chris Lattner
8c4652790e rename some maps.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60242 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 09:20:15 +00:00
Chris Lattner
00314b3d84 rename some variables.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60241 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 09:15:21 +00:00
Chris Lattner
a161ab06d9 eliminate a bunch of code in favor of using AliasAnalysis::getModRefInfo.
Put a some code back to handle buggy behavior that GVN expects: it wants
loads to depend on each other, and accesses to depend on their allocations.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60240 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 09:09:48 +00:00
Chris Lattner
25a081439f simplify some code and rename some variables. Reduce nesting.
Use getTypeStoreSize instead of ABITypeSize for in-memory size
in a couple places.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60238 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 08:51:16 +00:00
Chris Lattner
5391a1d804 Split getDependency into getDependency and getDependencyFrom, the
former does caching, the later doesn't.  This dramatically simplifies
the logic in getDependency and getDependencyFrom.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60234 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-29 03:47:00 +00:00