1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 12:02:58 +02:00
Commit Graph

414 Commits

Author SHA1 Message Date
Owen Anderson
cc33e89571 Revert the ConstantInt constructors back to their 2.5 forms where possible, thanks to contexts-on-types. More to come.
llvm-svn: 77011
2009-07-24 23:12:02 +00:00
Dan Gohman
4c5b26a78e Fix whitespace.
llvm-svn: 76929
2009-07-24 01:03:59 +00:00
Owen Anderson
cc287b28c9 Get rid of the Pass+Context magic.
llvm-svn: 76702
2009-07-22 00:24:57 +00:00
Dan Gohman
190d29cb5c Replace the original ad-hoc code for determining whether (v pred w) implies
(x pred y) with more thorough code that does more complete canonicalization
before resorting to range checks. This helps it find more cases where
the canonicalized expressions match.

llvm-svn: 76671
2009-07-21 23:03:19 +00:00
Dan Gohman
00fa00fec8 Make the range calculations for addrecs to be more conservative,
as they aren't currently prepared to handle complicated overflow
cases.

llvm-svn: 76524
2009-07-21 00:42:47 +00:00
Dan Gohman
4100aea6ad Whitespace cleanups.
llvm-svn: 76523
2009-07-21 00:38:55 +00:00
Dan Gohman
a37a433693 Minor code simplification.
llvm-svn: 76521
2009-07-21 00:37:45 +00:00
Dan Gohman
47100f32c0 Add a comment to clarify why there isn't any code in this spot.
llvm-svn: 76505
2009-07-20 23:54:43 +00:00
Dan Gohman
857ccb8149 Remove the code that tried to evaluate whether (A pred B) is known
by determining if (B pred (B-A)) is known, as it doesn't handle
overflow correctly.

llvm-svn: 76504
2009-07-20 23:53:35 +00:00
Dan Gohman
b92b14f20b Minor code simplification.
llvm-svn: 76496
2009-07-20 22:41:51 +00:00
Dan Gohman
74a435e9f1 The upper argument of ConstantRange is exclusive, not inclusive.
llvm-svn: 76492
2009-07-20 22:34:18 +00:00
Dan Gohman
00b05492f1 Revert the addition of hasNoPointerOverflow to GEPOperator.
Getelementptrs that are defined to wrap are virtually useless to
optimization, and getelementptrs that are undefined on any kind
of overflow are too restrictive -- it's difficult to ensure that
all intermediate addresses are within bounds. I'm going to take
a different approach.

Remove a few optimizations that depended on this flag.

llvm-svn: 76437
2009-07-20 17:43:30 +00:00
Dan Gohman
25a722cc45 Add a new Operator class, for handling Instructions and ConstantExprs
in a convenient manner, factoring out some common code from
InstructionCombining and ValueTracking. Move the contents of
BinaryOperators.h into Operator.h and use Operator to generalize them
to support ConstantExprs as well as Instructions.

llvm-svn: 76232
2009-07-17 20:47:02 +00:00
Owen Anderson
21d2d69727 Move the ConstantInt uniquing table into LLVMContextImpl. This exposed a number of issues in
our current context-passing stuff, which is also fixed here

llvm-svn: 76089
2009-07-16 18:04:31 +00:00
Dan Gohman
50e65d8c93 Fill in some holes in ScalarEvolution's loop iteration condition
analysis. This allows indvars to emit a simpler loop trip count
expression.

llvm-svn: 76085
2009-07-16 17:34:36 +00:00
Owen Anderson
8c85061ee6 Move EVER MORE stuff over to LLVMContext.
llvm-svn: 75703
2009-07-14 23:09:55 +00:00
Torok Edwin
f955a6ef49 llvm_unreachable->llvm_unreachable(0), LLVM_UNREACHABLE->llvm_unreachable.
This adds location info for all llvm_unreachable calls (which is a macro now) in
!NDEBUG builds.
In NDEBUG builds location info and the message is off (it only prints
"UREACHABLE executed").

