Commit Graph

274 Commits

Author SHA1 Message Date
Duncan Sands
50ca4d37f7 Improve threading of comparisons over select instructions (spotted by my
auto-simplifier).  This has a big impact on Ada code, but not much else.
Unfortunately the impact is mostly negative!  This is due to PR9004 (aka
SCCP failing to resolve conditional branch conditions in the destination
blocks of the branch), in which simple correlated expressions are not
resolved but complicated ones are, so simplifying has a bad effect!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124788 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-03 09:37:39 +00:00
Duncan Sands
4b720718fb Reenable the transform "(X*Y)/Y->X" when the multiplication is known not to
overflow (nsw flag), which was disabled because it breaks 254.gap.  I have
informed the GAP authors of the mistake in their code, and arranged for the
testsuite to use -fwrapv when compiling this benchmark.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124746 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-02 20:52:00 +00:00
Duncan Sands
f9e4a986c0 Add a m_Undef pattern for convenience. This is so that code that uses
pattern matching can also pattern match undef, creating a more uniform
style.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124657 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-01 09:06:20 +00:00
Duncan Sands
7681c6da60 Have m_One also match constant vectors for which every element is 1.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124655 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-01 08:39:12 +00:00
Duncan Sands
7af00c0f6e Commit 124487 broke 254.gap. See if disabling the part that might be triggered
by PR9088 fixes things.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124561 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-30 18:24:20 +00:00
Duncan Sands
1895e98ef3 Transform (X/Y)*Y into X if the division is exact. Instcombine already knows how
to do this and more, but would only do it if X/Y had only one use.  Spotted as the
most common missed simplification in SPEC by my auto-simplifier, now that it knows
about nuw/nsw/exact flags.  This removes a bunch of multiplications from 447.dealII
and 483.xalancbmk.  It also removes a lot from tramp3d-v4, which results in much
more inlining.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124560 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-30 18:03:50 +00:00
Nick Lewycky
5413880654 Fix comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124544 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-29 19:55:23 +00:00
Frits van Bommel
1fca2c32cc Move InstCombine's knowledge of fdiv to SimplifyInstruction().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124534 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-29 15:26:31 +00:00
Duncan Sands
79f4eea7a3 This dyn_cast should be a cast. Pointed out by Frits van Bommel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124497 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-28 18:53:08 +00:00
Duncan Sands
a3e292c7e8 Thread divisions over selects and phis. This doesn't fire much and has basically
zero effect on the testsuite (it improves two Ada testcases).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124496 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-28 18:50:50 +00:00
Duncan Sands
593faa53fa My auto-simplifier noticed that ((X/Y)*Y)/Y occurs several times in SPEC
benchmarks, and that it can be simplified to X/Y.  (In general you can only
simplify (Z*Y)/Y to Z if the multiplication did not overflow; if Z has the
form "X/Y" then this is the case).  This patch implements that transform and
moves some Div logic out of instcombine and into InstructionSimplify.
Unfortunately instcombine gets in the way somewhat, since it likes to change
(X/Y)*Y into X-(X rem Y), so I had to teach instcombine about this too.
Finally, thanks to the NSW/NUW flags, sometimes we know directly that "Z*Y"
does not overflow, because the flag says so, so I added that logic too.  This
eliminates a bunch of divisions and subtractions in 447.dealII, and has good
effects on some other benchmarks too.  It seems to have quite an effect on
tramp3d-v4 but it's hard to say if it's good or bad because inlining decisions
changed, resulting in massive changes all over.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124487 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-28 16:51:11 +00:00
Duncan Sands
d70d1a5c44 According to my auto-simplifier the most common missed simplifications in
optimized code are:
  (non-negative number)+(power-of-two) != 0 -> true
and
  (x | 1) != 0 -> true
