1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00
Commit Graph

772 Commits

Author SHA1 Message Date
Nick Lewycky
3823432a57 The logic inside getMulExpr to simplify {a,+,b}*{c,+,d} was wrong, which was
visible given a=b=c=d=1, on iteration #1 (the second iteration). Replace it with
correct math. Fixes PR10383!

llvm-svn: 139133
2011-09-06 05:05:14 +00:00
Nick Lewycky
18c0b01a56 Revert r139126 due to selfhost failures reported by buildbots.
llvm-svn: 139130
2011-09-06 02:43:13 +00:00
Nick Lewycky
30dcc754df Teach SCEV to report a max backedge count in one interesting case in
HowFarToZero; the case for a canonical loop.

llvm-svn: 139126
2011-09-05 23:25:16 +00:00
Andrew Trick
43d88c3879 Comment and clarifying assert.
llvm-svn: 139036
2011-09-02 21:20:46 +00:00
Andrew Trick
5a5a5ebe68 Allow loop unrolling to get known trip counts from ScalarEvolution.
SCEV unrolling can unroll loops with arbitrary induction variables. It
is a prerequisite for -disable-iv-rewrite performance. It is also
easily handles loops of arbitrary structure including multiple exits
and is generally more robust.

This is under a temporary option to avoid affecting default
behavior for the next couple of weeks. It is needed so that I can
checkin unit tests for updateUnloop.

llvm-svn: 137384
2011-08-11 23:36:16 +00:00
Andrew Trick
a7fc7983d4 Made SCEV's UDiv expressions more canonical. When dividing a
recurrence, the initial values low bits can sometimes be ignored.

To take advantage of this, added FoldIVUser to IndVarSimplify to fold
an IV operand into a udiv/lshr if the operator doesn't affect the
result.

-indvars -disable-iv-rewrite now transforms

i = phi i4
i1 = i0 + 1
idx = i1 >> (2 or more)
i4 = i + 4

into

i = phi i4
idx = i0 >> ...
i4 = i + 4

llvm-svn: 137013
2011-08-06 07:00:37 +00:00
Andrew Trick
86f6a3c645 Use consistent terminology for loop exit/exiting blocks. Name change only.
llvm-svn: 136677
2011-08-02 04:23:35 +00:00
Andrew Trick
ae93f1bf46 SCEV: Added a data structure for storing not-taken info per loop
exit. Added an interfaces for querying either the loop's exact/max
backedge taken count or a specific loop exit's not-taken count.

llvm-svn: 136100
2011-07-26 17:19:55 +00:00
Jay Foad
ae5894c5cc Use ArrayRef in ConstantFoldInstOperands and ConstantFoldCall.
llvm-svn: 135477
2011-07-19 13:32:40 +00:00
Chris Lattner
e1fe7061ce land David Blaikie's patch to de-constify Type, with a few tweaks.
llvm-svn: 135375
2011-07-18 04:54:35 +00:00
Andrew Trick
b92801a07e SCEV: missing null check fix for r132360, dragonegg crash.
llvm-svn: 132416
2011-06-01 19:14:56 +00:00
Andrew Trick
60ad58febd scev: Better sign-extend removal. Normalize postincrement recurrences
so that their sign extended forms are congruent when no overflow occurs.

llvm-svn: 132360
2011-05-31 21:17:47 +00:00
Dan Gohman
392ab7a6ba Change a few std::maps to DenseMaps.
llvm-svn: 131088
2011-05-09 18:44:09 +00:00
Andrew Trick
270f5fb525 Corrects an old, old typo in a case that doesn't seem to be reached in practice.
llvm-svn: 130316
2011-04-27 18:17:36 +00:00
Andrew Trick
cef977b295 Test case and comment for PR9633.
llvm-svn: 130294
2011-04-27 05:42:17 +00:00
Andrew Trick
73a354c27e Fix for PR9633 [indvars] Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Added a type check in ScalarEvolution::computeSCEVAtScope to handle the case in which operands of an
AddRecExpr in the current scope are folded.

llvm-svn: 130271
2011-04-27 01:21:25 +00:00
Dan Gohman
6ff1c50bb5 Fix an iterator invalidation bug.
llvm-svn: 130166
2011-04-25 22:48:29 +00:00
Chris Lattner
0304b82f80 Fix a ton of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!

llvm-svn: 129558
2011-04-15 05:18:47 +00:00
Andrew Trick
07887af00c Added isValidRewrite() to check the result of ScalarEvolutionExpander.
SCEV may generate expressions composed of multiple pointers, which can
lead to invalid GEP expansion. Until we can teach SCEV to follow strict
pointer rules, make sure no bad GEPs creep into IR.
Fixes rdar://problem/9038671.

llvm-svn: 127839
2011-03-17 23:51:11 +00:00
Andrew Trick
09d2dcd9ef Remove getMinusSCEVForExitTest().
This function performed acrobatics to prove no-self-wrap, which we now
have for free.

llvm-svn: 127643
2011-03-15 01:16:14 +00:00
Andrew Trick
5c8b815e5f Propagate SCEV no-wrap flags whenever possible.
This needs review.

llvm-svn: 127638
2011-03-15 00:37:00 +00:00
Andrew Trick
da253e79f0 Negating a recurrence preserves no-self-wrap.
llvm-svn: 127593
2011-03-14 17:38:54 +00:00
Andrew Trick
dab71254b6 HowFarToZero can compute a trip count as long as the recurrence has no-self-wrap.
llvm-svn: 127591
2011-03-14 17:28:02 +00:00
Andrew Trick
5d45b563c5 Added SCEV::NoWrapFlags to manage unsigned, signed, and self wrap
properties.
Added the self-wrap flag for SCEV::AddRecExpr.
A slew of temporary FIXMEs indicate the intention of the no-self-wrap flag
without changing behavior in this revision.