llvm-svn: 75640
2009-07-14 16:55:14 +00:00
Dan Gohman
5069f6b40f Make SCEVCallbackVH::allUsesReplacedWith more thorough in removing
users from the Scalars map.

llvm-svn: 75634
2009-07-14 14:34:04 +00:00
Dan Gohman
e69947ca6e Add a comment about why ScalarEvolution doesn't recognize non-loop PHIs
even when they're obvious.

llvm-svn: 75632
2009-07-14 14:06:25 +00:00
Owen Anderson
1404d6e7d1 Move more functionality over to LLVMContext.
llvm-svn: 75559
2009-07-13 23:50:59 +00:00
Dan Gohman
fd3cc860ec Print a newline after printing a Value, now that Value's operator<<
doesn't print a newline.

llvm-svn: 75543
2009-07-13 23:03:05 +00:00
Dan Gohman
5c3d16883e Fix a few assertion strings.
llvm-svn: 75530
2009-07-13 22:20:53 +00:00
Dan Gohman
b8ec6716fd Whitespace cleanups.
llvm-svn: 75525
2009-07-13 22:05:32 +00:00
Dan Gohman
370f5f3116 Fix an 80-column violation.
llvm-svn: 75524
2009-07-13 22:04:06 +00:00
Dan Gohman
a9953c0a28 Reapply 75252, with a fix to avoid the infinite recursion case. The
check for avoiding re-analyzing a widening cast needed to happen
earlier, as getSCEV itself may result in a isLoopGuardedByCond query.

llvm-svn: 75511
2009-07-13 21:35:55 +00:00
Owen Anderson
1e5155161a Move more functionality over to LLVMContext.
llvm-svn: 75497
2009-07-13 20:58:05 +00:00
Dan Gohman
1a780ad8db Move the memoization check for SCEVSignExtendExpr and
SCEVZeroExtendExpr ahead of the most expensive analysis. This
speeds up analysis and helps avoid pathologically bad behavior
on the testcase in PR4534.

llvm-svn: 75496
2009-07-13 20:55:53 +00:00
Dan Gohman
bf3719359b Convert SCEV from FoldingSetNode to FastFoldingSetNode. This eliminates
a bunch of redundent code in Profile methods, and prepares for upcoming
changes to do improved memoization.

llvm-svn: 75494
2009-07-13 20:50:19 +00:00
Owen Anderson
393d8b0a0c Begin the painful process of tearing apart the rat'ss nest that is Constants.cpp and ConstantFold.cpp.
This involves temporarily hard wiring some parts to use the global context.  This isn't ideal, but it's
the only way I could figure out to make this process vaguely incremental.

llvm-svn: 75445
2009-07-13 04:09:18 +00:00
Nick Lewycky
d3d5cfa475 Revert r75252 which was causing some crashes at compile time.
llvm-svn: 75384
2009-07-11 20:38:25 +00:00
Torok Edwin
ae8a3ff177 assert(0) -> LLVM_UNREACHABLE.
Make llvm_unreachable take an optional string, thus moving the cerr<< out of
line.
LLVM_UNREACHABLE is now a simple wrapper that makes the message go away for
NDEBUG builds.

llvm-svn: 75379
2009-07-11 20:10:48 +00:00
Dan Gohman
5749595b5b Remove ScalarEvolution::hasSCEV, which isn't being used, and which
breaks encapsulation. Also remove a dead prototype for setSCEV.

llvm-svn: 75272
2009-07-10 20:25:29 +00:00
Dan Gohman
404a92e330 Generalize ScalarEvolution's cast-folding code to support more kinds
of loops. Add several new functions to for working with ScalarEvolution's
add-hoc value-range analysis functionality.

llvm-svn: 75252
2009-07-10 16:42:52 +00:00
Dan Gohman
05e65cf9e4 Make the code that updates ScalarEvolution's internal state in response
to a loop deletion more thorough. Don't prune the def-use tree search at
instructions that don't have SCEVs computed, because an instruction with
a user that has a computed SCEV may itself lack a computed SCEV.  Also,
remove loop-related values from the ValuesAtScopes and
ConstantEvolutionLoopExitValues maps as well.