Instcombine knows about the second one of course, but only does it if X|1
has only one use.  These fire thousands of times in the testsuite.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124183 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-25 09:38:29 +00:00
Duncan Sands
9d32f60a6f At -O123 the early-cse pass is run before instcombine has run. According to my
auto-simplier the transform most missed by early-cse is (zext X) != 0 -> X != 0.
This patch adds this transform and some related logic to InstructionSimplify
and removes some of the logic from instcombine (unfortunately not all because
there are several situations in which instcombine can improve things by making
new instructions, whereas instsimplify is not allowed to do this).  At -O2 this
often results in more than 15% more simplifications by early-cse, and results in
hundreds of lines of bitcode being eliminated from the testsuite.  I did see some
small negative effects in the testsuite, for example a few additional instructions
in three programs.  One program, 483.xalancbmk, got an additional 35 instructions,
which seems to be due to a function getting an additional instruction and then
being inlined all over the place.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123911 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-20 13:21:55 +00:00
Duncan Sands
b2f3c383ec For completeness, generalize the (X + Y) - Y -> X transform and add X - (X + 1) -> -1.
These were not recommended by my auto-simplifier since they don't fire often enough.
However they do fire from time to time, for example they remove one subtraction from
the final bitcode for 483.xalancbmk.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123755 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-18 11:50:19 +00:00
Duncan Sands
fe02c69f84 Simplify (X<<1)-X into X. According to my auto-simplier this is the most common missed
simplification in fully optimized code.  It occurs sporadically in the testsuite, and
many times in 403.gcc: the final bitcode has 131 fewer subtractions after this change.
The reason that the multiplies are not eliminated is the same reason that instcombine
did not catch this: they are used by other instructions (instcombine catches this with
a more general transform which in general is only profitable if the operands have only
one use).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123754 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-18 09:24:58 +00:00
Duncan Sands
c087e20331 Turn X-(X-Y) into Y. According to my auto-simplifier this is the most common
simplification present in fully optimized code (I think instcombine fails to
transform some of these when "X-Y" has more than one use).  Fires here and
there all over the test-suite, for example it eliminates 8 subtractions in
the final IR for 445.gobmk, 2 subs in 447.dealII, 2 in paq8p etc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123442 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 15:26:10 +00:00
Duncan Sands
cf80bc1d4a Factorize common code out of the InstructionSimplify shift logic. Add in
threading of shifts over selects and phis while there.  This fires here and
there in the testsuite, to not much effect.  For example when compiling spirit
it fires 5 times, during early-cse, resulting in 6 more cse simplifications,
and 3 more terminators being folded by jump threading, but the final bitcode
doesn't change in any interesting way: other optimizations would have caught
the opportunity anyway, only later.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123441 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 14:44:12 +00:00
Duncan Sands
c43cee3fbb Move some shift transforms out of instcombine and into InstructionSimplify.
While there, I noticed that the transform "undef >>a X -> undef" was wrong.
For example if X is 2 then the top two bits must be equal, so the result can
not be anything.  I fixed this in the constant folder as well.  Also, I made
the transform for "X << undef" stronger: it now folds to undef always, even
though X might be zero.  This is in accordance with the LangRef, but I must
admit that it is fairly aggressive.  Also, I added "i32 X << 32 -> undef"
following the LangRef and the constant folder, likewise fairly aggressive.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123417 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 00:37:45 +00:00
Duncan Sands
53ad861193 Remove some wrong code which fortunately was never executed (as explained in
the comment I added): an extern weak global may have a null address.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123373 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-13 10:43:08 +00:00
Duncan Sands
6dc91253ab The most common simplification missed by instsimplify in unoptimized bitcode
is "X != 0 -> X" when X is a boolean.  This occurs a lot because of the way
llvm-gcc converts gcc's conditional expressions.  Add this, and a few other
similar transforms for completeness.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123372 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-13 08:56:29 +00:00
Duncan Sands
124708d9b4 Revert commit 122654 at the request of Chris, who reckons that instsimplify
is the wrong hammer for this nail, and is probably right.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122661 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-01 20:08:02 +00:00
Duncan Sands
7cf85e74e3 Fix a README item by having InstructionSimplify do a mild form of value
numbering, in which it considers (for example) "%a = add i32 %x, %y" and
"%b = add i32 %x, %y" to be equal because the operands are equal and the
result of the instructions only depends on the values of the operands.
This has almost no effect (it removes 4 instructions from gcc-as-one-file),
and perhaps slows down compilation: I measured a 0.4% slowdown on the large
gcc-as-one-file testcase, but it wasn't statistically significant.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122654 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-01 16:12:09 +00:00
Benjamin Kramer
e21083aa3a Cast away "comparison between signed and unsigned integer" warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122598 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-28 13:52:52 +00:00
Duncan Sands
1cd05bb605 When determining whether the new instruction was already present in
the original instruction, half the cases were missed (making it not
wrong but suboptimal).  Also correct a typo (A <-> B) in the second
chunk. 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122414 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-22 17:15:25 +00:00
Duncan Sands
a3c44a5280 Add some statistics, good for understanding how much more powerful
instcombine is compared to instsimplify.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122397 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-22 09:40:51 +00:00
Duncan Sands
07f30fbd73 While I don't think any later transforms can fire, it seems cleaner to
not assume this (for example in case more transforms get added below
it).  Suggested by Frits van Bommel.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122332 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 15:03:43 +00:00
Duncan Sands
75d289ed62 Fix inverted condition noticed by Frits van Bommel.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122331 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 14:48:48 +00:00
Duncan Sands
82fdab3358 Pull a few more simplifications out of instcombine (there are still
plenty left though!), in particular for multiplication.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122330 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 14:00:22 +00:00
Duncan Sands
3421d90853 Teach InstructionSimplify about distributive laws. These transforms fire
quite often, but don't make much difference in practice presumably because
instcombine also knows them and more.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122328 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 13:32:22 +00:00
Duncan Sands
0312a93693 Move checking of the recursion limit into the various Thread methods.
No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122327 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 09:09:15 +00:00
Duncan Sands
566edb04b8 Add generic simplification of associative operations, generalizing
a couple of existing transforms.  This fires surprisingly often, for
example when compiling gcc "(X+(-1))+1->X" fires quite a lot as well
as various "and" simplifications (usually with a phi node operand).
Most of the time this doesn't make a real difference since the same
thing would have been done elsewhere anyway, eg: by instcombine, but
there are a few places where this results in simplifications that we
were not doing before.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122326 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-21 08:49:00 +00:00
Duncan Sands
ee9a2e322a Have SimplifyBinOp dispatch Xor, Add and Sub to the corresponding methods
(they had just been forgotten before).  Adding Xor causes "main" in the
existing testcase 2010-11-01-lshr-mask.ll to be hugely more simplified.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122245 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-20 14:47:04 +00:00
Duncan Sands
fea3b218d6 Move Sub simplifications and additional Add simplifications out of
instcombine and into InstructionSimplify.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121861 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-15 14:07:39 +00:00
Duncan Sands
f8b1a5ea96 If we detect that the instruction we are simplifying is unreachable, arrange for
it to be replaced by undef rather than not replaced at all, the idea being that
this may reduce the amount of work done by whoever called InstructionSimplify.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121860 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-15 11:02:22 +00:00
Chandler Carruth
e89ada98a6 Add some dead stores to pacify my least favorite GCC warning: may be
uninitialized. The warning is terrible, has incorrect source locations, and has
a huge false positive rate such as *all* of these.

