Commit Graph

210 Commits

Author SHA1 Message Date
Chris Lattner
e5cbdca3bd recognize an unsigned add with overflow idiom into uadd.
This resolves a README entry and technically resolves PR4916,
but we still get poor code for the testcase in that PR because
GVN isn't CSE'ing uadd with add, filed as PR8817.

Previously we got:

_test7:                                 ## @test7
	addq	%rsi, %rdi
	cmpq	%rdi, %rsi
	movl	$42, %eax
	cmovaq	%rsi, %rax
	ret

Now we get:

_test7:                                 ## @test7
	addq	%rsi, %rdi
	movl	$42, %eax
	cmovbq	%rsi, %rax
	ret



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122182 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-19 19:37:52 +00:00
Chris Lattner
9448184b99 add another overflow idiom
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121854 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-15 07:28:58 +00:00
Chris Lattner
08859ffa63 add a note about overflow idiom recognition.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121853 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-15 07:25:55 +00:00
Chris Lattner
ef17f08dbc add a shift/imul missed optimization
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121850 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-15 07:10:43 +00:00
Chris Lattner
2fc36e19b1 add a note about a SPEC hack that gcc mainline does.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121849 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-15 06:38:24 +00:00
Chris Lattner
a97c91f014 add a note
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121656 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-13 00:15:25 +00:00
Benjamin Kramer
2f7228b80c Generalize the and-icmp-select instcombine further by allowing selects of the form
(x & 2^n) ? 2^m+C : C

we can offset both arms by C to get the "(x & 2^n) ? 2^m : 0" form, optimize the
select to a shift and apply the offset afterwards.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121609 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-11 10:49:22 +00:00
Benjamin Kramer
c21a821e9f The srem -> urem transform is not safe for any divisor that's not a power of two.
E.g. -5 % 5 is 0 with srem and 1 with urem.

Also addresses Frits van Bommel's comments.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120049 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 20:33:57 +00:00
Benjamin Kramer
b70ebd2aa3 InstCombine: Reduce "X shift (A srem B)" to "X shift (A urem B)" iff B is positive.
This allows to transform the rem in "1 << ((int)x % 8);" to an and.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120028 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-23 18:52:42 +00:00
Benjamin Kramer
93f8455d73 InstCombine: Implement X - A*-B -> X + A*B.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119984 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 20:31:27 +00:00
Benjamin Kramer
ce750f0332 Implement the "if (X == 6 || X == 4)" -> "if ((X|2) == 6)" optimization.
This currently only catches the most basic case, a two-case switch, but can be
extended later.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119964 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-22 09:45:38 +00:00
Chris Lattner
3e41106de4 add some random notes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119925 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 07:05:31 +00:00
Chris Lattner
75d8f599e7 optimize:
void a(int x) { if (((1<<x)&8)==0) b(); }

into "x != 3", which occurs over 100 times in 403.gcc but in no
other program in llvm-test.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119922 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 06:44:42 +00:00
Chris Lattner
79a980ad85 tail calls on x86 are implemented.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119920 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21 06:10:27 +00:00
Chris Lattner
af510f16ec add a note
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118806 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-11 18:23:57 +00:00
Chris Lattner
1e68fdb946 add pr#
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118797 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-11 17:17:56 +00:00
Chris Lattner
274191fa70 add a case we fail to devirt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118608 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-09 19:37:28 +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
Benjamin Kramer
019e378754 Add a note.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118337 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-06 10:37:16 +00:00
Benjamin Kramer
9510a2538b Add constant folding for strspn and strcspn to SimplifyLibCalls.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115116 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-30 00:58:35 +00:00
Chris Lattner
313a94c3d0 idiom recognition should catch this.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114304 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-19 00:37:34 +00:00
Nick Lewycky
b1e4eebec0 Add optimization to Target/README.txt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110543 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-08 07:04:25 +00:00
Benjamin Kramer
1db071f0da Teach instcombine to transform
(X >s -1) ? C1 : C2 and (X <s  0) ? C2 : C1
into ((X >>s 31) & (C2 - C1)) + C1, avoiding the conditional.

This optimization could be extended to take non-const C1 and C2 but we better
stay conservative to avoid code size bloat for now.

for
int sel(int n) {
     return n >= 0 ? 60 : 100;
}

we now generate
  sarl  $31, %edi
  andl  $40, %edi
  leal  60(%rdi), %eax

