Nick Lewycky
a58fb48a55
Now that we look at all the header PHIs, we need to consider all the header PHIs
...
when deciding that the loop has stopped evolving. Fixes miscompile in the gcc
torture testsuite!
llvm-svn: 142843
2011-10-24 21:02:38 +00:00
Nick Lewycky
9be7f277e4
Reapply r142781 with fix. Original message:
...
Enhance SCEV's brute force loop analysis to handle multiple PHI nodes in the
loop header when computing the trip count.
With this, we now constant evaluate:
struct ListNode { const struct ListNode *next; int i; };
static const struct ListNode node1 = {0, 1};
static const struct ListNode node2 = {&node1, 2};
static const struct ListNode node3 = {&node2, 3};
int test() {
int sum = 0;
for (const struct ListNode *n = &node3; n != 0; n = n->next)
sum += n->i;
return sum;
}
llvm-svn: 142790
2011-10-24 06:57:05 +00:00
Nick Lewycky
8e904dee82
PHI nodes not in the loop header aren't part of the loop iteration initial
...
state. Furthermore, they might not have two operands. This fixes the underlying
issue behind the crashes introduced in r142781.
llvm-svn: 142788
2011-10-24 05:51:01 +00:00
Nick Lewycky
9d28c26d77
Speculatively revert r142781. Bots are showing
...
Assertion `i_nocapture < OperandTraits<PHINode>::operands(this) && "getOperand() out of range!"' failed.
coming out of indvars.
llvm-svn: 142786
2011-10-24 04:00:25 +00:00
Nick Lewycky
1700007ecc
Enhance SCEV's brute force loop analysis to handle multiple PHI nodes in the
...
loop header when computing the trip count.
With this, we now constant evaluate:
struct ListNode { const struct ListNode *next; int i; };
static const struct ListNode node1 = {0, 1};
static const struct ListNode node2 = {&node1, 2};
static const struct ListNode node3 = {&node2, 3};
int test() {
int sum = 0;
for (const struct ListNode *n = &node3; n != 0; n = n->next)
sum += n->i;
return sum;
}
llvm-svn: 142781
2011-10-23 23:43:14 +00:00
Nick Lewycky
a6674c7fc9
Make SCEV's brute force analysis stronger in two ways. Firstly, we should be
...
able to constant fold load instructions where the argument is a constant.
Second, we should be able to watch multiple PHI nodes through the loop; this
patch only supports PHIs in loop headers, more can be done here.
With this patch, we now constant evaluate:
static const int arr[] = {1, 2, 3, 4, 5};
int test() {
int sum = 0;
for (int i = 0; i < 5; ++i) sum += arr[i];
return sum;
}
llvm-svn: 142731
2011-10-22 19:58:20 +00:00
Nick Lewycky
a447e0f38f
An instruction's operands aren't necessarily instructions or constants. They
...
could be arguments, for example.
No testcase because this is a bug-fix broken out of a larger optimization patch.
llvm-svn: 141951
2011-10-14 09:38:46 +00:00
Andrew Trick
3e8a576da1
Fixes PR11070 - assert in SCEV getConstantEvolvingPHIOperands.
...
llvm-svn: 141219
2011-10-05 22:06:53 +00:00
Andrew Trick
ed39bb8efd
Typo. Thanks Bob.
...
llvm-svn: 141188
2011-10-05 16:52:28 +00:00
Chandler Carruth
f6567a131d
Fix a broken assert found by -Wparentheses.
...
llvm-svn: 141168
2011-10-05 07:02:23 +00:00
Andrew Trick
e9162f1ff8
Fix disabled SCEV analysis caused r141161 and add unit test.
...
I noticed during self-review that my previous checkin disabled some
analysis. Even with the reenabled analysis the test case runs in about
5ms. Without the fix, it will take several minutes at least.
llvm-svn: 141164
2011-10-05 05:58:49 +00:00
Andrew Trick
3a86ba767c
Avoid exponential recursion in SCEV getConstantEvolvingPHI and EvaluateExpression.
...
Note to compiler writers: never recurse on multiple instruction
operands without memoization.
Fixes rdar://10187945. Was taking 45s, now taking 5ms.
llvm-svn: 141161
2011-10-05 03:25:31 +00:00
Nick Lewycky
287682ead1
The product of two chrec's can always be represented as a chrec.
...
llvm-svn: 141066
2011-10-04 06:51:26 +00:00
Nick Lewycky
3155552461
Reapply r140979 with fix! We never did get a testcase, but careful review of the
...
logic by David Meyer revealed this bug.
llvm-svn: 140992
2011-10-03 07:10:45 +00:00
Nick Lewycky
b1dbce1406
Revert r140979 due to reports of bootstrap failure.
...
llvm-svn: 140980
2011-10-03 05:14:59 +00:00
Nick Lewycky
3c624b8d0d
Add one more case we compute a max trip count.
...
llvm-svn: 140979
2011-10-03 01:03:57 +00:00
Andrew Trick
ef8e4efff8
indvars: generalize SCEV getPreStartForSignExtend.
...
Handle general Add expressions to avoid leaving around redundant
32-bit IVs.
llvm-svn: 140701
2011-09-28 17:02:54 +00:00
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