If anyone has a better solution, please let me know. Alternatively, I'll
happily add -Wno-uninitialized to the -Werror build mode. Maybe I can even do
it *only* when building with GCC instead of Clang.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120281 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-29 01:41:13 +00:00
Duncan Sands
4cd2ad15b4 Expand a little on the description of what InstructionSimplify does.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120016 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 10:50:08 +00:00
Duncan Sands
a63395a30f If a GEP index simply advances by multiples of a type of zero size,
then replace the index with zero.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119974 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 16:32:50 +00:00
Duncan Sands
85bbff6c94 Move the "gep undef" -> "undef" transform from instcombine to
InstructionSimplify.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119970 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 13:42:49 +00:00
Duncan Sands
e60d79faf7 Add a rather pointless InstructionSimplify transform, inspired by recent constant
folding improvements: if P points to a type of size zero, turn "gep P, N" into "P".
More generally, if a gep index type has size zero, instcombine could replace the
index with zero, but that is not done here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119942 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 13:53:09 +00:00
Duncan Sands
87689cfc54 Remove threading of Xor over selects and phis, with an explanation
of why such threading is pointless.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119798 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-19 09:20:39 +00:00
Duncan Sands
2b749870d0 Move some those Xor simplifications which don't require creating new
instructions out of InstCombine and into InstructionSimplify.  While
there, introduce an m_AllOnes pattern to simplify matching with integers
and vectors with all bits equal to one.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119536 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-17 18:52:15 +00:00
Duncan Sands
d261dc650a Previously SimplifyInstruction could report that an instruction
simplified to itself (this can only happen in unreachable blocks).
Change it to return null instead.  Hopefully this will fix some
buildbot failures.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119490 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-17 08:35:29 +00:00
Duncan Sands
ff10341183 Fix a layering violation: hasConstantValue, which is part of the PHINode
class, uses DominatorTree which is an analysis.  This change moves all of
the tricky hasConstantValue logic to SimplifyInstruction, and replaces it
with a very simple literal implementation.  I already taught users of
hasConstantValue that need tricky stuff to use SimplifyInstruction instead.
I didn't update InlineFunction because the IR looks like it might be in a
funky state at the point it calls hasConstantValue, which makes calling
SimplifyInstruction dangerous since it can in theory do a lot of tricky
reasoning.  This may be a pessimization, for example in the case where
all phi node operands are either undef or a fixed constant.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119459 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-17 04:30:22 +00:00
Duncan Sands
1845009290 In which I discover the existence of loops. Threading an operation
over a phi node by applying it to each operand may be wrong if the
operation and the phi node are mutually interdependent (the testcase
has a simple example of this).  So only do this transform if it would
be correct to perform the operation in each predecessor of the block
containing the phi, i.e. if the other operands all dominate the phi.
This should fix the FFMPEG snow.c regression reported by İsmail Dönmez.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119347 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-16 12:16:38 +00:00
Duncan Sands
5520089465 Teach InstructionSimplify the trick of skipping incoming phi
values that are equal to the phi itself.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119161 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-15 17:52:45 +00:00
Duncan Sands
eff0581583 If dom tree information is available, make it possible to pass
it to get better phi node simplification.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119055 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-14 18:36:10 +00:00
Duncan Sands
cd6636c737 Teach InstructionSimplify about phi nodes. I chose to have it simply
offload the work to hasConstantValue rather than do something more
complicated (such handling mutually recursive phis) because (1) it is
not clear it is worth it; and (2) if it is worth it, maybe such logic
would be better placed in hasConstantValue.  Adjust some GVN tests
which are now cleaned up much further (eg: all phi nodes are removed).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119043 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-14 13:30:18 +00:00
Duncan Sands
12a86f5b31 Strip trailing whitespace.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119038 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-14 11:23:23 +00:00
Duncan Sands
bc68d71d2a Reduce the maximum recursion depth, 5 seems pointlessly too much.
Probably it should just be 1, but compromise with 3.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118718 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-10 20:53:24 +00:00
Duncan Sands
a74a58c83b Teach InstructionSimplify how to look through PHI nodes. Since PHI
nodes can be used in loops, this could result in infinite looping
if there is no recursion limit, so add such a limit.  It is also
used for the SelectInst case because in theory there could be an
infinite loop there too if the basic block is unreachable.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118694 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-10 18:23:01 +00:00
Duncan Sands
b2cbdc35ba Simplify binary operations where one operand is a select instruction.
The simplifications performed here never create new instructions, they
only return existing instructions (or a constant), and so are always a
win.  In theory they should transform (for example)
  %z = and i32 %x, %y
  %s = select i1 %cond, i32 %y, i32 %z
  %r = and i32 %x, %s
