Nick Lewycky
849715d31f
Roll these back to r151448 until I figure out how they're breaking
...
MultiSource/Applications/lua.
llvm-svn: 151463
2012-02-25 23:01:19 +00:00
Nick Lewycky
1636c6eaef
An argument and a local identified object (eg. a noalias call) could turn out
...
equal if both are null. In the test, scope type %t and global @y by adding a
'gep' prefix to them.
llvm-svn: 151452
2012-02-25 20:19:07 +00:00
Nick Lewycky
808d0e3fa7
Fix five-letter typo in comment.
...
llvm-svn: 151450
2012-02-25 19:12:58 +00:00
Nick Lewycky
94be1c7d95
Teach instsimplify to be more aggressive when analyzing comparisons of pointers
...
by using llvm::isIdentifiedObject. Also teach it to handle GEPs that have
the same base pointer and constant operands. Fixes PR11238!
llvm-svn: 151449
2012-02-25 19:07:42 +00:00
Chris Lattner
b01936f21a
fix PR12075, a regression in a recent transform I added. In unreachable code, gep chains can be infinite. Just like "stripPointerCasts", use a set to keep track of visited instructions so we don't recurse infinitely.
...
llvm-svn: 151383
2012-02-24 19:01:58 +00:00
Chris Lattner
50ad7c3f54
fold comparisons of gep'd alloca points with null to false,
...
implementing PR12013. We now compile the testcase to:
__Z4testv: ## @_Z4testv
## BB#0: ## %_ZN4llvm15SmallVectorImplIiE9push_backERKi.exit
pushq %rbx
subq $64, %rsp
leaq 32(%rsp), %rbx
movq %rbx, (%rsp)
leaq 64(%rsp), %rax
movq %rax, 16(%rsp)
movl $1, 32(%rsp)
leaq 36(%rsp), %rax
movq %rax, 8(%rsp)
leaq (%rsp), %rdi
callq __Z1gRN4llvm11SmallVectorIiLj8EEE
movq (%rsp), %rdi
cmpq %rbx, %rdi
je LBB0_2
## BB#1:
callq _free
LBB0_2: ## %_ZN4llvm11SmallVectorIiLj8EED1Ev.exit
addq $64, %rsp
popq %rbx
ret
instead of:
__Z4testv: ## @_Z4testv
## BB#0:
pushq %rbx
subq $64, %rsp
xorl %eax, %eax
leaq (%rsp), %rbx
addq $32, %rbx
movq %rbx, (%rsp)
movq %rbx, 8(%rsp)
leaq 64(%rsp), %rcx
movq %rcx, 16(%rsp)
je LBB0_2
## BB#1:
movl $1, 32(%rsp)
movq %rbx, %rax
LBB0_2: ## %_ZN4llvm15SmallVectorImplIiE9push_backERKi.exit
addq $4, %rax
movq %rax, 8(%rsp)
leaq (%rsp), %rdi
callq __Z1gRN4llvm11SmallVectorIiLj8EEE
movq (%rsp), %rdi
cmpq %rbx, %rdi
je LBB0_4
## BB#3:
callq _free
LBB0_4: ## %_ZN4llvm11SmallVectorIiLj8EED1Ev.exit
addq $64, %rsp
popq %rbx
ret
This doesn't shrink clang noticably though.
llvm-svn: 150944
2012-02-20 00:42:49 +00:00
Eli Friedman
be89455c98
Fix a rather nasty regression from r150690: LHS != RHS does not imply LHS->stripPointerCasts() != RHS->stripPointerCasts().
...
llvm-svn: 150863
2012-02-18 03:29:25 +00:00
Benjamin Kramer
3bef0c77d1
Revert "InstSimplify: Strip pointer casts early."
...
Turns out this isn't safe, because the code below depends on LHS and RHS having
the same type.
llvm-svn: 150695
2012-02-16 15:19:59 +00:00
Benjamin Kramer
0911ace9f3
InstSimplify: Strip pointer casts early.
...
llvm-svn: 150694
2012-02-16 15:03:04 +00:00
Benjamin Kramer
8c809e592f
InstSimplify: Ignore pointer casts when constant folding compares between pointers.
...
llvm-svn: 150690
2012-02-16 13:49:39 +00:00
Duncan Sands
931ce8ee15
Fix PR11948: the result type of an icmp may be a vector of boolean -
...
don't assume it is a boolean.
llvm-svn: 150247
2012-02-10 14:31:24 +00:00
Craig Topper
639b152ca5
Convert assert(0) to llvm_unreachable
...
llvm-svn: 149967
2012-02-07 05:05:23 +00:00
Benjamin Kramer
fba4e88bc2
PatternMatch: Introduce a matcher for instructions with the "exact" bit. Use it to simplify a few matchers.
...
llvm-svn: 147403
2012-01-01 17:55:30 +00:00
Nadav Rotem
1a91e4381d
Add support for vectors of pointers.
...
llvm-svn: 145801
2011-12-05 06:29:09 +00:00
Chad Rosier
49a66381f7
Propagate TargetLibraryInfo throughout ConstantFolding.cpp and
...
InstructionSimplify.cpp. Other fixups as needed.
Part of rdar://10500969
llvm-svn: 145559
2011-12-01 03:08:23 +00:00
Nick Lewycky
4047e7c476
Make use of "getScalarType()". No functionality change.
...
llvm-svn: 145556
2011-12-01 02:39:36 +00:00
Eli Friedman
6bda990650
Fix code to match comment. Fixes PR11340, a regression from r143209.
...
llvm-svn: 144121
2011-11-08 21:08:02 +00:00
Dan Gohman
19a8523a2f
Teach instsimplify to simplify calls to undef.
...
llvm-svn: 143719
2011-11-04 18:32:42 +00:00
Duncan Sands
1077c1fa88
Reapply commit 143214 with a fix: m_ICmp doesn't match conditions
...
with the given predicate, it matches any condition and returns the
predicate - d'oh! Original commit message:
The expression icmp eq (select (icmp eq x, 0), 1, x), 0 folds to false.
Spotted by my super-optimizer in 186.crafty and 450.soplex. We really
need a proper infrastructure for handling generalizations of this kind
of thing (which occur a lot), however this case is so simple that I decided
to go ahead and implement it directly.
llvm-svn: 143318
2011-10-30 19:56:36 +00:00
Eli Friedman
7c9bef9ba8
Revert r143214; it's breaking a bunch of stuff.
...
llvm-svn: 143265
2011-10-29 00:56:07 +00:00
Duncan Sands
7791a854c3
The expression icmp eq (select (icmp eq x, 0), 1, x), 0 folds to false.
...
Spotted by my super-optimizer in 186.crafty and 450.soplex. We really
need a proper infrastructure for handling generalizations of this kind
of thing (which occur a lot), however this case is so simple that I decided
to go ahead and implement it directly.
llvm-svn: 143214
2011-10-28 19:01:20 +00:00
Duncan Sands
5730fe6a31
Fold icmp ugt (udiv X, Y), X to false. Spotted by my super-optimizer
...
in 186.crafty.
llvm-svn: 143209
2011-10-28 18:17:44 +00:00
Duncan Sands
ca325638c8
Reapply commit 143028 with a fix: the problem was casting a ConstantExpr Mul
...
using BinaryOperator (which only works for instructions) when it should have
been a cast to OverflowingBinaryOperator (which also works for constants).
While there, correct a few other dubious looking uses of BinaryOperator.
Thanks to Chad Rosier for the testcase. Original commit message:
My super-optimizer noticed that we weren't folding this expression to
true: (x *nsw x) sgt 0, where x = (y | 1). This occurs in 464.h264ref.
llvm-svn: 143125
2011-10-27 19:16:21 +00:00
Duncan Sands
5c8fa99c32
The maximum power of 2 dividing a power of 2 is itself. This occurs
...
in 403.gcc and was spotted by my super-optimizer.
llvm-svn: 143054
2011-10-26 20:55:21 +00:00
Benjamin Kramer
ec933b857e
InstSimplify: Don't try to replace an extractvalue/insertvalue pair with the original value if types don't match.
...
Fixes clang selfhost.
llvm-svn: 139120
2011-09-05 18:16:19 +00:00
Duncan Sands
a74d10bb60
Add some simple insertvalue simplifications, for the purpose of cleaning
...
up do-nothing exception handling code produced by dragonegg.
llvm-svn: 139113
2011-09-05 06:52:48 +00:00
Eli Friedman
6da9a85aaa
Revert r137781; I agree with Duncan's comment that the situation in question is clearly impossible given the current structure of the code.
...
llvm-svn: 137853
2011-08-17 19:31:49 +00:00
Eli Friedman
fc821baad4
Extend the undef ^ undef idiom once more. No testcase: I can't figure out how to actually trigger the codepath in question at the moment, but it might get exposed in the future.
...
llvm-svn: 137781
2011-08-16 22:38:34 +00:00
Duncan Sands
be4435d95e
Fix what seems an obvious typo. Patch by Ivan Krasin. Problem
...
reported at http://habrahabr.ru/blogs/compilers/125626/ .
llvm-svn: 136865
2011-08-04 10:02:21 +00:00
Duncan Sands
52f6e018e2
Add helper function for getting true/false constants in a uniform
...
way for i1 and vector of i1 types. Use these to make some code
more self-documenting.
llvm-svn: 136079
2011-07-26 15:03:53 +00:00
Jay Foad
6513dac6e2
Convert GetElementPtrInst to use ArrayRef.
...
llvm-svn: 135904
2011-07-25 09:48:08 +00:00
Jay Foad
d4458dd707
Convert ConstantExpr::getGetElementPtr and
...
ConstantExpr::getInBoundsGetElementPtr to use ArrayRef.
llvm-svn: 135673
2011-07-21 14:31:17 +00:00
Jay Foad
bbbf29aab7
Convert SimplifyGEPInst to use ArrayRef.
...
llvm-svn: 135482
2011-07-19 15:07:52 +00:00
Jay Foad
ae5894c5cc
Use ArrayRef in ConstantFoldInstOperands and ConstantFoldCall.
...
llvm-svn: 135477
2011-07-19 13:32:40 +00:00
Chris Lattner
e1fe7061ce
land David Blaikie's patch to de-constify Type, with a few tweaks.
...
llvm-svn: 135375
2011-07-18 04:54:35 +00:00
Dan Gohman
ba1afd789e
Improve constant folding of undef for cmp and select operators.
...
llvm-svn: 134223
2011-07-01 01:03:43 +00:00
Duncan Sands
77695f14dc
The comparision "max(x,y)==x" is equivalent to "x>=y". Since the max is
...
often expressed as "x >= y ? x : y", there is a good chance we can extract
the existing "x >= y" from it and use that as a replacement for "max(x,y)==x".
llvm-svn: 131049
2011-05-07 16:56:49 +00:00
Eli Friedman
c562cbdb82
PR9838: Fix transform introduced in r127064 to not trigger when only one side of the icmp is an exact shift.
...
llvm-svn: 130954
2011-05-05 21:59:18 +00:00
Duncan Sands
586612a764
Add variations on: max(x,y) >= min(x,z) folds to true. This isn't that common,
...
but according to my super-optimizer there are only two missed simplifications
of -instsimplify kind when compiling bzip2, and this is one of them. It amuses
me to have bzip2 be perfectly optimized as far as instsimplify goes!
llvm-svn: 130840
2011-05-04 16:05:05 +00:00
Duncan Sands
7497273b12
Implement some basic simplifications involving min/max, for example
...
max(a,b) >= a -> true. According to my super-optimizer, these are
by far the most common simplifications (of the -instsimplify kind)
that occur in the testsuite and aren't caught by -std-compile-opts.
llvm-svn: 130780
2011-05-03 19:53:10 +00:00
Duncan Sands
8c729e71c2
Fix PR9579: when simplifying a compare to "true" or "false", and it was
...
a vector compare, generate a vector result rather than i1 (and crashing).
llvm-svn: 130706
2011-05-02 18:51:41 +00:00
Duncan Sands
750a066af1
Move some rem transforms out of instcombine and into instsimplify.
...
This automagically provides a transform noticed by my super-optimizer
as occurring quite often: "rem x, (select cond, x, 1)" -> 0.
llvm-svn: 130694
2011-05-02 16:27:02 +00:00
Jay Foad
0d5ca4cf44
Don't include Operator.h from InstrTypes.h.
...
llvm-svn: 129271
2011-04-11 09:35:34 +00:00
Nick Lewycky
c2b564b36f
Fix two cases I forgot to update when doing a mental "getSwappedPredicate".
...
Thanks Duncan Sands!
llvm-svn: 127323
2011-03-09 08:20:06 +00:00
Nick Lewycky
485af203fc
Add another micro-optimization. Apologies for the lack of refactoring, but I
...
gave up when I realized I couldn't come up with a good name for what the
refactored function would be, to describe what it does.
This is PR9343 test12, which is test3 with arguments reordered. Whoops!
llvm-svn: 127318
2011-03-09 06:26:03 +00:00
Nick Lewycky
a2cb87f86d
Thread comparisons over udiv/sdiv/ashr/lshr exact and lshr nuw/nsw whenever
...
possible. This goes into instcombine and instsimplify because instsimplify
doesn't need to check hasOneUse since it returns (almost exclusively) constants.
This fixes PR9343 #4 #5 and #8 !
llvm-svn: 127064
2011-03-05 05:19:11 +00:00
Nick Lewycky
75a3dd996d
Revert broken srem logic from r126991.
...
llvm-svn: 127021
2011-03-04 19:26:08 +00:00
Nick Lewycky
3bc3a84ba8
Fold "icmp pred (srem X, Y), Y" like we do for urem. Handle signed comparisons
...
in the urem case, though not the other way around. This is enough to get #3 from
PR9343!
llvm-svn: 126991
2011-03-04 10:06:52 +00:00
Nick Lewycky
a5f309e983
Teach instruction simplify to use constant ranges to solve problems of the form
...
"icmp pred %X, CI" and a number of examples where "%X = binop %Y, CI2".
Some of these cases (div and rem) used to make it through opt -O2, but the
others are probably now making code elsewhere redundant (probably instcombine).
llvm-svn: 126988
2011-03-04 07:00:57 +00:00
Nick Lewycky
e9d448e997
Optimize "icmp pred (urem X, Y), Y" --> true/false depending on pred. There's
...
more work to do here, "icmp ult (urem X, 10), 11" doesn't optimize away yet.
Fixes example 3 from PR9343!
llvm-svn: 126741
2011-03-01 08:15:50 +00:00