Chris Lattner
445d8c6b50
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
952d1f9f40
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
08f18b1b74
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
3d27f71f2d
InstSimplify: Strip pointer casts early.
...
llvm-svn: 150694
2012-02-16 15:03:04 +00:00
Benjamin Kramer
ea51f62e4b
InstSimplify: Ignore pointer casts when constant folding compares between pointers.
...
llvm-svn: 150690
2012-02-16 13:49:39 +00:00
Duncan Sands
26641d7c02
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
a2886c21d9
Convert assert(0) to llvm_unreachable
...
llvm-svn: 149967
2012-02-07 05:05:23 +00:00
Benjamin Kramer
9442cd01f6
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
3924cb0267
Add support for vectors of pointers.
...
llvm-svn: 145801
2011-12-05 06:29:09 +00:00
Chad Rosier
c24b86ffbe
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
e659b8459e
Make use of "getScalarType()". No functionality change.
...
llvm-svn: 145556
2011-12-01 02:39:36 +00:00
Eli Friedman
0bae8b2cfb
Fix code to match comment. Fixes PR11340, a regression from r143209.
...
llvm-svn: 144121
2011-11-08 21:08:02 +00:00
Dan Gohman
85977e6ab4
Teach instsimplify to simplify calls to undef.
...
llvm-svn: 143719
2011-11-04 18:32:42 +00:00
Duncan Sands
3d5692a475
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
3af3c046a9
Revert r143214; it's breaking a bunch of stuff.
...
llvm-svn: 143265
2011-10-29 00:56:07 +00:00
Duncan Sands
280bc553b3
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
92af0a8a7f
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
7cb61e5a0e
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
ba286d7c73
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
4b79c21ef2
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
fd26a954a8
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
ad3cfe7933
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
55919a9ed7
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
020c1947b7
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
c1c92719a4
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
d1b7849d49
Convert GetElementPtrInst to use ArrayRef.
...
llvm-svn: 135904
2011-07-25 09:48:08 +00:00
Jay Foad
ed8db7d9df
Convert ConstantExpr::getGetElementPtr and
...
ConstantExpr::getInBoundsGetElementPtr to use ArrayRef.
llvm-svn: 135673
2011-07-21 14:31:17 +00:00
Jay Foad
b992a635fb
Convert SimplifyGEPInst to use ArrayRef.
...
llvm-svn: 135482
2011-07-19 15:07:52 +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
Dan Gohman
54664ed714
Improve constant folding of undef for cmp and select operators.
...
llvm-svn: 134223
2011-07-01 01:03:43 +00:00
Duncan Sands
af32728a57
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
8a20e66926
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
a228785526
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
0a9c1246d7
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
f91c5ab341
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
a3e3699c88
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
7c14a558fe
Don't include Operator.h from InstrTypes.h.
...
llvm-svn: 129271
2011-04-11 09:35:34 +00:00
Nick Lewycky
774647d974
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
980104d1d6
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
9719a719c7
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
41c529bd09
Revert broken srem logic from r126991.
...
llvm-svn: 127021
2011-03-04 19:26:08 +00:00
Nick Lewycky
8e3a79da9f
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
3cec6f5563
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
c9d20067cd
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
Benjamin Kramer
5b7a4e0195
Move "A | ~(A & ?) -> -1" from InstCombine to InstructionSimplify.
...
llvm-svn: 126082
2011-02-20 15:20:01 +00:00
Duncan Sands
b86070933f
Remove pointless blank line.
...
llvm-svn: 125463
2011-02-13 18:11:05 +00:00
Duncan Sands
d114ab331c
Teach instsimplify that X+Y>=X+Z is the same as Y>=Z if neither side overflows,
...
plus some variations of this. According to my auto-simplifier this occurs a lot
but usually in combination with max/min idioms. Because max/min aren't handled
yet this unfortunately doesn't have much effect in the testsuite.
llvm-svn: 125462
2011-02-13 17:15:40 +00:00
Duncan Sands
8b4e283bfb
Formatting and comment tweaks.
...
llvm-svn: 125200
2011-02-09 17:45:03 +00:00
Chris Lattner
9e4aa0259f
Teach instsimplify some tricks about exact/nuw/nsw shifts.
...
improve interfaces to instsimplify to take this info.
llvm-svn: 125196
2011-02-09 17:15:04 +00:00