Nick Lewycky
4ab50b93c8
Chris prefers icmp/select over udiv!
...
llvm-svn: 60187
2008-11-27 22:41:10 +00:00
Nick Lewycky
69941fd0a0
Add a couple of missed optimizations on integer vectors. Multiply and divide
...
by 1, as well as multiply by -1.
llvm-svn: 60182
2008-11-27 20:21:08 +00:00
Nick Lewycky
07d726ec4d
Optimize (x/y)*y into x-(x%y) in general. Div and rem are about the same, and
...
a subtract is cheaper than a multiply. This generalizes an existing transform.
llvm-svn: 59800
2008-11-21 07:33:58 +00:00
Chris Lattner
c3f3b059d0
Handle the case where there is no "not". It is possible it got
...
folded into the select.
llvm-svn: 59389
2008-11-16 04:25:26 +00:00
Chris Lattner
645f60141b
make this actually test what it is trying to.
...
llvm-svn: 59386
2008-11-16 04:21:51 +00:00
Bill Wendling
3f547be28f
If the LHS of the FCMP is coming from a UIToFP instruction, then we don't want
...
to generate signed ICMP instructions to replace the FCMP. This would violate
the following:
define i1 @test1(i32 %val) {
%1 = uitofp i32 %val to double
%2 = fcmp ole double %1, 0.000000e+00
ret i1 %2
}
would be transformed into:
define i1 @test1(i32 %val) {
%1 = icmp slt i33 %val, 1
ret i1 %1
}
which is obviously wrong. This patch modifes InstCombiner::FoldFCmp_IntToFP_Cst
to handle when the LHS comes from UIToFP.
llvm-svn: 58929
2008-11-09 04:26:50 +00:00
Nick Lewycky
8d8acf327b
Fix demanded bits analysis with srem by negative number. Based on a patch
...
by Richard Osborne.
llvm-svn: 58555
2008-11-02 02:41:50 +00:00
Dan Gohman
83eea0b17f
Fix this recently moved code to use the correct type. CI is now a
...
ConstantInt, and SI is the original cast instruction. This fixes
PR2996.
llvm-svn: 58549
2008-11-02 00:17:33 +00:00
Dan Gohman
13cbcf1c18
Canonicalize sext(i1) to i1?-1:0, and update various instcombine
...
optimizations accordingly.
llvm-svn: 58457
2008-10-30 20:40:10 +00:00
Dan Gohman
2c34c130bf
(A & sext(C)) | (B & ~sext(C) -> C ? A : B
...
llvm-svn: 58351
2008-10-28 22:38:57 +00:00
Nick Lewycky
730d5dade6
Don't try to create a mask when we don't need one. Fixes a crash.
...
llvm-svn: 58075
2008-10-24 06:14:27 +00:00
Dan Gohman
bc0278400c
Teach instcombine's visitLoad to scan back several instructions
...
to find opportunities for store-to-load forwarding or load CSE,
in the same way that visitStore scans back to do DSE. Also, define
a new helper function for testing whether the addresses of two
memory accesses are known to have the same value, and use it in
both visitStore and visitLoad.
These two changes allow instcombine to eliminate loads in code
produced by front-ends that frequently emit obviously redundant
addressing for memory references.
llvm-svn: 57608
2008-10-15 23:19:35 +00:00
Evan Cheng
d885f6e139
Combine (fcmp cc0 x, y) | (fcmp cc1 x, y) into a single fcmp when possible.
...
llvm-svn: 57515
2008-10-14 18:44:08 +00:00
Evan Cheng
ce70752b11
- Somehow I forgot about one / une.
...
- Renumber fcmp predicates to match their icmp counterparts.
- Try swapping operands to expose more optimization opportunities.
llvm-svn: 57513
2008-10-14 18:13:38 +00:00
Evan Cheng
67786cce66
Optimize anding of two fcmp into a single fcmp if the operands are the same. e.g. uno && ueq -> ueq
...
ord && olt -> olt
ord && ueq -> oeq
llvm-svn: 57507
2008-10-14 17:15:11 +00:00
Chris Lattner
da435910e8
Fix PR2697 by rewriting the '(X / pos) op neg' logic. This also changes
...
a couple other cases for clarity, but shouldn't affect correctness.
Patch by Eli Friedman!
llvm-svn: 57387
2008-10-11 22:55:00 +00:00
Chris Lattner
917a6c1343
rewrite bswap matching to be more general, allowing arbitrary
...
shifting and masking inside a bswap expr. This allows it to handle
the cases from PR2842, which involve the intermediate 'or'
expressions being shifted, not just the input value.
llvm-svn: 57095
2008-10-05 02:13:19 +00:00
Nick Lewycky
e8ced3ec19
Fix misoptimization of: xor i1 (icmp eq (X, C1), icmp s[lg]t (X, C2))
...
llvm-svn: 56834
2008-09-30 06:08:34 +00:00
Dan Gohman
dafa9c6e85
Improve instcombine's handling of integer min and max in two ways:
...
- Recognize expressions like "x > -1 ? x : 0" as min/max and turn them
into expressions like "x < 0 ? 0 : x", which is easily recognizable
as a min/max operation.
- Refrain from folding expression like "y/2 < 1" to "y < 2" when the
comparison is being used as part of a min or max idiom, like
"y/2 < 1 ? 1 : y/2". In that case, the division has another use, so
folding doesn't eliminate it, and obfuscates the min/max, making it
harder to recognize as a min/max operation.
These benefit ScalarEvolution, CodeGen, and anything else that wants to
recognize integer min and max.
llvm-svn: 56246
2008-09-16 18:46:06 +00:00
Dan Gohman
eff71f2953
On 64-bit targets, change 32-bit getelementptr indices to be 64-bit
...
getelementptr indices, inserting an explicit cast if necessary.
This helps expose the sign-extension operation to other optimizations.
llvm-svn: 56133
2008-09-11 23:06:38 +00:00
Dan Gohman
7d01c0654c
Fix a vectorshuffle instcombine bug introduced by r55995.
...
Patch by Nicolas Capens!
llvm-svn: 56129
2008-09-11 22:47:57 +00:00
Dan Gohman
c1ae01688f
Fix an icmp+sdiv optimization to check for and handle an overflow
...
condition. This fixes PR2740.
llvm-svn: 56076
2008-09-10 23:30:57 +00:00
Dan Gohman
86fb5b48de
Make SimplifyDemandedVectorElts simplify vectors with multiple
...
users, and teach it about shufflevector instructions.
Also, fix a subtle bug in SimplifyDemandedVectorElts'
insertelement code.
This is a patch that was originally written by Eli Friedman,
with some fixes and cleanup by me.
llvm-svn: 55995
2008-09-09 18:11:14 +00:00
Nick Lewycky
f023db6444
Don't crash when trying to constant fold a vector with some elements that can't
...
be folded. Instead, fail to fold the entire vector.
We could also return a vector with some elements folded and some not. If anyone
thinks that's a better approach, please speak up!
llvm-svn: 55689
2008-09-03 05:54:33 +00:00
Nick Lewycky
99f4558117
Revert r54876 r54877 r54906 and r54907. Evan found that these caused a 20%
...
slowdown in bzip2.
llvm-svn: 55113
2008-08-21 05:56:10 +00:00
Nick Lewycky
53b44029d6
Consider the case where xor by -1 and xor by 128 have been combined already to
...
produce an xor by 127.
llvm-svn: 54906
2008-08-17 19:58:24 +00:00
Nick Lewycky
18f50b2637
Xor'ing both sides of icmp by sign-bit is equivalent to swapping signedness of
...
the predicate.
Also, make this optz'n apply in more cases where it's safe to do so.
llvm-svn: 54876
2008-08-17 07:34:14 +00:00
Owen Anderson
2a6adfa4f0
Remove GCSE and LoadVN from the testsuite.
...
llvm-svn: 54832
2008-08-16 00:00:54 +00:00
Dan Gohman
6134fbccef
Fix a bogus srem rule - a negative value srem'd by a power-of-2
...
can have a non-negative result; for example, -16%16 is 0. Also,
clarify the related comments. This fixes PR2670.
llvm-svn: 54767
2008-08-13 23:12:35 +00:00
Chris Lattner
2aa0ff27aa
Implement support for simplifying vector comparisons by 0.0 and 1.0 like we
...
do for scalars. Patch contributed by Nicolas Capens
This also generalizes the previous xforms to work on long double, now that
isExactlyValue works for long double.
llvm-svn: 54653
2008-08-11 22:06:05 +00:00
Dan Gohman
ac22cfcae9
Fix a shufflevector instcombine that was emitting invalid masks indices
...
when it meant to be emitting undef indices.
llvm-svn: 54417
2008-08-06 18:17:32 +00:00
Chris Lattner
f5b353c1fd
optimize a common idiom generated by clang for bitfield access, PR2638.
...
llvm-svn: 54408
2008-08-06 07:35:52 +00:00
Chris Lattner
7bdaecb7f4
Zap sitofp/fptoui pairs. In all cases when the sign difference
...
matters, the result is undefined anyway.
llvm-svn: 54396
2008-08-06 05:13:06 +00:00
Nick Lewycky
bf42893567
Reinstate this optimization, but without the miscompile. Thanks to Bill for
...
tracking down that this was breaking llvm-gcc bootstrap on Linux.
llvm-svn: 54394
2008-08-06 04:54:03 +00:00
Bill Wendling
0e966d3e2c
Just grep for through the LL code instead of the ASM code
...
llvm-svn: 54389
2008-08-06 00:10:32 +00:00
Bill Wendling
bc6786e7ee
Add default architecture.
...
llvm-svn: 54384
2008-08-05 23:36:00 +00:00
Bill Wendling
3dfa168d22
Testcase for PR2629.
...
llvm-svn: 54377
2008-08-05 22:23:59 +00:00
Bill Wendling
ee12a7aeff
Revert r53282. This was causing a miscompile on Linux. Also, the transformation
...
looks bogus. Please see PR2629 for details on why this is breaking things.
llvm-svn: 54372
2008-08-05 21:23:45 +00:00
Chris Lattner
c600c53d1f
Fix PR2553
...
llvm-svn: 53715
2008-07-17 06:07:20 +00:00
Matthijs Kooijman
f22f34f0cc
Add a few cases to instcombine's extractvalue testcase.
...
llvm-svn: 53675
2008-07-16 12:57:25 +00:00
Evan Cheng
c97094552c
Fix PR2296. Do not transform x86_sse2_storel_dq into a full-width store.
...
llvm-svn: 53666
2008-07-16 07:28:14 +00:00
Chris Lattner
16395e51f4
Fix PR2506 by being a bit more careful about reverse fact propagation when
...
disproving a condition. This actually compiles the existing testcase
(udiv_select_to_select_shift) to:
define i64 @test(i64 %X, i1 %Cond) {
entry:
%divisor1.t = lshr i64 %X, 3 ; <i64> [#uses=1]
%quotient2 = lshr i64 %X, 3 ; <i64> [#uses=1]
%sum = add i64 %divisor1.t, %quotient2 ; <i64> [#uses=1]
ret i64 %sum
}
instead of:
define i64 @test(i64 %X, i1 %Cond) {
entry:
%quotient1.v = select i1 %Cond, i64 3, i64 4 ; <i64> [#uses=1]
%quotient1 = lshr i64 %X, %quotient1.v ; <i64> [#uses=1]
%quotient2 = lshr i64 %X, 3 ; <i64> [#uses=1]
%sum = add i64 %quotient1, %quotient2 ; <i64> [#uses=1]
ret i64 %sum
}
llvm-svn: 53534
2008-07-14 00:15:52 +00:00
Nick Lewycky
f76aa23b54
Enhance analysis of srem.
...
Remove dead code analyzing urem. 'urem' of power-of-2 is canonicalized to an
'and' instruction.
llvm-svn: 53506
2008-07-12 05:04:38 +00:00
Nick Lewycky
f95b64acaa
Add another optimization from PR2330. Also catch some missing cases that are
...
similar.
llvm-svn: 53451
2008-07-11 07:20:53 +00:00
Chris Lattner
6af608b8ce
Fix folding of icmp's of i1 where the comparison is signed. The code
...
was using the algorithm for folding unsigned comparisons which is
completely wrong. This has been broken since the signless types change.
llvm-svn: 53444
2008-07-11 04:20:58 +00:00
Chris Lattner
4fa8bb3430
Fix a bogus optimization: folding (slt (zext i1 A to i32), 1) -> (slt i1 A, true)
...
This cause a regression in InstCombine/JavaCompare, which was doing the right
thing on accident. To handle the missed case, generalize the comparisons based
on masked bits a little bit to handle comparisons against the max value. For
example, we can now xform (slt i32 (and X, 4), 4) -> (setne i32 (and X, 4), 4)
llvm-svn: 53443
2008-07-11 04:09:09 +00:00
Chris Lattner
1be09d9e21
make this condition more precise.
...
llvm-svn: 53442
2008-07-11 03:54:57 +00:00
Nick Lewycky
6193a564ab
Fix overzealous optimization. Thanks to Duncan Sands for pointing out my error!
...
llvm-svn: 53393
2008-07-10 05:51:40 +00:00
Nick Lewycky
f9c27c343a
Fold (a < 8) && (b < 8) into (a|b) < 8 for unsigned less or greater than.
...
llvm-svn: 53282
2008-07-09 07:29:11 +00:00
Nick Lewycky
364661c43e
Fold ((1 << a) & 1) to (a == 0).
...
llvm-svn: 53276
2008-07-09 05:20:13 +00:00