llvm-svn: 127590
2011-03-14 16:50:06 +00:00
Andrew Trick
c4703f6ea1 When SCEV can determine the loop test is X < X, set ExactBECount=0.
When ExactBECount is a constant, use it for MaxBECount.
When MaxBECount cannot be computed, replace it with ExactBECount.
Fixes PR9424.

llvm-svn: 127342
2011-03-09 17:29:58 +00:00
Andrew Trick
de565b0456 whitespace
llvm-svn: 127340
2011-03-09 17:23:39 +00:00
Chris Lattner
2596ac19b9 teach SCEV that the scale and addition of an inbounds gep don't NSW.
This fixes a FIXME in scev-aa.ll (allowing a new no-alias result) and
generally makes things more precise.

llvm-svn: 125449
2011-02-13 03:14:49 +00:00
Chris Lattner
fec8b6bd6d Per discussion with Dan G, inbounds geps *certainly* can have
unsigned overflow (e.g. "gep P, -1"), and while they can have
signed wrap in theoretical situations, modelling an AddRec as
not having signed wrap is going enough for any case we can 
think of today.  In the future if this isn't enough, we can
revisit this.  Modeling them as having NUW isn't causing any
known problems either FWIW.

llvm-svn: 125410
2011-02-11 21:43:33 +00:00
Nick Lewycky
fc7a74c9a0 Fix memory corruption. If one of the SCEV creation functions calls another but
doesn't return immediately after then the insert position in UniqueSCEVs will
be out of date. No test because this is a memory corruption issue. Fixes PR9051!

llvm-svn: 124282
2011-01-26 08:40:22 +00:00
Dan Gohman
308677c046 Add a comment.
llvm-svn: 124126
2011-01-24 17:54:18 +00:00
Nick Lewycky
13a2b8281f Simplify some code with no functionality change. Make the test a lot more
robust against smarter optimizations, using the power of FileCheck.

llvm-svn: 124081
2011-01-23 20:06:05 +00:00
Nick Lewycky
2503c9f9c8 Use value ranges to fold ext(trunc) in SCEV when possible.
llvm-svn: 124062
2011-01-23 06:20:19 +00:00
Nick Lewycky
4440e5815b Have SCEV turn sext(x) into zext(x) when x is s>= 0. This applies many times in
"make check" alone.

llvm-svn: 124046
2011-01-22 22:06:21 +00:00
Nick Lewycky
51c13384f5 Similarly, analyze truncate through multiply.
llvm-svn: 123842
2011-01-19 18:56:00 +00:00
Nick Lewycky
9867e58096 Add a missed SCEV fold that is required to continue analyzing the IR produced
by indvars through the scev expander.

trunc(add x, y) --> add(trunc x, y). Currently SCEV largely folds the other way
which is probably wrong, but preserved to minimize churn. Instcombine doesn't
do this fold either, demonstrating a missed optz'n opportunity on code doing
add+trunc+add.

llvm-svn: 123838
2011-01-19 16:59:46 +00:00
Nick Lewycky
5a538b62ca Add a missing SCEV simplification sext(zext x) --> zext x.
llvm-svn: 123832
2011-01-19 15:56:12 +00:00
Chris Lattner
8c0a70a30c some comment improvements.
llvm-svn: 123243
2011-01-11 17:11:59 +00:00
Eric Christopher
e86e1aecd8 Temporarily revert 123133, it's causing some regressions and I'm trying
to get a testcase.

llvm-svn: 123225
2011-01-11 09:02:09 +00:00
Chris Lattner
14bf29d7a0 the GEP faq says that only inbounds geps are guaranteed to not overflow.
llvm-svn: 123218
2011-01-11 06:44:41 +00:00
Chris Lattner
0643d32b61 add a fixme: ir isn't expressive enough.
llvm-svn: 123139
2011-01-09 23:02:10 +00:00
Chris Lattner
c8a9f4ca2b Step #4 in improving trip count analysis: HowFarToZero can analyze
NUW AddRec's much more aggressively.  We now get a trip count
for @test2 in nsw.ll

llvm-svn: 123138
2011-01-09 22:58:47 +00:00
Chris Lattner
09cfec2226 rearrange some code, no functionality change.
llvm-svn: 123136
2011-01-09 22:39:48 +00:00
Chris Lattner
4efcd276de Step #3 to improving trip count analysis: If we fold
a + {b,+,stride} into {a+b,+,stride}  (because a is LIV),
then the resultant AddRec is NUW/NSW if the client says it
is.

llvm-svn: 123133
2011-01-09 22:31:26 +00:00
Chris Lattner
b6a67a9068 Step #2 to improve trip count analysis for loops like this:
void f(int* begin, int* end) { std::fill(begin, end, 0); }

