Commit Graph

2211 Commits

Author SHA1 Message Date
Dan Gohman
86fbf2fe4c Rename UnknownValue to CouldNotCompute, since it holds an instance of
SCEVCouldNotCompute, and not SCEVUnknown.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72999 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-06 14:37:11 +00:00
Devang Patel
5c06f61e57 Simplify.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72970 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-05 23:08:56 +00:00
Dan Gohman
1d09de3eca Move SCEVExpander::getOrInsertCanonicalInductionVariable out of line.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72949 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-05 16:35:53 +00:00
Dan Gohman
c965ee223c Remove some unnecessary #includes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72948 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-05 16:32:58 +00:00
Dan Gohman
ae3a0be92e Split the Add, Sub, and Mul instruction opcodes into separate
integer and floating-point opcodes, introducing
FAdd, FSub, and FMul.

For now, the AsmParser, BitcodeReader, and IRBuilder all preserve
backwards compatability, and the Core LLVM APIs preserve backwards
compatibility for IR producers. Most front-ends won't need to change
immediately.

This implements the first step of the plan outlined here:
http://nondot.org/sabre/LLVMNotes/IntegerOverflow.txt


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72897 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-04 22:49:04 +00:00
Dan Gohman
7714285efd Change ConstantFoldConstantExpression to accept a null
TargetData pointer. The only thing it's used for are
calls to ConstantFoldCompareInstOperands and
ConstantFoldInstOperands, which both already accept a
null TargetData pointer. This makes
ConstantFoldConstantExpression easier to use in clients
where TargetData is optional.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72741 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-02 21:48:15 +00:00
Dan Gohman
18a69c5a36 Delete an obsolete sentance from a comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72667 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-31 16:18:57 +00:00
Dan Gohman
f1a80489d6 Add braces around an array initializer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72453 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-27 02:07:15 +00:00
Dan Gohman
4a4f767235 Teach SCEVExpander to avoid creating over-indexed GEP indices when
possible. For example, it now emits

  %p.2.ip.1 = getelementptr [3 x [3 x double]]* %p, i64 2, i64 %tmp, i64 1

instead of the equivalent but less obvious

  %p.2.ip.1 = getelementptr [3 x [3 x double]]* %p, i64 0, i64 %tmp, i64 19


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72452 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-27 02:00:53 +00:00
Dan Gohman
72776d2190 Teach BasicAliasAnalysis to understand constant gep indices that fall
beyond their associated static array type.

I believe that this fixes a legitimate bug, because BasicAliasAnalysis
already has code to check for this condition that works for non-constant
indices, however it was missing the case of constant indices. With this
change, it checks for both.

This fixes PR4267, and miscompiles of SPEC 188.ammp and 464.h264.href.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72451 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-27 01:48:27 +00:00
Dan Gohman
91bb61a1e2 For the return type of SCEVUDivExpr, use the RHS' type instead of
that of the LHS. It doesn't matter for correctness, but the LHS
is more likely than the RHS to be a pointer type in exotic cases,
and it's more tidy to have it return the integer type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72424 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-26 17:44:05 +00:00
Dan Gohman
f876ad0a70 In cases where a pointer value is an operand of a multiplication or
division operation, don't attempt to use the operation's value as
the base of a getelementptr. This fixes PR4271.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72422 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-26 17:41:16 +00:00
Chris Lattner
ab9cf1282b make memdep use the getModRefInfo method for stores instead of the
low-level alias() method, allowing it to reason more aggressively
about pointers into constant memory.  PR4189


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72403 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-25 21:28:56 +00:00
Dan Gohman
6c0866ca83 Various comment fixes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72376 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-24 23:45:28 +00:00
Dan Gohman
d594e6f034 Change ScalarEvolution::getSCEVAtScope to always return the original value
in the case where a loop exit value cannot be computed, instead of only in
some cases while using SCEVCouldNotCompute in others. This simplifies
getSCEVAtScope's callers.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72375 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-24 23:25:42 +00:00
Torok Edwin
3790fb0c03 Instead of clearing the rewriter, don't attempt to rewrite dead phi nodes.
Also fix 80 column violation.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72371 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-24 19:36:09 +00:00
Dan Gohman
fb5a3419f3 Fix this code for hosts where std::vector doesn't have .data().
Use &Ops[0] instead, which is safe since Ops will never be empty here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72368 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-24 19:02:45 +00:00
Dan Gohman
453aa4fbf1 Generalize SCEVExpander::visitAddRecExpr's GEP persuit, and avoid
sending SCEVUnknowns to expandAddToGEP. This avoids the need for
expandAddToGEP to bend the rules and peek into SCEVUnknown
expressions.