into
  %r = and i32 %x, y
but in practice they get into a fight with instcombine, and lose.
Unfortunately instcombine does a poor job in this case.  Nonetheless
I'm committing this transform to make it easier to discuss what to
do to make peace with instcombine.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118679 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-10 13:00:08 +00:00
Duncan Sands
3bbb0cc42b Factorize code, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118516 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-09 17:25:51 +00:00
Duncan Sands
92826def59 Add simplification of floating point comparisons with the result
of a select instruction, the same as already exists for integer
comparisons.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118379 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-07 16:46:25 +00:00
Duncan Sands
1ac7c9979a Fix a README item: when doing a comparison with the result
of a select instruction, see if doing the compare with the
true and false values of the select gives the same result.
If so, that can be used as the value of the comparison.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118378 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-07 16:12:23 +00:00
Owen Anderson
4e282decf3 Revert r114097, adding back in the assertion against replacing an Instruction by itself. Now that CorrelatedValuePropagation is
more careful not to call SimplifyInstructionsInBlock() on an unreachable block, the issue has been fixed at a higher level.  Add
a big warning to SimplifyInstructionsInBlock() to hopefully prevent this in the future.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114117 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-16 20:51:41 +00:00
Owen Anderson
4b91c3ac96 Fix PR8161, in which an unreachable loop causes recursive instruction simplification to try
to replace an instruction with itself.  Add a predicate to the simplifier to prevent this case.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114097 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-16 17:42:36 +00:00
Benjamin Kramer
6844c8ea5a Teach InstructionSimplify to fold (A & B) & A -> A & B and (A | B) | A -> A | B.
Reassociate does this but it doesn't catch all cases (e.g. if the operands are i1).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113651 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-10 22:39:55 +00:00
Chris Lattner
d2bfe54b0a Fix PR7647, handling the case when 'To' ends up being
mutated by recursive simplification.  This also enhances
ReplaceAndSimplifyAllUses to actually do a real RAUW
at the end of it, which updates any value handles
pointing to "From" to start pointing to "To".  This
seems useful for debug info and random other VH users.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108415 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-15 06:36:08 +00:00
Eli Friedman
e2f93131fb Revert r108401; it breaks bootstrap :(
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108407 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-15 05:09:31 +00:00
Eli Friedman
3ed60a2a22 Add AssertingVH which makes PR7647 break consistently.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108401 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-15 04:46:14 +00:00
Chris Lattner
047542669a move some select simplifications out out instcombine into
inst simplify.  No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101873 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-20 05:32:14 +00:00
Chris Lattner
c8e14b3d37 fix incorrect folding of icmp with undef, PR6481.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97659 91177308-0d34-0410-b5e6-96231b3b80d8
2010-03-03 19:46:03 +00:00
Dan Gohman
6b617a7213 Constant-fold certain comparisons with infinity and negative infinity.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96777 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-22 04:06:03 +00:00
Chris Lattner
8aee8efc0c factor some logic out of instcombine into a new SimplifyAddInst method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90011 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-27 17:42:22 +00:00
Chris Lattner
c514c1f521 factor some instcombine simplifications for getelementptr out to a new
SimplifyGEPInst method in InstructionSimplify.h.  No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89980 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-27 00:29:05 +00:00
Chris Lattner
40d8c28b27 move some generally useful functions out of jump threading
into libanalysis and transformutils.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86735 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-10 22:26:15 +00:00
Chris Lattner
70ce6d0819 I misread the parens, not so redundant after all.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86648 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-10 02:04:54 +00:00
Chris Lattner
9f3ce36d7e remove some redundant parens.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86645 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-10 01:56:04 +00:00
Chris Lattner
e34537856a add a new SimplifyInstruction API, which is like ConstantFoldInstruction,
except that the result may not be a constant.  Switch jump threading to 
use it so that it gets things like (X & 0) -> 0, which occur when phi preds
are deleted and the remaining phi pred was a zero.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86637 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-10 01:08:51 +00:00
Chris Lattner
d06094f068 factor simplification logic for AND and OR out to InstSimplify from instcombine.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86635 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-10 00:55:12 +00:00
Chris Lattner
210c5d4880 pull a bunch of logic out of instcombine into instsimplify for compare
simplification, this handles the foldable fcmp x,x cases among many others.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86627 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-09 23:55:12 +00:00
Chris Lattner
9dbb42944c rename SimplifyCompare -> SimplifyCmpInst and split it into
Simplify[IF]Cmp pieces.  Add some predicates to CmpInst to 
determine whether a predicate is fp or int.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86624 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-09 23:28:39 +00:00
Chris Lattner
8f73deaa87 fix ConstantFoldCompareInstOperands to take the LHS/RHS as
individual operands instead of taking a temporary array


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86619 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-09 23:06:58 +00:00
Chris Lattner
9f3c25aeb3 stub out a new libanalysis "instruction simplify" interface that
takes decimated instructions and applies identities to them.  This
is pretty minimal at this point, but I plan to pull some instcombine
logic out into these and similar routines.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86613 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-09 22:57:59 +00:00