Frits van Bommel
978376c200
Add test cases for Jay's r129641 and fix a 32-bit-centric testcase in a file with a 64-bit datalayout.
...
llvm-svn: 129643
2011-04-16 14:31:50 +00:00
Chris Lattner
0304b82f80
Fix a ton of comment typos found by codespell. Patch by
...
Luis Felipe Strano Moraes!
llvm-svn: 129558
2011-04-15 05:18:47 +00:00
Eli Friedman
198c39a4fe
Add an instcombine for constructs like a | -(b != c); a select is more
...
canonical, and generally leads to better code. Found while looking at
an article about saturating arithmetic.
llvm-svn: 129545
2011-04-14 22:41:27 +00:00
Nadav Rotem
ecc7d9a408
This testcase passed even without the fix. Added the target info to make the
...
test fail (without the fix). Thanks Dan.
llvm-svn: 128999
2011-04-06 11:18:29 +00:00
Nadav Rotem
8bb81fc184
InstCombine optimizes gep(bitcast(x)) even when the bitcasts casts away address
...
space info. We crash with an assert in this case. This change checks that the
address space of the bitcasted pointer is the same as the gep ptr.
llvm-svn: 128884
2011-04-05 14:29:52 +00:00
Benjamin Kramer
7c0178b9ec
InstCombine: Turn icmp + sext into bitwise/integer ops when the input has only one unknown bit.
...
int test1(unsigned x) { return (x&8) ? 0 : -1; }
int test3(unsigned x) { return (x&8) ? -1 : 0; }
before (x86_64):
_test1:
andl $8, %edi
cmpl $1, %edi
sbbl %eax, %eax
ret
_test3:
andl $8, %edi
cmpl $1, %edi
sbbl %eax, %eax
notl %eax
ret
after:
_test1:
shrl $3, %edi
andl $1, %edi
leal -1(%rdi), %eax
ret
_test3:
shll $28, %edi
movl %edi, %eax
sarl $31, %eax
ret
llvm-svn: 128732
2011-04-01 20:09:10 +00:00
Nadav Rotem
897b838d5f
Instcombile optimization: extractelement(cast) -> cast(extractelement)
...
llvm-svn: 128683
2011-03-31 22:57:29 +00:00
Benjamin Kramer
22bdd799ee
InstCombine: APFloat can't perform arithmetic on PPC double doubles, don't even try.
...
Thanks Eli!
llvm-svn: 128676
2011-03-31 21:35:49 +00:00
Benjamin Kramer
40e705fb80
InstCombine: Fix transform to use the swapped predicate.
...
Thanks Frits!
llvm-svn: 128628
2011-03-31 10:46:03 +00:00
Benjamin Kramer
40a71a4a85
InstCombine: fold fcmp (fneg x), (fneg y) -> fcmp x, y
...
llvm-svn: 128627
2011-03-31 10:12:22 +00:00
Benjamin Kramer
e16910dd92
InstCombine: fold fcmp pred (fneg x), C -> fcmp swap(pred) x, -C
...
llvm-svn: 128626
2011-03-31 10:12:15 +00:00
Benjamin Kramer
fd3a92ea15
InstCombine: Shrink "fcmp (fpext x), C" to "fcmp x, C" if C can be losslessly converted to the type of x.
...
Fixes PR9592.
llvm-svn: 128625
2011-03-31 10:12:07 +00:00
Benjamin Kramer
701d4c897f
InstCombine: fold fcmp (fpext x), (fpext y) -> fcmp x, y.
...
llvm-svn: 128624
2011-03-31 10:11:58 +00:00
Benjamin Kramer
e6e5b11a65
Avoid turning a floating point division with a constant power of two into a denormal multiplication.
...
Some platforms may treat denormals as zero, on other platforms multiplication
with a subnormal is slower than dividing by a normal.
llvm-svn: 128555
2011-03-30 17:02:54 +00:00
Benjamin Kramer
310f9bb68e
InstCombine: If the divisor of an fdiv has an exact inverse, turn it into an fmul.
...
Fixes PR9587.
llvm-svn: 128546
2011-03-30 15:42:35 +00:00
Benjamin Kramer
4ae67c9fcb
InstCombine: Add a few missing combines for ANDs and ORs of sign bit tests.
...
On x86 we now compile "if (a < 0 && b < 0)" into
testl %edi, %esi
js IF.THEN
llvm-svn: 128496
2011-03-29 22:06:41 +00:00
Nick Lewycky
fd664969bc
Teach the transformation that moves binary operators around selects to preserve
...
the subclass optional data.
llvm-svn: 128388
2011-03-27 19:51:23 +00:00
Nick Lewycky
27e865c948
Add a small missed optimization: turn X == C ? X : Y into X == C ? C : Y. This
...
removes one use of X which helps it pass the many hasOneUse() checks.
In my analysis, this turns up very often where X = A >>exact B and that can't be
simplified unless X has one use (except by increasing the lifetime of A which is
generally a performance loss).
llvm-svn: 128373
2011-03-27 07:30:57 +00:00
Eli Friedman
6a874d7f22
FileCheck-ize and update test.
...
llvm-svn: 127845
2011-03-18 01:10:31 +00:00
Devang Patel
f8c3eb7368
Try to not lose variable's debug info during instcombine.
...
This is done by lowering dbg.declare intrinsic into dbg.value intrinsic.
Radar 9143931.
llvm-svn: 127834
2011-03-17 22:18:16 +00:00
Eric Christopher
7f724c8079
If we don't know how long a string is we can't fold an _chk version to the
...
normal version.
Fixes rdar://9123638
llvm-svn: 127636
2011-03-15 00:25:41 +00:00
Benjamin Kramer
d4ea449e7e
ComputeMaskedBits: sub falls through to add, and sub doesn't have the same overflow semantics as add.
...
Should fix the selfhost failures that started with r127463.
llvm-svn: 127465
2011-03-11 14:46:49 +00:00
Benjamin Kramer
666407939f
InstCombine: Fix a thinko where transform an icmp under the assumption that it's a zero comparison when it's not.
...
Fixes PR9454.
llvm-svn: 127464
2011-03-11 11:37:40 +00:00
Benjamin Kramer
52a44b9c80
InstCombine: Turn umul_with_overflow into mul nuw if we can prove that it cannot overflow.
...
This happens a lot in clang-compiled C++ code because it adds overflow checks to operator new[]:
unsigned *foo(unsigned n) { return new unsigned[n]; }
We can optimize away the overflow check on 64 bit targets because (uint64_t)n*4 cannot overflow.
llvm-svn: 127418
2011-03-10 18:40:14 +00:00
Benjamin Kramer
8313cf1cf4
Fix mistyped CHECK lines.
...
llvm-svn: 127366
2011-03-09 22:07:31 +00:00
Eli Friedman
50311331a7
PR9346: Prevent SimplifyDemandedBits from incorrectly introducing
...
INT_MIN % -1.
llvm-svn: 127306
2011-03-09 01:28:35 +00:00
Nick Lewycky
fad3512a9a
Tweak this test. We can analyze what happens and show that we still do the
...
right thing, instead of merely being unable to analyze and the transform
doesn't occur.
llvm-svn: 127149
2011-03-07 02:10:18 +00:00
Nick Lewycky
2cbaf887bb
Add more analysis of the sign bit of an srem instruction. If the LHS is negative
...
then the result could go either way. If it's provably positive then so is the
srem. Fixes PR9343 #7 !
llvm-svn: 127146
2011-03-07 01:50:10 +00:00
Nick Lewycky
46bb763f35
ConstantInt has some getters which return ConstantInt's or ConstantVector's of
...
the value splatted into every element. Extend this to getTrue and getFalse which
by providing new overloads that take Types that are either i1 or <N x i1>. Use
it in InstCombine to add vector support to some code, fixing PR8469!
llvm-svn: 127116
2011-03-06 03:36:19 +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
b2557b7cf1
Try once again to optimize "icmp (srem X, Y), Y" by turning the comparison into
...
true/false or "icmp slt/sge Y, 0".
llvm-svn: 127063
2011-03-05 04:28:48 +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
Anders Carlsson
1eb388e6c3
Make InstCombiner::FoldAndOfICmps create a ConstantRange that's the
...
intersection of the LHS and RHS ConstantRanges and return "false" when
the range is empty.
This simplifies some code and catches some extra cases.
llvm-svn: 126744
2011-03-01 15:05:01 +00:00
Nick Lewycky
dcc97b5f44
srem doesn't actually have the same resulting sign as its numerator, you could
...
also have a zero when numerator = denominator. Reverts parts of r126635 and
r126637.
llvm-svn: 126644
2011-02-28 09:17:39 +00:00
Nick Lewycky
28f01da48e
Teach InstCombine to fold "(shr exact X, Y) == 0" --> X == 0, fixing #1 from
...
PR9343.
llvm-svn: 126643
2011-02-28 08:31:40 +00:00
Nick Lewycky
e0f44d0aba
The sign of an srem instruction is the sign of its dividend (the first
...
argument), regardless of the divisor. Teach instcombine about this and fix
test7 in PR9343!
llvm-svn: 126635
2011-02-28 06:20:05 +00:00
Chris Lattner
72a2ebab6c
change instcombine to not turn a call to non-varargs bitcast of
...
function prototype into a call to a varargs prototype. We do
allow the xform if we have a definition, but otherwise we don't
want to risk that we're changing the abi in a subtle way. On
X86-64, for example, varargs require passing stuff in %al.
llvm-svn: 126363
2011-02-24 05:10:56 +00:00
Benjamin Kramer
50cd35c25e
InstCombine: Add a bunch of combines of the form x | (y ^ z).
...
We usually catch this kind of optimization through InstSimplify's distributive
magic, but or doesn't distribute over xor in general.
"A | ~(A | B) -> A | ~B" hits 24 times on gcc.c.
llvm-svn: 126081
2011-02-20 13:23:43 +00:00
Eli Friedman
35ed1e5d6c
PR9218: SimplifyDemandedVectorElts can return a non-null value that is not
...
the instruction passed in. Make sure to account for this correctly, instead
of looping infinitely.
llvm-svn: 126058
2011-02-19 22:42:40 +00:00
Duncan Sands
1ddd628de0
Add some transforms of the kind X-Y>X -> 0>Y which are valid when there is no
...
overflow. These subsume some existing equality transforms, so zap those.
llvm-svn: 125843
2011-02-18 16:25:37 +00:00
Chris Lattner
f9501b79f9
have instcombine preserve nsw/nuw/exact when sinking
...
common operations through a phi.
llvm-svn: 125790
2011-02-17 23:01:49 +00:00
Chris Lattner
fc8ee641a2
fix instcombine merging GEPs through a PHI to only make the
...
result inbounds if all of the inputs are inbounds.
llvm-svn: 125785
2011-02-17 22:21:26 +00:00
Nadav Rotem
ad2fd4eada
Enhance constant folding of bitcast operations on vectors of floats.
...
Add getAllOnesValue of FP numbers to Constants and APFloat.
Add more tests.
llvm-svn: 125776
2011-02-17 21:22:27 +00:00
Duncan Sands
00610dbf64
Transform "A + B >= A + C" into "B >= C" if the adds do not wrap. Likewise for some
...
variations (some of these were already present so I unified the code). Spotted by my
auto-simplifier as occurring a lot.
llvm-svn: 125734
2011-02-17 07:46:37 +00:00
Chris Lattner
6e936c247f
preserve NUW/NSW when transforming add x,x
...
llvm-svn: 125711
2011-02-17 02:23:02 +00:00
Chris Lattner
79947d56ea
filecheckize
...
llvm-svn: 125710
2011-02-17 02:21:03 +00:00
Nick Lewycky
5c854580b2
Teach PatternMatch that splat vectors could be floating point as well as
...
integer. Fixes PR9228!
llvm-svn: 125613
2011-02-15 23:13:23 +00:00
Nadav Rotem
5306a4ae96
Fix 9216 - Endless loop in InstCombine pass.
...
The pattern "A&(A^B) -> A & ~B" recreated itself because ~B is
actually a xor -1.
llvm-svn: 125557
2011-02-15 07:13:48 +00:00
Nadav Rotem
98c5af8517
Fix test
...
llvm-svn: 125460
2011-02-13 16:13:16 +00:00
Nadav Rotem
3ce2bfbb55
Fix a regression from r125393;
...
It caused a crash in MultiSource/Benchmarks/Bullet.
Opt hit an assertion with "opt -std-compile-opts" because
Constant::getAllOnesValue doesn't know how to handle floats.
This patch added a test to reproduce the problem and a check that the
destination vector is of integer type.
Thank you Benjamin!
llvm-svn: 125459
2011-02-13 15:45:34 +00:00