which turns into a != exit expression where one pointer is
strided and (thanks to step #1) known to not overflow, and 
the other is loop invariant.

The observation here is that, though the IV is strided by
4 in this case, that the IV *has* to become equal to the
end value.  It cannot "miss" the end value by stepping over
it, because if it did, the strided IV expression would
eventually wrap around.

Handle this by turning A != B into "A-B != 0" where the A-B
part is known to be NUW.

llvm-svn: 123131
2011-01-09 22:26:35 +00:00
Chris Lattner
57e9b35653 teach SCEV analysis of PHI nodes that PHI recurences formed
with GEP instructions are always NUW, because PHIs cannot wrap
the end of the address space.

llvm-svn: 123105
2011-01-09 02:28:48 +00:00
Chris Lattner
fa37cac39c reduce indentation. Print <nuw> and <nsw> when dumping SCEV AddRec's
that have the bit set.

llvm-svn: 123104
2011-01-09 02:16:18 +00:00
Jay Foad
79e18ed269 PR5207: Change APInt methods trunc(), sext(), zext(), sextOrTrunc() and
zextOrTrunc(), and APSInt methods extend(), extOrTrunc() and new method
trunc(), to be const and to return a new value instead of modifying the
object in place.

llvm-svn: 121120
2010-12-07 08:25:19 +00:00
Jay Foad
789e8ac4f7 PR5207: Rename overloaded APInt methods set(), clear(), flip() to
setAllBits(), setBit(unsigned), etc.

llvm-svn: 120564
2010-12-01 08:53:58 +00:00
Benjamin Kramer
9141603779 Simplify code. No change in functionality.
llvm-svn: 119908
2010-11-20 18:43:35 +00:00
Benjamin Kramer
821c39433d Silence warning about an uninitialized variable.
llvm-svn: 119800
2010-11-19 11:37:26 +00:00
Duncan Sands
4562d3b919 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.

llvm-svn: 119727
2010-11-18 19:59:41 +00:00
Dan Gohman
3213622610 Introduce memoization for ScalarEvolution dominates and properlyDominates
queries, and SCEVExpander getRelevantLoop queries.

llvm-svn: 119595
2010-11-18 00:34:22 +00:00
Dan Gohman
ecff21cc67 Factor out the code for purging a SCEV from all the various memoization maps.
Some of these maps may merge in the future, but for now it's convenient to have
a utility function for them.

llvm-svn: 119587
2010-11-17 23:28:48 +00:00
Dan Gohman
8e594dfe39 Merge the implementations of isLoopInvariant and hasComputableLoopEvolution, and
memoize the results. This improves compile time in code which highly complex
expressions which get queried many times.

llvm-svn: 119584
2010-11-17 23:21:44 +00:00
Dan Gohman
fb6ea18d0a Make SCEV::getType() and SCEV::print non-virtual. Move SCEV::hasOperand
to ScalarEvolution. Delete SCEV::~SCEV. SCEV is no longer virtual.

llvm-svn: 119578
2010-11-17 22:27:42 +00:00
Dan Gohman
9bbb0fa515 Move SCEV::dominates and properlyDominates to ScalarEvolution.
llvm-svn: 119570
2010-11-17 21:41:58 +00:00
Dan Gohman
04df5af12b Move SCEV::isLoopInvariant and hasComputableLoopEvolution to be member
functions of ScalarEvolution, in preparation for memoization and
other optimizations.

llvm-svn: 119562
2010-11-17 21:23:15 +00:00
Duncan Sands
b5fd5f2124 Before replacing a phi node with a different value, it
needs to be checked that this won't break LCSSA form.
Change the existing checking method to a more direct one:
rather than seeing if all predecessors belong to the loop,
check that the replacing value is either not in any loop or
is in a loop that contains the phi node.

llvm-svn: 119556
2010-11-17 20:49:12 +00:00
Dan Gohman
4dc0a20aea Verify SCEVAddRecExpr's invariant in ScalarEvolution::getAddRecExpr
instead of in SCEVAddRecExpr's constructor, in preparation for an
upcoming change.

llvm-svn: 119554
2010-11-17 20:48:38 +00:00
Dan Gohman
a585073323 Fix ScalarEvolution's range memoization to avoid using a
default ctor with ConstantRange.

llvm-svn: 119550
2010-11-17 20:23:08 +00:00
Duncan Sands
7376a19858 Have ScalarEvolution use SimplifyInstruction rather than hasConstantValue.
While there, add a note about an inefficiency I noticed.

llvm-svn: 119458
2010-11-17 04:18:45 +00:00
Dan Gohman
b10ff802a0 Memoize results from ScalarEvolution's getUnsignedRange and getSignedRange.
This fixes some extreme compile times on unrolled sha512 code.

llvm-svn: 119455
2010-11-17 02:44:44 +00:00
Dan Gohman
85557399a1 Make ScalarEvolution::forgetLoop forget all contained loops too, because
they may have ValuesAtScopes map entries referencing their outer loops.
This fixes a user-after-free reported in PR8471.

llvm-svn: 117698
2010-10-29 20:16:10 +00:00
Owen Anderson
46990c17f7 Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which
must be called in the pass's constructor.  This function uses static dependency declarations to recursively initialize
the pass's dependencies.

Clients that only create passes through the createFooPass() APIs will require no changes.  Clients that want to use the
CommandLine options for passes will need to manually call the appropriate initialization functions in PassInitialization.h
before parsing commandline arguments.

I have tested this with all standard configurations of clang and llvm-gcc on Darwin.  It is possible that there are problems
with the static dependencies that will only be visible with non-standard options.  If you encounter any crash in pass
registration/creation, please send the testcase to me directly.

llvm-svn: 116820
2010-10-19 17:21:58 +00:00
Owen Anderson
63f757463c Begin adding static dependence information to passes, which will allow us to
perform initialization without static constructors AND without explicit initialization
by the client.  For the moment, passes are required to initialize both their
(potential) dependencies and any passes they preserve.  I hope to be able to relax
the latter requirement in the future.

llvm-svn: 116334
2010-10-12 19:48:12 +00:00
Owen Anderson
69cbf2e8b7 Now with fewer extraneous semicolons!
llvm-svn: 115996
2010-10-07 22:25:06 +00:00
Dan Gohman
ff478951be Don't add the operand count to SCEV uniquing data; FoldingSetNodeID
already knows its own length, so this is redundant.

llvm-svn: 115521
2010-10-04 17:24:08 +00:00
Dan Gohman
fb64948296 Reapply r112432, now that the real problem is addressed.
llvm-svn: 112667
2010-08-31 22:53:17 +00:00
Dan Gohman
cadc463790 Reapply r112433, now that the real problem is addressed.
llvm-svn: 112666
2010-08-31 22:52:12 +00:00
Dan Gohman
a9b5b6bd36 Revert r110916. This patch is buggy because the code inside the
inner loop doesn't update all the variables in the outer loop.

llvm-svn: 112665
2010-08-31 22:50:31 +00:00
Dan Gohman
6822b9d177 Revert r112432. It appears to be exposing a problem in the emacs build.
llvm-svn: 112638
2010-08-31 20:58:44 +00:00
Dan Gohman
47865eb626 Speculatively revert r112433.
llvm-svn: 112608
2010-08-31 17:56:47 +00:00
Dan Gohman
4e9013673c Restructure the {A,+,B}<L> * {C,+,D}<L> folding so that it folds
all applicable addrecs before recursing on getMulExpr, instead of
recursing on getMulExpr for each one.

llvm-svn: 112433
2010-08-29 15:16:58 +00:00
Dan Gohman
88b40ae04a Batch up subtracts along with adds, when analyzing long chains of
operations.

llvm-svn: 112432
2010-08-29 15:10:06 +00:00
Dan Gohman
988c90a5e1 Micro-optimize GroupByComplexity.
llvm-svn: 112431
2010-08-29 15:07:13 +00:00
Dan Gohman
690916c085 Hold AddRec->getLoop() in a variable, to make the Mul code more consistent
with the Add code.

llvm-svn: 112430
2010-08-29 14:55:19 +00:00
Dan Gohman
5a3ad9c218 Rename a variable, for consistency.
llvm-svn: 112429
2010-08-29 14:53:34 +00:00
Dan Gohman
d581ece72a Use iterators instead of indices.
llvm-svn: 112428
2010-08-29 14:52:02 +00:00
Dan Gohman
aa972a1ee3 Fix an index calculation thinko.
llvm-svn: 112337
2010-08-28 00:39:27 +00:00
Dan Gohman
ee0a450648 When merging adjacent operands, scan ahead and merge all equal
adjacent operands at once, instead of just two at a time.

llvm-svn: 112299
2010-08-27 21:39:59 +00:00
Dan Gohman
f950201d01 Make the {A,+,B}<L> + {C,+,D}<L> --> Other + {A+C,+,B+D}<L>
transformation collect all the addrecs with the same loop
add combine them at once rather than starting everything over
at the first chance.

llvm-svn: 112290
2010-08-27 20:45:56 +00:00
Dan Gohman
636c57c5de Switch ScalarEvolution's main Value*->SCEV* map from std::map
to DenseMap.

llvm-svn: 112281
2010-08-27 18:55:03 +00:00
Dan Gohman
e1fcf40b52 Optimize SCEVComplexityCompare. Use a 3-way return instead of a 2-way
return to avoid needing two calls to test for equivalence, and sort
addrecs by their degree before examining their operands.

llvm-svn: 112267
2010-08-27 15:26:01 +00:00
Dan Gohman
013400a0f9 To create a copy of a SmallVector with an element removed from the
middle, copy the elements in two groups, rather than copying all the
elements and then doing an erase on the middle of the result. These
are SmallVectors, so we shouldn't expect to hit dynamic allocation
in the common case.

llvm-svn: 111151
2010-08-16 16:57:24 +00:00
Dan Gohman
7312563612 Tidy whitespace.
llvm-svn: 111147
2010-08-16 16:34:09 +00:00
Dan Gohman
8281459eb0 Add a comment.
llvm-svn: 111145
2010-08-16 16:31:39 +00:00
Dan Gohman
71323d2cfe Use const_iterator in a few places.
llvm-svn: 111144
2010-08-16 16:30:01 +00:00
Dan Gohman
b0604c0b83 Use iterators instead of indices in a few more places.
llvm-svn: 111143
2010-08-16 16:27:53 +00:00
Dan Gohman
64c713c605 Micro-optimize SCEVConstant comparison.
llvm-svn: 111142
2010-08-16 16:25:35 +00:00
Dan Gohman
6d808db278 Move SCEVNAryExpr's virtual member functions out of line, and convert
them to iterators.

llvm-svn: 111140
2010-08-16 16:21:27 +00:00
Dan Gohman
d55de2457e Use iterators instead of indices in simple cases.
llvm-svn: 111138
2010-08-16 16:16:11 +00:00
Dan Gohman
daec40b96d Avoid gratuitous inefficiency in ifndef NDEBUG code.
llvm-svn: 111137
2010-08-16 16:13:54 +00:00
Dan Gohman
345dc8add7 Make one getAddExpr call when analyzing a+b+c+d+e+... instead of one
for each add instruction. Ditto for Mul.

llvm-svn: 111136
2010-08-16 16:03:49 +00:00
Dan Gohman
fec602e7c5 Delete an unused function.
llvm-svn: 111135
2010-08-16 15:57:14 +00:00
Dan Gohman
076597a026 Various optimizations. Don't compare two loops' depths
when they are the same loop. Don't compare two instructions'
loop depths when they are in the same block.

llvm-svn: 111045
2010-08-13 21:24:58 +00:00
Dan Gohman
ecb279a1c2 When testing whether one loop contains another, test this directly
rather than testing whether the loop contains the other's header.

llvm-svn: 111039
2010-08-13 20:23:25 +00:00
Dan Gohman
02de74d4dc Add a const.
llvm-svn: 111038
2010-08-13 20:17:27 +00:00
Dan Gohman
3650d2058f When creating a symmetric SCEV with a constant operand, put
the constant operand on the left, as that's where ScalarEvolution
will end up canonicalizing to.

llvm-svn: 111037
2010-08-13 20:17:14 +00:00
Dan Gohman
de171ff360 An add recurrence is loop-invariant in any loop inside of its
associated loop. This avoids potentially expensive traversals
of the add recurrence's operands.

llvm-svn: 111034
2010-08-13 20:11:39 +00:00
Dan Gohman
8103471a35 Optimize ScalarEvolution::getAddExpr's operand factoring code by
having it finish processing all of the muliply operands before
starting the whole getAddExpr process over again, instead of
immediately after the first simplification.

llvm-svn: 110916
2010-08-12 15:00:23 +00:00
Dan Gohman
d7b79a35df Hoist some loop-invariant code out of a hot loop.
llvm-svn: 110915
2010-08-12 14:52:55 +00:00
Dan Gohman
cc5fb07653 Optimize ScalarEvolution::getAddExpr's duplicate operand detection
by having it finish processing the whole operand list before
starting the whole getAddExpr process over again, instead of
immediately after the first duplicate is found.

llvm-svn: 110914
2010-08-12 14:46:54 +00:00
Dan Gohman
603e66618f When analyzing loop exit conditions combined with and and or, don't
make any assumptions about when the two conditions will agree on when
to permit the loop to exit. This fixes PR7845.

llvm-svn: 110758
2010-08-11 00:12:36 +00:00
Dan Gohman
7e49302e9a Rename and reorder the arguments to isImpliedCond, for consistency and clarity.
llvm-svn: 110750
2010-08-10 23:46:30 +00:00
Owen Anderson
f2fea95f2f Reapply r110396, with fixes to appease the Linux buildbot gods.
llvm-svn: 110460
2010-08-06 18:33:48 +00:00
Owen Anderson
aadd8a89ca Revert r110396 to fix buildbots.
llvm-svn: 110410
2010-08-06 00:23:35 +00:00
Owen Anderson
b9762c07cb Don't use PassInfo* as a type identifier for passes. Instead, use the address of the static
ID member as the sole unique type identifier.  Clean up APIs related to this change.

llvm-svn: 110396
2010-08-05 23:42:04 +00:00
Dan Gohman
bafce59252 Fix a minor bug which resulted in intermediate calculations
using wider types than are necessary.

llvm-svn: 110241
2010-08-04 19:52:50 +00:00
Dan Gohman
68ac0492a4 Make SCEVUnknown a CallbackVH, so that it can be notified directly
of Value deletions and RAUWs, instead of relying on ScalarEvolution's
Scalars map being notified, as that's complicated at best, and
insufficient in general.

This means SCEVUnknown needs a non-trivial destructor, so introduce
a mechanism to allow ScalarEvolution to locate all the SCEVUnknowns.

llvm-svn: 110086
2010-08-02 23:49:30 +00:00
Oscar Fuentes
4742c01c2a Prefix next' iterator operation with llvm::'.
Fixes potential ambiguity problems on VS 2010.

Patch by nobled!

llvm-svn: 110029
2010-08-02 06:00:15 +00:00
Eric Christopher
6a1da7b4a5 Speculatively revert r109705 since it seems to be causing some build bot
angst.

llvm-svn: 109718
2010-07-29 01:25:38 +00:00
Dan Gohman
ea1486b53c Factor out some of the code for updating old SCEVUnknown values, and
extend it to handle the case where multiple RAUWs affect a single
SCEVUnknown.

Add a ScalarEvolution unittest to test for this situation.

llvm-svn: 109705
2010-07-29 00:17:55 +00:00
Dan Gohman
2bea1e1572 Make SCEVCallbackVH::allUsesReplacedWith update the old SCEVUnknown
object, as it may still be referenced by SCEVs not cleaned up by the
use list traversal.

Also, in ScalarEvolution::forgetValue, only check for a SCEVUnknown
object for the original value, not for any value in the use list,
because other SCEVUnknown values aren't necessary obsolete at that
point.

llvm-svn: 109570
2010-07-28 01:09:07 +00:00
Dan Gohman
9a6ea54d94 Make SCEVCallbackVH::allUsesReplacedWith unconditionally delete
the old value.

llvm-svn: 109567
2010-07-28 00:28:25 +00:00
Dan Gohman
188a4d7d53 Micro-optimize SCEVComplexityCompare.
llvm-svn: 109267
2010-07-23 21:20:52 +00:00
Dan Gohman
2de2b0713e Add a const qualifier.
llvm-svn: 109266
2010-07-23 21:18:55 +00:00
Gabor Greif
96a9f8c7c6 mass elimination of reliance on automatic iterator dereferencing
llvm-svn: 109103
2010-07-22 13:36:47 +00:00
Owen Anderson
f8addbb0a1 Fix batch of converting RegisterPass<> to INTIALIZE_PASS().
llvm-svn: 109045
2010-07-21 22:09:45 +00:00
Dan Gohman
61bb92a5ff Add a fast path for x - x.
llvm-svn: 108855
2010-07-20 16:53:00 +00:00
Dan Gohman
04768aa9a5 Teach ScalarEvolution how to fold trunc(undef) and anyext(undef) to undef.
This helps LSR behave more consistently on bugpoint-reduced testcases.

llvm-svn: 108451
2010-07-15 20:02:11 +00:00
Dan Gohman
547c92af20 In ScalarEvolution::forgetValue, eliminate any SCEVUnknown
entries associated with the value being erased in the
folding set map.  These entries used to be harmless, because
a SCEVUnknown doesn't store any information about its Value*,
so having a new Value allocated at the old Value's address
wasn't a problem. But now that ScalarEvolution is storing more
information about values, this is no longer safe.

llvm-svn: 107316
2010-06-30 20:21:12 +00:00
Dan Gohman
683a9e2498 Revert the part of r107257 which introduced new logic for using
nsw and nuw flags from IR Instructions. On further consideration,
this isn't valid.

llvm-svn: 107298
2010-06-30 17:27:11 +00:00
Dan Gohman
b7fc09a156 Improve ScalarEvolution's nsw and nuw preservation.
llvm-svn: 107257
2010-06-30 07:16:37 +00:00
Dan Gohman
7446416058 When computing a new ConservativeResult, intersect it with
the old one instead of replacing it, to be more precise.

llvm-svn: 107256
2010-06-30 06:58:35 +00:00
Dan Gohman
32534063c7 Fix ScalarEvolution's tripcount computation for chains of loops
where each loop's induction variable's start value is the exit
value of a preceding loop.

llvm-svn: 107224
2010-06-29 23:43:06 +00:00
Dan Gohman
f5dfb360be Just as its not safe to blindly transfer the nsw bit from an add
instruction to an add scev, it's not safe to blindly transfer the
inbounds flag from a gep instruction to an nsw on the scev for the
gep.

llvm-svn: 107117
2010-06-29 01:41:41 +00:00
Dan Gohman
01de3704f9 Eliminate a redundant FoldingSet lookup.
llvm-svn: 106872
2010-06-25 18:47:08 +00:00
Dan Gohman
bfbfa95b51 Don't try to preserve pointer types in SCEVConstants; the old code
was over-complicated.

llvm-svn: 106760
2010-06-24 16:47:03 +00:00
Dan Gohman
35a5a7285a Make the trunc code consistent with the zext and sext code in its
handling of pointer types.

llvm-svn: 106757
2010-06-24 16:33:38 +00:00
Dan Gohman
f44783ab4e Replace ScalarEvolution's private copy of getLoopPredecessor
with LoopInfo's public copy.

llvm-svn: 106603
2010-06-22 23:43:28 +00:00
Dan Gohman
a3bc6b13f7 Allow "exhaustive" trip count evaluation on phi nodes with all
constant operands.

llvm-svn: 106537
2010-06-22 13:15:46 +00:00
Dan Gohman
6a3c46ad49 Use A.append(...) instead of A.insert(A.end(), ...) when A is a
SmallVector, and other SmallVector simplifications.

llvm-svn: 106452
2010-06-21 19:47:52 +00:00
Dan Gohman
cec5b682b6 Fix ScalarEvolution's "exhaustive" trip count evaluation code to avoid
assuming that loops are in canonical form, as ScalarEvolution doesn't
depend on LoopSimplify itself. Also, with indirectbr not all loops can
be simplified. This fixes PR7416.

llvm-svn: 106389
2010-06-19 14:17:24 +00:00
Dan Gohman
b5ec637e57 Revert r106304 (105548 and friends), which are the SCEVComplexityCompare
optimizations. There is still some nondeterminism remaining.

llvm-svn: 106306
2010-06-18 19:54:20 +00:00
Dan Gohman
527b570925 Reapply 105540, 105542, and 105548, and revert r105732.
llvm-svn: 106304
2010-06-18 19:26:04 +00:00
Dan Gohman
75f6f94c48 Reapply 105546.
llvm-svn: 106302
2010-06-18 19:12:32 +00:00
Dan Gohman
ab895769a7 Reapply 105544.
llvm-svn: 106301
2010-06-18 19:09:27 +00:00
Dan Gohman
e20e668c7e Remove getIntegerSCEV; it's redundant with getConstant, and getConstant
is more consistent with the ConstantInt API.

llvm-svn: 106281
2010-06-18 14:33:50 +00:00
Dan Gohman
1d9d93381a Simplify this code.
llvm-svn: 106254
2010-06-17 23:34:09 +00:00
Evan Cheng
28c151ae52 Revert 105540, 105542, 105544, 105546, and 105548 to unbreak bootstrapping.
llvm-svn: 105740
2010-06-09 18:59:43 +00:00
Dan Gohman
490f4d7020 The FoldingSet hash data includes pointer values, so it isn't
determinstic. Instead, give SCEV objects an arbitrary sequence
number.

llvm-svn: 105548
2010-06-07 19:36:14 +00:00
Dan Gohman
ee75f6f4dd Optimize this code somewhat by taking advantage of the fact
that the operands are sorted.

llvm-svn: 105546
2010-06-07 19:20:57 +00:00
Dan Gohman
e4676a62de Micro-optimize this, to speed up this hotspot in debug builds a little.
llvm-svn: 105544
2010-06-07 19:16:37 +00:00
Dan Gohman
044a968609 Micro-optimize this.
llvm-svn: 105542
2010-06-07 19:12:54 +00:00
Dan Gohman
65954b2eb4 Optimize ScalarEvolution's SCEVComplexityCompare predicate: don't go
scrounging through SCEVUnknown contents and SCEVNAryExpr operands;
instead just do a simple deterministic comparison of the precomputed
hash data.

Also, since this is more precise, it eliminates the need for the slow
N^2 duplicate detection code.

llvm-svn: 105540
2010-06-07 19:06:13 +00:00
Dan Gohman
5ba21692e6 ConstantFoldConstantExpression can theoretically return null.
llvm-svn: 104948
2010-05-28 16:12:08 +00:00
Dan Gohman
5c61a913b2 Use the SCEVAddRecExpr::getPostIncExpr utility function instead
of doing the same thing manually.

llvm-svn: 102997
2010-05-04 01:12:27 +00:00
Dan Gohman
4e1dbacdf8 Fix a copy+pasto.
llvm-svn: 102996
2010-05-04 01:11:15 +00:00
Dan Gohman
2f27d59870 Use getConstant instead of getIntegerSCEV. The two are basically the
same, now that getConstant has overloads consistent with ConstantInt::get.

llvm-svn: 102965
2010-05-03 22:09:21 +00:00
Dan Gohman
66c6519877 Silence warnings about -1 being converted to an unsigned value.
Also, pass true for isSigned even when creating constants for unsigned
comparisons, because the point is to create an all-ones constant,
rather than UINT64_MAX, even for integers wider than 64 bits.

llvm-svn: 102946
2010-05-03 20:23:47 +00:00
Dan Gohman
51faf74c7d Use isTrueWhenEqual and isFalseWhenEqual instead of assuming that
SimplifyICmpOperands will simplify such cases to EQ or NE. This makes
the correcntess of the code independent on SimplifyICmpOperands doing
certain simplifications.

llvm-svn: 102927
2010-05-03 18:00:24 +00:00
Dan Gohman
b4fdc7ea81 In ScalarEvolution::print, don't bother printing out the SCEVs for
comparison instructions, since they aren't interesting, despite having
integer result types.

llvm-svn: 102925
2010-05-03 17:03:23 +00:00
Dan Gohman
043875bc90 In SimplifyICmpOperands, avoid needlessly swapping the operands in the
case where both are addrecs in unrelated loops.

llvm-svn: 102924
2010-05-03 17:00:11 +00:00
Dan Gohman
02c26ed601 Factor out the new <= and >= analysis code into SimplifyICmpOperands.
llvm-svn: 102922
2010-05-03 16:35:17 +00:00
Dan Gohman
116829ede7 Set isSigned to true when creating an all-ones integer constant, even
for unsigned purposes, so >64-bit integer values get a full all-ones
value.

llvm-svn: 102739
2010-04-30 19:22:39 +00:00
Dan Gohman
3c454a3df0 Silence compiler warnings.
llvm-svn: 102734
2010-04-30 19:21:13 +00:00
Dan Gohman
231fe284cd ScalarEvolution support for <= and >= loops.
Also, generalize ScalarEvolutions's min and max recognition to handle
some new forms of min and max that this change makes more common.

llvm-svn: 102234
2010-04-24 03:09:42 +00:00
Dan Gohman
bae847c4c6 Use SimplifyICmpOperands in isKnownPredicate too.
llvm-svn: 102233
2010-04-24 01:38:36 +00:00
Dan Gohman
815586b78c Update isImpliedCond to use the new SimplifyICmpOperands utility.
llvm-svn: 102232
2010-04-24 01:34:53 +00:00
Dan Gohman
0fbfae5efe Add a new utility function SimplifyICmpOperands. Much of this code is
refactored out of ScalarEvolution::isImpliedCond, which will be updated
to use this new utility routine soon.

llvm-svn: 102229
2010-04-24 01:28:42 +00:00
Dan Gohman
4196c77b3b When it doesn't matter whether zero or sign extension is used,
use ScalarEvolutions "any" extend function.

llvm-svn: 102156
2010-04-23 01:51:29 +00:00
Dan Gohman
31d6b29bae Don't attempt to analyze values which are obviously undef. This fixes some
assertion failures in extreme cases.

llvm-svn: 102042
2010-04-22 01:35:11 +00:00
Dan Gohman
4ca879bebb Make ScalarEvolution::getConstant support pointer types, for consistency
with ScalarEvolution's overall approach to pointer types.

llvm-svn: 102003
2010-04-21 16:04:04 +00:00
Dan Gohman
2d575a91e0 Fix SCEVCommutativeExpr::print to be robust in the case of improper
expression canonicalization. Its job is to print what's there, not to
make judgements about it.

llvm-svn: 101461
2010-04-16 15:03:25 +00:00
Dan Gohman
034c0f7354 Make getPredecessorWithUniqueSuccessorForBB return the unique successor
in addition to the predecessor.

llvm-svn: 101374
2010-04-15 16:19:08 +00:00
Dan Gohman
a71d62f6e4 Add a comment.
llvm-svn: 101248
2010-04-14 16:08:56 +00:00
Dan Gohman
1521831bff Teach ScalarEvolution to simplify smax and umax when it can prove
that one operand is always greater than another.

llvm-svn: 101142
2010-04-13 16:51:03 +00:00
Dan Gohman
298e7410d6 Minor code micro-optimizations.
llvm-svn: 101141
2010-04-13 16:49:23 +00:00
Dan Gohman
2b5e134433 Micro-optimize a few hot spots.
llvm-svn: 101086
2010-04-12 23:08:18 +00:00
Dan Gohman
ece51fc413 Add fast paths to ScalarEvolution::getSizeOf and getOffsetOf, as
they're used a lot by getNodeForGEP, which can be called a lot.
This speeds up -iv-users by around 15% on several testcases.

llvm-svn: 101083
2010-04-12 23:03:26 +00:00
Dan Gohman
e87da8a25d Generalize ScalarEvolution's PHI analysis to handle loops that don't
have preheaders or dedicated exit blocks, as clients may not otherwise
need to run LoopSimplify.

llvm-svn: 101030
2010-04-12 07:49:36 +00:00
Dan Gohman
eee8b53fdb Rewrite the overflow checking in the get{Signed,Unsigned}Range code for
AddRecs so that it checks for overflow in the computation that it is
performing, rather than just checking hasNo{Signed,Unsigned}Wrap, since
those flags are for a different computation. This fixes a bug that
impacts an upcoming change.

llvm-svn: 101028
2010-04-12 07:39:33 +00:00
Dan Gohman
3bf0040d05 Fix indentation.
llvm-svn: 101001
2010-04-11 23:44:58 +00:00
Dan Gohman
ff456e3f4d Enhance ScalarEvolution::isKnownPredicate with support for
loop conditions which are invariants.

llvm-svn: 100995
2010-04-11 22:16:48 +00:00
Dan Gohman
f73ed98d56 Minor code simplification.
llvm-svn: 100994
2010-04-11 22:13:11 +00:00
Dan Gohman
07d134b751 When creating a ConstantRange for [n,UINT_MAX], special case n == 0, because
ConstantRange(0, 0) creates an empty range rather than a full one.

llvm-svn: 100993
2010-04-11 22:12:18 +00:00
Dan Gohman
9ca5efece4 Rename isLoopGuardedByCond to isLoopEntryGuardedByCond, to emphasise
that it's only testing for the entry condition, not full loop-invariant
conditions.

llvm-svn: 100979
2010-04-11 19:27:13 +00:00
Dan Gohman
127f5c53e1 Add variants of ult, ule, etc. which take a uint64_t RHS, for convenience.
llvm-svn: 100824
2010-04-08 23:03:40 +00:00
Dan Gohman
bd878ac80b Revert this change from a while ago; ScalarEvolution shouldn't analyze
undef as 0, since it can't force other analyses to intepret the undef
in the same way.

llvm-svn: 100749
2010-04-08 05:58:24 +00:00
Dan Gohman
ff37afdc4b Define placement new wrappers for BumpPtrAllocator and
RecyclingAllocator to allow client code to be simpler, and
simplify several clients.

llvm-svn: 98847
2010-03-18 18:49:47 +00:00
Dan Gohman
8f98d70a9b Add the ability to "intern" FoldingSetNodeID data into a
BumpPtrAllocator-allocated region to allow it to be stored in a more
compact form and to avoid the need for a non-trivial destructor call.

Use this new mechanism in ScalarEvolution instead of
FastFoldingSetNode to avoid leaking memory in the case where a
FoldingSetNodeID uses heap storage, and to reduce overall memory
usage.

llvm-svn: 98829
2010-03-18 16:16:38 +00:00
Dan Gohman
69cd222c14 Reapply r98755 with a thinko which miscompiled gengtype fixed.
llvm-svn: 98793
2010-03-18 01:17:13 +00:00
Dan Gohman
f9a688a249 Revert 98755, which may be causing trouble.
llvm-svn: 98762
2010-03-17 19:54:53 +00:00
Dan Gohman
d90131eff2 Change SCEVNAryExpr's operand array from a SmallVector to a plain
pointer and length, and allocate the arrays in ScalarEvolution's
BumpPtrAllocator, so that they get released when their owning
SCEV gets released. SCEVs are immutable, so they don't need to worry
about operand array resizing. This fixes a memory leak reported
in PR6637.

llvm-svn: 98755
2010-03-17 18:51:01 +00:00
Dan Gohman
a722142044 Avoid analyzing instructions in blocks not reachable from the entry block.
They are lots of trouble, and they don't matter. This fixes PR6559.

llvm-svn: 98103
2010-03-09 23:46:50 +00:00
Dan Gohman
c08c48c9f3 Spelling fixes.
llvm-svn: 97453
2010-03-01 17:49:51 +00:00
Dan Gohman
52ed61204b Make LoopSimplify change conditional branches in loop exiting blocks
which branch on undef to branch on a boolean constant for the edge
exiting the loop. This helps ScalarEvolution compute trip counts for
loops.

Teach ScalarEvolution to recognize single-value PHIs, when safe, and
ForgetSymbolicName to forget such single-value PHI nodes as apprpriate
in ForgetSymbolicName.

llvm-svn: 97126
2010-02-25 06:57:05 +00:00
Dan Gohman
4d65bd9c6a ConstantFoldInstOperands can theoretically return null if it
didn't fold anything.

llvm-svn: 97049
2010-02-24 19:31:47 +00:00
Dan Gohman
fa19b098dc Simplify this code; these casts aren't necessary.
llvm-svn: 97048
2010-02-24 19:31:06 +00:00
Dan Gohman
6aacf4728c Convert a few more backedge-taken count functions to use BackedgeTakenInfo.
llvm-svn: 97042
2010-02-24 17:31:30 +00:00
Dan Gohman
2575392bf1 Remove unused variables and parameters.
llvm-svn: 96780
2010-02-22 04:11:59 +00:00
Dan Gohman
39b7e5961e Add a comment.
llvm-svn: 96688
2010-02-19 18:49:22 +00:00
Dan Gohman
9268d67079 Teach ScalarEvolution how to compute a tripcount for a loop with
true or false as its exit condition. These are usually eliminated by
SimplifyCFG, but the may be left around during a pass which wishes
to preserve the CFG.

llvm-svn: 96683
2010-02-19 18:12:07 +00:00
Dale Johannesen
0f58c73229 recommit 96626, evidence that it broke things appears
to be spurious

llvm-svn: 96662
2010-02-19 07:14:22 +00:00
Dale Johannesen
d73b81bf12 Revert 96626, which causes build failure on ppc Darwin.
llvm-svn: 96653
2010-02-19 01:54:37 +00:00
Dan Gohman
2f0615ee5e Indvars needs to explicitly notify ScalarEvolution when it is replacing
a loop exit value, so that if a loop gets deleted, ScalarEvolution
isn't stick holding on to dangling SCEVAddRecExprs for that loop. This
fixes PR6339.

llvm-svn: 96626
2010-02-18 23:26:33 +00:00
Duncan Sands
1b33dd3c83 There are two ways of checking for a given type, for example isa<PointerType>(T)
and T->isPointerTy().  Convert most instances of the first form to the second form.
Requested by Chris.

llvm-svn: 96344
2010-02-16 11:11:14 +00:00
Duncan Sands
2acaf3609c Uniformize the names of type predicates: rather than having isFloatTy and
isInteger, we now have isFloatTy and isIntegerTy.  Requested by Chris!

llvm-svn: 96223
2010-02-15 16:12:20 +00:00
Dan Gohman
adc600ceb5 When testing whether a given SCEV depends on a temporary symbolic
name, test whether the SCEV itself is that temporary symbolic name,
in addition to checking whether the symbolic name appears as a
possibly-indirect operand.

llvm-svn: 96216
2010-02-15 10:28:37 +00:00
Dan Gohman
1e93b1c022 Override dominates and properlyDominates for SCEVAddRecExpr, as a
SCEVAddRecExpr doesn't necessarily dominate blocks merely dominated
by all of its operands. This fixes an abort compiling 403.gcc.

llvm-svn: 96056
2010-02-13 00:19:39 +00:00