This fixes a regression in 483.xalancbmk.

llvm-svn: 75030
2009-07-08 19:23:34 +00:00
Dan Gohman
dd7f97c496 Change all SCEV* to SCEV *.
llvm-svn: 74918
2009-07-07 17:06:11 +00:00
Owen Anderson
121f736d9c "LLVMContext* " --> "LLVMContext *"
llvm-svn: 74878
2009-07-06 23:00:19 +00:00
Owen Anderson
5f268720e9 Finish LLVMContext-ing lib/Analysis. This required pushing LLVMContext's through the ValueTracking API.
llvm-svn: 74873
2009-07-06 22:37:39 +00:00
Owen Anderson
ad3229d281 Thread LLVMContext through the constant folding APIs, which touches a lot of files.
llvm-svn: 74844
2009-07-06 18:42:36 +00:00
Nick Lewycky
d9573d899d When comparing constants, consider a less wide constant to be "less complex"
than a wider one, before trying to compare their contents which will crash
if their sizes are different.

llvm-svn: 74792
2009-07-04 17:24:52 +00:00
Dan Gohman
b3c5210779 Minor code cleanups.
llvm-svn: 74551
2009-06-30 20:13:32 +00:00
Dan Gohman
ab49c8abe9 Use getSCEV instead of getUnknown to create a SCEV for a
Constant. This lets ConstantInts be handled as SCEVConstant instead
of SCEVUnknown, as getUnknown no longer has special-case code for
ConstantInt and friends. This usually doesn't affect the final
output, since the constants end up getting folded later, but it
does make intermediate expressions more obvious in many cases.

llvm-svn: 74459
2009-06-29 21:31:18 +00:00
Dan Gohman
d496b35af0 Don't cache PHI exit values from exhaustive evaluations, because
an individual exhaustive evaluation reflects only the exit value
implied by an individual exit, which may differ from the actual
exit value of the loop if there are other exits. This fixes PR4477.

llvm-svn: 74447
2009-06-29 20:34:13 +00:00
Dan Gohman
011d5bd123 Simplify this code, and avoid using APInt(). This fixes
(otherwise harmless) uninitialized value warnings that
Duncan found with gcc-4.4.

llvm-svn: 74437
2009-06-29 18:25:52 +00:00
Dan Gohman
592d4b6ee0 Convert ScalarEvolution to use BumpPtrAllocator and FoldingSet, instead
of a team of individual allocations and a team of std::maps.

llvm-svn: 74393
2009-06-27 21:21:31 +00:00
Dan Gohman
9e78d55440 Fix ScalarEvolution::getAddRecExpr's code which canonicalized the
nesting order of nested AddRec expressions to skip the transformation
if it would introduce an AddRec with operands not loop-invariant
with respect to its loop.

llvm-svn: 74343
2009-06-26 22:36:20 +00:00
Dan Gohman
e8b1947a18 Fix SCEVAddRecExpr::isLoopInvariant to test if all of its operands
are loop invariant, not just the start operand.

llvm-svn: 74338
2009-06-26 22:17:21 +00:00
Dan Gohman
34b8ca6976 Minor whitespace cleanups.
llvm-svn: 74074
2009-06-24 14:49:00 +00:00
Dan Gohman
b4e1f166e1 Simplify [su]max(MAX, n) to MAX. This comes up in loop tripcount
computations in loops with multiple exits.

Adjust the testcase for PR4436 so that the relevant portion isn't
optimized away.

llvm-svn: 74073
2009-06-24 14:46:22 +00:00
Dan Gohman
19c3326fc9 Delete some orphaned comments, fix some 80-column violations,
and tidy up a few other formatting issues.

llvm-svn: 74060
2009-06-24 04:48:43 +00:00
Dan Gohman
4f4bda36df Extend ScalarEvolution's multiple-exit support to compute exact
trip counts in more cases.

