Commit Graph

630 Commits

Author SHA1 Message Date
Andrew Trick a51d74fc35 Set NSW/NUW flags on SCEVAddExpr when the operation is flagged as
such.

I'm doing this now for completeness because I can't think of/remember
any reason that it was left out. I'm not sure it will help anything,
but if we don't do it we need to explain why in comments.

llvm-svn: 139450
2011-09-10 01:09:50 +00:00
Nick Lewycky e0aa54bb98 This transform only handles two-operand AddRec's. Prevent it from trying to
handle anything more complex. Fixes PR10383 again!

llvm-svn: 139186
2011-09-06 21:42:18 +00:00
Nick Lewycky 78664db054 Fix typo in comment again.
llvm-svn: 139139
2011-09-06 07:02:40 +00:00
Nick Lewycky 237878b7ac Apparently we compile the code, not the comments. Thanks Eli!
llvm-svn: 139138
2011-09-06 06:56:00 +00:00
Nick Lewycky 0af94cc50b Fix typo in comment.
llvm-svn: 139137
2011-09-06 06:46:01 +00:00
Nick Lewycky 702cf1eccc Nope! I had it right the first time. Revert the operative part of r139135 and
add more showing of my work.

llvm-svn: 139136
2011-09-06 06:39:54 +00:00
Nick Lewycky 6f86e001d6 Fix flipped sign. While there, show my math.
llvm-svn: 139135
2011-09-06 05:33:18 +00:00
Nick Lewycky db66b82dd5 No no no, fix typo properly!
llvm-svn: 139134
2011-09-06 05:08:09 +00:00
Nick Lewycky 658bdb5133 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 b1438c763a Revert r139126 due to selfhost failures reported by buildbots.
llvm-svn: 139130
2011-09-06 02:43:13 +00:00
Nick Lewycky c4c43fbb07 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 bbb226a827 Comment and clarifying assert.
llvm-svn: 139036
2011-09-02 21:20:46 +00:00
Andrew Trick 2b6860f0a1 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 6d45a01b67 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 77c55428fa Use consistent terminology for loop exit/exiting blocks. Name change only.
llvm-svn: 136677
2011-08-02 04:23:35 +00:00
Andrew Trick 3ca3f98c2c 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 f4b14a2b0d Use ArrayRef in ConstantFoldInstOperands and ConstantFoldCall.
llvm-svn: 135477
2011-07-19 13:32:40 +00:00
Chris Lattner 229907cd11 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 8ef3ad049d SCEV: missing null check fix for r132360, dragonegg crash.
llvm-svn: 132416
2011-06-01 19:14:56 +00:00
Andrew Trick 812276eed4 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 0daf687e1d Change a few std::maps to DenseMaps.
llvm-svn: 131088
2011-05-09 18:44:09 +00:00
Andrew Trick 7d1eea86d9 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 01eff820ae Test case and comment for PR9633.
llvm-svn: 130294
2011-04-27 05:42:17 +00:00
Andrew Trick 759ba0802d 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 6acd95b3c1 Fix an iterator invalidation bug.
llvm-svn: 130166
2011-04-25 22:48:29 +00:00
Chris Lattner 0ab5e2cded 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 87716c93c2 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 a34f1b1f10 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 f6b01ff422 Propagate SCEV no-wrap flags whenever possible.
This needs review.

llvm-svn: 127638
2011-03-15 00:37:00 +00:00
Andrew Trick e92dcceab7 Negating a recurrence preserves no-self-wrap.
llvm-svn: 127593
2011-03-14 17:38:54 +00:00
Andrew Trick f1781db622 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 8b55b736b1 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 2afa325811 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 2a3b71684a whitespace
llvm-svn: 127340
2011-03-09 17:23:39 +00:00
Chris Lattner 4f23f2be15 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 7936a8a488 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 d9e6b4a8ff 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 3ac8cd614f Add a comment.
llvm-svn: 124126
2011-01-24 17:54:18 +00:00
Nick Lewycky d4192f71b5 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 bc98f5b78e Use value ranges to fold ext(trunc) in SCEV when possible.
llvm-svn: 124062
2011-01-23 06:20:19 +00:00
Nick Lewycky b32c8943e6 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 5c901f3489 Similarly, analyze truncate through multiply.
llvm-svn: 123842
2011-01-19 18:56:00 +00:00
Nick Lewycky 5143f0f09b 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 e9ea75e3fc Add a missing SCEV simplification sext(zext x) --> zext x.
llvm-svn: 123832
2011-01-19 15:56:12 +00:00
Chris Lattner d30de95520 some comment improvements.
llvm-svn: 123243
2011-01-11 17:11:59 +00:00
Eric Christopher 23bf3bafb7 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 23109cb319 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 67f82314af add a fixme: ir isn't expressive enough.
llvm-svn: 123139
2011-01-09 23:02:10 +00:00
Chris Lattner 28f140a33e 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 dff679f4b6 rearrange some code, no functionality change.
llvm-svn: 123136
2011-01-09 22:39:48 +00:00