Factor out the code for testing whether a SCEV can be factored by
a constant for use in a GEP index. This allows it to handle
SCEVAddRecExprs, by recursing.

As a result, SCEVExpander can now put more things in GEP indices,
so it emits fewer explicit mul instructions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72366 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-24 18:06:31 +00:00
Dan Gohman
3925043af0 When the low bits of one operand of an add are zero, that number
of low bits of the other operand are preserved in the output.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72365 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-24 18:02:35 +00:00
Torok Edwin
b679de2a21 The rewriter may hold references to instructions that are deleted because they are trivially dead.
Fix by clearing the rewriter cache before deleting the trivially dead
instructions.
Also make InsertedExpressions use an AssertingVH to catch these
bugs easier.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72364 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-24 14:23:16 +00:00
Dan Gohman
0d56b06f86 Fix a thinko in the code that adapted SCEVMulExpr operands for
use in expanding SCEVAddExprs with GEPs. The operands of a
SCEVMulExpr need to be multiplied together, not added.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72250 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-22 07:14:20 +00:00
Jay Foad
e3e51c0038 Use v.data() instead of &v[0] when SmallVector v might be empty.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72210 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-21 09:52:38 +00:00
Dan Gohman
9004c8afd4 Teach ValueTracking a new way to analyze PHI nodes, and and teach
Instcombine to be more aggressive about using SimplifyDemandedBits
on shift nodes. This allows a shift to be simplified to zero in the
included test case.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72204 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-21 02:28:33 +00:00
Dan Gohman
a3035a69f9 Teach SCEV::isLoopInvariant and SCEV::hasComputableLoopEvolution
about the convention from LoopInfo that a null Loop* means the entire
function body.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72152 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-20 01:01:24 +00:00
Dan Gohman
1959b7562e Make SCEVCallbackVH a private nested class inside ScalarEvolution, as
it's an implementation detail.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72122 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-19 19:22:47 +00:00
Dan Gohman
278b49af8a Create ConstantExpr GEPs the correct way. This fixes
MultiSource/Benchmarks/Prolangs-C/football and a variety of other
failures.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72120 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-19 19:18:01 +00:00
Dan Gohman
5be18e8476 Teach SCEVExpander to expand arithmetic involving pointers into GEP
instructions. It attempts to create high-level multi-operand GEPs,
though in cases where this isn't possible it falls back to casting
the pointer to i8* and emitting a GEP with that. Using GEP instructions
instead of ptrtoint+arithmetic+inttoptr helps pointer analyses that
don't use ScalarEvolution, such as BasicAliasAnalysis.

Also, make the AddrModeMatcher more aggressive in handling GEPs.
Previously it assumed that operand 0 of a GEP would require a register
in almost all cases. It now does extra checking and can do more
matching if operand 0 of the GEP is foldable. This fixes a problem
that was exposed by SCEVExpander using GEPs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72093 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-19 02:15:55 +00:00
Daniel Dunbar
8c562e2d25 Silence Release-Asserts warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72011 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 16:43:04 +00:00
Dan Gohman
10978bd591 Teach ScalarEvolution to recognize x^-1 in the case where non-demanded
bits have been stripped out by instcombine.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72010 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 16:29:04 +00:00
Dan Gohman
0bac95e2e2 Delete a redundant 'else'.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72009 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 16:17:44 +00:00
Dan Gohman
8ea94524ed Fix ScalarEvolution::isLoopGuardedByCond to accept a null Loop*, for
consistency with other routines that use a null Loop* to mean code
not contained by any loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72008 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 16:03:58 +00:00
Dan Gohman
5183caebc1 Minor code cleanups. Do more of the work before the if statements
instead of within their controlling expressions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72007 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 15:58:39 +00:00
Dan Gohman
f78a978d46 Add assertion checks to the SCEV operator creation methods to catch
type mismatches.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72006 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 15:44:58 +00:00
Dan Gohman
859b4824ee Make ScalarEvolution::isLoopGuardedByCond work even when the edge
entering a loop is a non-split critical edge.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72004 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 15:36:09 +00:00
Dan Gohman
70a1fe7048 Add an isOne() utility function to ScalarEvolution, similar to isZero()
and similar to ConstantInt's isOne().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72003 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-18 15:22:39 +00:00
Bill Wendling
dc817b6f42 Non-functionality changes:
- Reformatting.
- Use while() instead of do-while().
- Move simple constructors into .h file.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71782 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-14 18:26:15 +00:00
Bill Wendling
e66b291240 Clean up this file fixing 80-column violations, bad formatting, etc. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71781 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-14 18:16:46 +00:00
Duncan Sands
18395d2c3d Avoid getting a compiler warning
IVUsers.cpp: In member function ‘bool llvm::IVUsers::AddUsersIfInteresting(llvm::Instruction*)’:
 IVUsers.cpp:221: warning: ‘isSigned’ may be used uninitialized in this function