Generalize ScalarEvolution's isLoopGuardedByCond code to recognize
And and Or conditions, splitting the code out into an
isNecessaryCond helper function so that it can evaluate Ands and Ors
recursively, and make SCEVExpander be much more aggressive about
hoisting instructions out of loops.

test/CodeGen/X86/pr3495.ll has an additional instruction now, but
it appears to be due to an arbitrary register allocation difference.

llvm-svn: 74048
2009-06-24 01:18:18 +00:00
Dan Gohman
6f0aa30f94 Teach GetMinSignBits about SCEVAddExprs.
llvm-svn: 74045
2009-06-24 01:05:09 +00:00
Dan Gohman
3bf5d76081 Move the special cases for constants out of getUnknown and into
createSCEV. Also, recognize UndefValue in createSCEV.

Change getIntegerSCEV's comment to avoid mentioning FP types,
and re-implement it in terms of getConstant instead of getUnknown.

llvm-svn: 74041
2009-06-24 00:54:57 +00:00
Dan Gohman
0a2dbfc356 Use ScalarEvolution::getConstant instead of getUnknown to create
SCEVConstants. This cleanup is a step toward letting getUnknown
be simpler.

llvm-svn: 74037
2009-06-24 00:38:39 +00:00
Dan Gohman
774c9da9c6 Include the maximum trip count expression in ScalarEvolution's print output.
llvm-svn: 74035
2009-06-24 00:33:16 +00:00
Dan Gohman
9ccdc738a9 Add an isAllOnesValue utility function, similar to isZero and isOne.
llvm-svn: 74032
2009-06-24 00:30:26 +00:00
Dan Gohman
058143a236 Fix a bug in the trip-count computation with And/Or. If either of the
sides is CouldNotCompute, the resulting exact count must be CouldNotCompute.

llvm-svn: 73920
2009-06-22 23:28:56 +00:00
Owen Anderson
422b2c613b Remove the parent pointer from SCEV, since it did not end up being needed.
llvm-svn: 73907
2009-06-22 21:57:23 +00:00
Owen Anderson
c023151c9f SCEVHandle is no more!
llvm-svn: 73906
2009-06-22 21:39:50 +00:00
Dan Gohman
54899b84bc Fix some typos that Duncan noticed.
llvm-svn: 73903
2009-06-22 21:10:22 +00:00
Owen Anderson
83b6bbdcb4 Banish global state from ScalarEvolution! SCEV uniquing is now done by tables attached to the ScalarEvolution pass.
This also throws out the SCEV reference counting scheme, as the the SCEVs now have a lifetime controlled by the
ScalarEvolution pass.

Note that SCEVHandle is now a no-op, and will be remove in a future commit.

llvm-svn: 73892
2009-06-22 18:25:46 +00:00
Dan Gohman
30b38faa05 Make use of getUMinFromMismatchedTypes when computing backedge-taken
counts for loops with multiple exits, replacing more conservative code
which only handled constants. This is derived from a patch by
Nick Lewycky.

This also fixes llc aborts in ClamAV and others, as
getUMinFromMismatchedTypes takes care of balancing the types before
working with them.

llvm-svn: 73884
2009-06-22 15:09:28 +00:00
Dan Gohman
cc245913e3 Add a getUMinFromMismatchedTypes helper function.
llvm-svn: 73883
2009-06-22 15:03:27 +00:00
Dan Gohman
d65752db50 Factor out code for computing umin and smin for SCEV expressions into
helper functions. Based on a patch by Nick Lewycky.

llvm-svn: 73869
2009-06-22 03:18:45 +00:00
Dan Gohman
db7860aa40 Teach ScalarEvolution how to analyze loops with multiple exit
blocks, and also exit blocks with multiple conditions (combined
with (bitwise) ands and ors). It's often infeasible to compute an
exact trip count in such cases, but a useful upper bound can often
be found.

llvm-svn: 73866
2009-06-22 00:31:57 +00:00
Dan Gohman
b2c544ddbd Delete an unused variable.
llvm-svn: 73865
2009-06-22 00:19:17 +00:00
Dan Gohman
eb0a67278b Fix ScalarEvolution's backedge-taken count computations to check for
overflow when computing a integer division to round up.