instead of
  testl %edi, %edi
  movl  $60, %ecx
  movl  $100, %eax
  cmovnsl %ecx, %eax


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107866 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-08 11:39:10 +00:00
Eli Friedman
b482829abb Minor amendment to switch-lowering improvement.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107569 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-03 08:43:32 +00:00
Eli Friedman
b4a74c1d82 Note switch-lowering inefficiency.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107565 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-03 07:38:12 +00:00
Eric Christopher
33634d0672 Add another bswap idiom that isn't matched.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107213 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-29 22:22:22 +00:00
Benjamin Kramer
0f471e018f TODO--
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106102 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-16 15:47:00 +00:00
Eli Friedman
8c47d3b73f Add README entry; based on testcase from Bill Hart.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105878 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-12 05:54:27 +00:00
Chris Lattner
c2685a9c98 add a note
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104404 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-21 23:16:21 +00:00
Dan Gohman
3a2a4846a6 Add a README entry.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102906 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-03 14:31:00 +00:00
Chris Lattner
9484689f14 add a note
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101581 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-16 23:52:30 +00:00
Chris Lattner
2392ae7d73 Implement rdar://7860110 (also in target/readme.txt) narrowing
a load/or/and/store sequence into a narrower store when it is
safe.  Daniel tells me that clang will start producing this sort
of thing with bitfields, and this does  trigger a few dozen times
on 176.gcc produced by llvm-gcc even now.

This compiles code like CodeGen/X86/2009-05-28-DAGCombineCrash.ll 
into:

        movl    %eax, 36(%rdi)

instead of:

        movl    $4294967295, %eax       ## imm = 0xFFFFFFFF
        andq    32(%rdi), %rax
        shlq    $32, %rcx
        addq    %rax, %rcx
        movq    %rcx, 32(%rdi)

and each of the testcases into a single store.  Each of them used
to compile into craziness like this:

_test4:
	movl	$65535, %eax            ## imm = 0xFFFF
	andl	(%rdi), %eax
	shll	$16, %esi
	addl	%eax, %esi
	movl	%esi, (%rdi)
	ret




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101343 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-15 04:48:01 +00:00
Chris Lattner
6663670359 move PR6576 here.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98194 91177308-0d34-0410-b5e6-96231b3b80d8
2010-03-10 21:42:42 +00:00
Chris Lattner
cf031f6d66 move PR6212 to this file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95624 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-09 00:11:10 +00:00
Eli Friedman
1144d7e3cc Remove a completed item, add a couple new ones.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94945 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-31 04:55:32 +00:00
Bob Wilson
3eb4f7e2dd Improve isSafeToLoadUnconditionally to recognize that GEPs with constant
indices are safe if the result is known to be within the bounds of the
underlying object.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94829 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29 19:19:08 +00:00
Chris Lattner
43dc2e6d76 reassociate should do this.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94374 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-24 20:17:09 +00:00
Chris Lattner
10c4245103 add a note.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94373 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-24 20:01:41 +00:00
Chris Lattner
818ff34bc0 implement a simple instcombine xform that has been in the
readme forever.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94318 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-23 18:49:30 +00:00
Chris Lattner
aa306c2cc1 add some notes, making posix-memalign be nocapture would be an easy improvement.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94312 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-23 17:59:23 +00:00
Eli Friedman
9cfb3adf44 Add some potentially interesting transformations to README.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93797 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-18 22:36:59 +00:00
Duncan Sands
e10920d678 Fix a README item: have functionattrs look through selects and
phi nodes when deciding which pointers point to local memory.
I actually checked long ago how useful this is, and it isn't
very: it hardly ever fires in the testsuite, but since Chris
wants it here it is!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92836 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-06 15:37:47 +00:00
Duncan Sands
7c422ac216 Partially address a README by having functionattrs consider calls to
memcpy, memset and other intrinsics that only access their arguments
to be readnone if the intrinsic's arguments all point to local memory.
This improves the testcase in the README to readonly, but it could in
theory be made readnone, however this would involve more sophisticated
analysis that looks through the memcpy.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92829 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-06 08:45:52 +00:00
Chris Lattner
e4412c1f0b implement an instcombine xform needed by clang's codegen
on the example in PR4216.  This doesn't trigger in the testsuite,
so I'd really appreciate someone scrutinizing the logic for
correctness.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92458 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-04 06:03:59 +00:00
Chris Lattner
f031e8ad01 Teach codegen to lower llvm.powi to an efficient (but not optimal)
multiply sequence when the power is a constant integer.  Before, our
codegen for std::pow(.., int) always turned into a libcall, which was
really inefficient.

This should also make many gfortran programs happier I'd imagine.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92388 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-01 03:32:16 +00:00
Chris Lattner
398ffba75f update this. To take the next step, llvm.powi should be generalized to work
on integers as well and codegen should lower them to branch trees.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92382 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-01 01:29:26 +00:00
Eli Friedman
bcae205a4b More info on this transformation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91230 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-12 23:23:43 +00:00
Eli Friedman
1555473387 Remove some stuff that's already implemented. Also, remove the note about
merging x >u 5 and x <s 20 because it's impossible to implement.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91228 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-12 21:41:48 +00:00
Chris Lattner
89742c2c3f expand note.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90429 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-03 07:43:46 +00:00
Chris Lattner
053321731c add a note
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90428 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-03 07:41:54 +00:00