with gcc-4.3.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71654 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-13 12:52:44 +00:00
Chris Lattner
21c4bddacf add IVUsers.cpp
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71646 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-13 06:28:04 +00:00
Dan Gohman
467c430316 Add three new helper routines, getNoopOrZeroExtend,
getNoopOrSignExtend, and getTruncateOrNoop. These are similar
to getTruncateOrZeroExtend etc., except that they assert that
the conversion is either not widening or narrowing, as
appropriate. These will be used in some upcoming fixes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71632 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-13 03:46:30 +00:00
Dan Gohman
81db61a2e6 Factor the code for collecting IV users out of LSR into an IVUsers class,
and generalize it so that it can be used by IndVarSimplify. Implement the
base IndVarSimplify transformation code using IVUsers. This removes
TestOrigIVForWrap and associated code, as ScalarEvolution now has enough
builtin overflow detection and folding logic to handle all the same cases,
and more. Run "opt -iv-users -analyze -disable-output" on your favorite
loop for an example of what IVUsers does.

This lets IndVarSimplify eliminate IV casts and compute trip counts in
more cases. Also, this happens to finally fix the remaining testcases
in PR1301.

Now that IndVarSimplify is being more aggressive, it occasionally runs
into the problem where ScalarEvolutionExpander's code for avoiding
duplicate expansions makes it difficult to ensure that all expanded
instructions dominate all the instructions that will use them. As a
temporary measure, IndVarSimplify now uses a FixUsesBeforeDefs function
to fix up instructions inserted by SCEVExpander. Fortunately, this code
is contained, and can be easily removed once a more comprehensive
solution is available.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71535 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-12 02:17:14 +00:00
Dan Gohman
efb9fbfdab When forgetting SCEVs for loop PHIs, don't forget SCEVUnknown values.
These values aren't analyzable, so they don't care if more information
about the loop trip count can be had. Also, SCEVUnknown is used for
a PHI while the PHI itself is being analyzed, so it needs to be left
in the Scalars map. This fixes a variety of subtle issues.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71533 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-12 01:27:58 +00:00
Dan Gohman
42a5875e10 Fix GetMinTrailingZeros for SCEVSignExtend and SCEVZeroExtendExpr to
return the correct value when the cast operand is all zeros. This ought
to be pretty rare, because it would mean that the regular SCEV folding
routines missed a case, though there are cases they might legitimately
miss. Also, it's unlikely anything currently using GetMinTrailingZeros
cares about this case.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71532 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-12 01:23:18 +00:00
Eli Friedman
361e54d433 Allow scalar evolution to compute iteration counts for loops with a
pointer-based condition.  This fixes PR3171.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71354 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-09 12:32:42 +00:00
Duncan Sands
777d2306b3 Rename PaddedSize to AllocSize, in the hope that this
will make it more obvious what it represents, and stop
it being confused with the StoreSize.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71349 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-09 07:06:46 +00:00
Dan Gohman
c63a62735b Don't attempt to handle unsized types in ScalarEvolution's GEP analyzer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71302 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-09 00:14:52 +00:00
Dan Gohman
b0285932ab Fix bogus overflow checks by replacing them with actual
overflow checks.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71284 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-08 23:11:16 +00:00
Dan Gohman
728c7f3059 Fold trunc casts into add-recurrence expressions, allowing the
add-recurrence to be exposed. Add a new SCEV folding rule to
help simplify expressions in the presence of these extra truncs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71264 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-08 21:03:19 +00:00
Dan Gohman
fb79160811 Fix another bug in r71252. This code supports GetElementPtr
constant exprs as well as instructions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71262 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-08 20:58:38 +00:00
Dan Gohman
6bce643c36 Add memoization for getSCEVAtScope results for instructions
which are not analyzed with SCEV techniques, which can require
brute-forcing through a large number of instructions. This
fixes a massive compile-time issue on 400.perlbench (in
particular, the loop in MD5Transform).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71259 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-08 20:47:27 +00:00