Thanks to Nick Lewycky for noticing this!

llvm-svn: 73862
2009-06-21 23:46:38 +00:00
Dan Gohman
29100270c0 Generalize isLoopGuardedByCond's checking to consider two
SCEVUnknowns with identical Instructions to be equal. This allows
it to analze cases such as the attached testcase, where the front-end
has cloned the loop controlling expression. Along with r73805, this
lets IndVarSimplify eliminate all the sign-extend casts in the
loop in the attached testcase.

llvm-svn: 73807
2009-06-20 00:35:32 +00:00
Dan Gohman
074c629d46 Use ScalarEvolution's new GetMinSignBits and GetMinLeadingZeros
in the loop backedge-taken count computation of the maximum
possible trip count.

llvm-svn: 73805
2009-06-20 00:32:22 +00:00
Dan Gohman
d3c3963eea Make GetMinTrailingZeros a member function of ScalarEvolution,
so that it can access the TargetData member (when available) and
use ValueTracking.h information to compute information for
SCEVUnknown Values.

Also add GetMinLeadingZeros and GetMinSignBits functions,
with minimal implementations.

llvm-svn: 73794
2009-06-19 23:29:04 +00:00
Dan Gohman
c71421c97e Make ScalarEvolution::print print getSCEVAtScope values for
expressions, when interesting.

llvm-svn: 73776
2009-06-19 17:49:54 +00:00
Owen Anderson
99dc404fc5 Add a parent pointer to SCEV, in preparation for getting rid of the global uniquing tables. No functionality change.
llvm-svn: 73728
2009-06-18 22:25:12 +00:00
Dan Gohman
cc9634d988 Recognize n != 0 ? n : 1 as umax(n, 1). Previously only ULT/UGT/ULE/UGE
comparisons were recognized for umax, but instcombine canonicalizes
unsigned comparisons with zero to this simpler form.

llvm-svn: 73717
2009-06-18 20:21:07 +00:00
Dan Gohman
b426c5dd35 Update a comment to reflect the code.
llvm-svn: 73704
2009-06-18 16:24:47 +00:00
Dan Gohman
9b236593c3 Fix trailing whitespace from ScalarEvolution::print.
llvm-svn: 73666
2009-06-18 00:37:45 +00:00
Dan Gohman
e72fd546a2 Teach ScalarEvolution how to recognize another xor(and(x, C), C) case.
If C is a single bit and the and gets analyzed as a truncate and
zero-extend, the xor can be represnted as an add.

llvm-svn: 73664
2009-06-18 00:00:20 +00:00
Dan Gohman
eb8d3f5fd5 Delete unnecessary braces.
llvm-svn: 73663
2009-06-17 23:54:37 +00:00
Dan Gohman
473789f75a Fix ScalarEvolution's Xor handling to not assume that an And
that gets recognized with a SCEVZeroExtendExpr must be an And
with a low-bits mask. With r73540, this is no longer the case.

llvm-svn: 73594
2009-06-17 01:22:39 +00:00
Dan Gohman
56b5a88785 Instcombine's ShrinkDemandedConstant may strip bits out of constants,
obscuring what would otherwise be a low-bits mask.  Use ComputeMaskedBits
to compute what ShrinkDemandedConstant knew about to reconstruct a
low-bits mask value.

llvm-svn: 73540
2009-06-16 19:52:01 +00:00
Dan Gohman
2e737ac21f Support vector casts in more places, fixing a variety of assertion
failures.

To support this, add some utility functions to Type to help support
vector/scalar-independent code. Change ConstantInt::get and
ConstantFP::get to support vector types, and add an overload to
ConstantInt::get that uses a static IntegerType type, for
convenience.

Introduce a new getConstant method for ScalarEvolution, to simplify
common use cases.

llvm-svn: 73431
2009-06-15 22:12:54 +00:00
Dan Gohman
d3a8d79c0d Implement more aggressive folding of add operand lists when
they contain multiplications of constants with add operations.
This helps simplify several kinds of things; in particular it
helps simplify expressions like ((-1 * (%a + %b)) + %a) to %b,
as expressions like this often come up in loop trip count
computations.

llvm-svn: 73361
2009-06-14 22:58:51 +00:00
Dan Gohman
bee566c1ce Check for the short-circuiting condition before performing
the potentially expensive erase.

llvm-svn: 73359
2009-06-14 22:53:57 +00:00
Dan Gohman
d1c7be715c Do compare constant SCEV values in SCEVComplexityCompare, because
even though the order doesn't matter at the top level of an expression,
it does matter when the constant is a subexpression of an n-ary
expression, because n-ary expressions are sorted lexicographically.

llvm-svn: 73358
2009-06-14 22:51:25 +00:00
Dan Gohman
d895ed43c8 Convert several parts of the ScalarEvolution framework to use
SmallVector instead of std::vector.

llvm-svn: 73357
2009-06-14 22:47:23 +00:00
Dan Gohman
25827fdc12 Add a ScalarEvolution::getAnyExtendExpr utility function for performing
extension with unspecified bits.

llvm-svn: 73293
2009-06-13 15:56:47 +00:00
Dan Gohman
5470ba421d Rename UnknownValue to CouldNotCompute, since it holds an instance of
SCEVCouldNotCompute, and not SCEVUnknown.

llvm-svn: 72999
2009-06-06 14:37:11 +00:00
Devang Patel
a6b3b19170 Simplify.
llvm-svn: 72970
2009-06-05 23:08:56 +00:00
Dan Gohman
ee407d25ca Remove some unnecessary #includes.
llvm-svn: 72948
2009-06-05 16:32:58 +00:00
Dan Gohman
5003d0ee42 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.

llvm-svn: 72424
2009-05-26 17:44:05 +00:00
Dan Gohman
621071c6c4 Various comment fixes.
llvm-svn: 72376
2009-05-24 23:45:28 +00:00
Dan Gohman
19be1fa810 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.

llvm-svn: 72375
2009-05-24 23:25:42 +00:00
Dan Gohman
18580e593a Teach SCEV::isLoopInvariant and SCEV::hasComputableLoopEvolution
about the convention from LoopInfo that a null Loop* means the entire
function body.

llvm-svn: 72152
2009-05-20 01:01:24 +00:00
Dan Gohman
be817680b8 Make SCEVCallbackVH a private nested class inside ScalarEvolution, as
it's an implementation detail.

llvm-svn: 72122
2009-05-19 19:22:47 +00:00
Dan Gohman
922033d119 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.

llvm-svn: 72093
2009-05-19 02:15:55 +00:00
Daniel Dunbar
7c5aee4f79 Silence Release-Asserts warnings.
llvm-svn: 72011
2009-05-18 16:43:04 +00:00
Dan Gohman
592d65ba06 Teach ScalarEvolution to recognize x^-1 in the case where non-demanded
bits have been stripped out by instcombine.

llvm-svn: 72010
2009-05-18 16:29:04 +00:00
Dan Gohman
09726e69b9 Delete a redundant 'else'.
llvm-svn: 72009
2009-05-18 16:17:44 +00:00
Dan Gohman
e50a960c5a 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.

llvm-svn: 72008
2009-05-18 16:03:58 +00:00
Dan Gohman
153b5acb45 Minor code cleanups. Do more of the work before the if statements
instead of within their controlling expressions.

llvm-svn: 72007
2009-05-18 15:58:39 +00:00
Dan Gohman
b24fd61296 Add assertion checks to the SCEV operator creation methods to catch
type mismatches.

llvm-svn: 72006
2009-05-18 15:44:58 +00:00
Dan Gohman
2c9bd7e0cb Make ScalarEvolution::isLoopGuardedByCond work even when the edge
entering a loop is a non-split critical edge.

llvm-svn: 72004
2009-05-18 15:36:09 +00:00