Commit Graph

2354 Commits

Author SHA1 Message Date
John McCall bd04b74bb2 Fix the inliner to maintain the current de facto invoke semantics:
- the selector for the landing pad must provide all available information
    about the handlers, filters, and cleanups within that landing pad
  - calls to _Unwind_Resume must be converted to branches to the enclosing
    lpad so as to avoid re-entering the unwinder when the lpad claimed it
    was going to handle the exception in some way
This is quite specific to libUnwind-based unwinding.  In an effort to not
interfere too badly with other unwinders, and with existing hacks in frontends,
this only triggers on _Unwind_Resume (not _Unwind_Resume_or_Rethrow) and does
nothing with selectors if it cannot find a selector call for either lpad.

llvm-svn: 132200
2011-05-27 18:34:38 +00:00
Benjamin Kramer 749ef5f420 InstCombine: Make switch folding with equality compares more aggressive by trying instsimplify on the arm where we know the compared value.
Stuff like "x == y ? y : x&y" now folds into "x&y".

llvm-svn: 132185
2011-05-27 13:00:16 +00:00
Chad Rosier b362884ca9 Renamed llvm.x86.sse42.crc32 intrinsics; crc64 doesn't exist.
crc32.[8|16|32] have been renamed to .crc32.32.[8|16|32] and
crc64.[8|16|32] have been renamed to .crc32.64.[8|64].

llvm-svn: 132163
2011-05-26 23:13:19 +00:00
Andrew Trick 7fac79e255 indvars: incremental fixes for -disable-iv-rewrite and testcases.
Use a proper worklist for use-def traversal without holding onto an
iterator. Now that we process all IV uses, we need complete logic for
resusing existing derived IV defs. See HoistStep.

llvm-svn: 132103
2011-05-26 00:46:11 +00:00
Eli Friedman 865866e7fe PR9998: ashr exact %x, 31 is not equivalent to sdiv exact %x, -2147483648.
llvm-svn: 132097
2011-05-25 23:26:20 +00:00
Andrew Trick eb3c36e69c indvars: fixed IV cloning in -disable-iv-rewrite mode with associated
cleanup and overdue test cases.

llvm-svn: 132038
2011-05-25 04:42:22 +00:00
Cameron Zwarich d7707fc911 Fix "make check" in Release by removing debug-only options from an 'opt' invocation.
llvm-svn: 131972
2011-05-24 18:26:09 +00:00
Cameron Zwarich 843bc7d673 Make LoadAndStorePromoter preserve debug info and create llvm.dbg.values when
promoting allocas to SSA variables. Fixes <rdar://problem/9479036>.

llvm-svn: 131953
2011-05-24 03:10:43 +00:00
Andrew Trick 37f0082804 FileCheck-ize a couple of IV unit tests.
llvm-svn: 131946
2011-05-24 01:02:49 +00:00
Andrew Trick 1ea0243bd0 Test case for r130799 - indvars: Added canExpandBackEdgeTakenCount.
llvm-svn: 131939
2011-05-24 00:17:53 +00:00
Chris Lattner 026f5e61f0 fix a really nasty basicaa mod/ref calculation bug that was causing miscompilation of
UnitTests/ObjC/messages-2.m with the recent optimizer improvements.

llvm-svn: 131897
2011-05-23 05:15:43 +00:00
Chris Lattner 8aff4f8efc Transform any logical shift of a power of two into an exact/NUW shift when
in a known-non-zero context.

llvm-svn: 131887
2011-05-23 00:21:50 +00:00
Chris Lattner 83791ced7b Teach valuetracking that byval arguments with a specified alignment are
aligned.

Teach memcpyopt to not give up all hope when confonted with an underaligned
memcpy feeding an overaligned byval.  If the *source* of the memcpy can be
determined to be adequeately aligned, or if it can be forced to be, we can
eliminate the memcpy.

This addresses PR9794.  We now compile the example into:

define i32 @f(%struct.p* nocapture byval align 8 %q) nounwind ssp {
entry:
  %call = call i32 @g(%struct.p* byval align 8 %q) nounwind
  ret i32 %call
}

in both x86-64 and x86-32 mode.  We still don't get a tailcall though,
because tailcalls apparently can't handle byval.

llvm-svn: 131884
2011-05-23 00:03:39 +00:00
Chris Lattner 713d52364f implement PR9315, constant folding exp2 in terms of pow (since hosts without
C99 runtimes don't have exp2).

llvm-svn: 131872
2011-05-22 22:22:35 +00:00
Chris Lattner 7c99f19d9f Carve out a place in instcombine to put transformations which work knowing that their
result is non-zero.  Implement an example optimization (PR9814), which allows us to
transform:
  A / ((1 << B) >>u 2)
into:
  A >>u (B-2)

which we compile into:

_divu3:                                 ## @divu3
	leal	-2(%rsi), %ecx
	shrl	%cl, %edi
	movl	%edi, %eax
	ret

instead of:

_divu3:                                 ## @divu3
	movb	%sil, %cl
	movl	$1, %esi
	shll	%cl, %esi
	shrl	$2, %esi
	movl	%edi, %eax
	xorl	%edx, %edx
	divl	%esi, %eax
	ret

llvm-svn: 131860
2011-05-22 18:18:41 +00:00
Chris Lattner c4ca7ab7e7 Fix PR9815: I was trying to get out of "generating code and then
failing to form a memset, then having to delete it" but my approximation
isn't safe for self recurrent loops.  Instead of doign a hack, just
do it the right way.

llvm-svn: 131858
2011-05-22 17:39:56 +00:00
Frits van Bommel ad964559ef Add a parameter to ConstantFoldTerminator() that callers can use to ask it to also clean up the condition of any conditional terminator it folds to be unconditional, if that turns the condition into dead code. This just means it calls RecursivelyDeleteTriviallyDeadInstructions() in strategic spots. It defaults to the old behavior.
I also changed -simplifycfg, -jump-threading and -codegenprepare to use this to produce slightly better code without any extra cleanup passes (AFAICT this was the only place in -simplifycfg where now-dead conditions of replaced terminators weren't being cleaned up). The only other user of this function is -sccp, but I didn't read that thoroughly enough to figure out whether it might be holding pointers to instructions that could be deleted by this.

llvm-svn: 131855
2011-05-22 16:24:18 +00:00
Chris Lattner 1a1acc2191 fix PR9856, an incorrectly conservative assertion: a global can be
"stored once" even if its address is compared.

llvm-svn: 131849
2011-05-22 07:15:13 +00:00
Chris Lattner f0d59072de fix PR9841 by having GVN not process dead loads. This was
causing it to get into infinite loops when it would widen a 
load (which can necessarily leave around dead loads).

llvm-svn: 131847
2011-05-22 07:03:34 +00:00
Chris Lattner a10327f531 remove a trivial test, make some other tests less trivial.
llvm-svn: 131846
2011-05-22 07:02:43 +00:00
Chris Lattner cc87723178 make this test less trivial.
llvm-svn: 131845
2011-05-22 06:59:33 +00:00
Nick Lewycky d60e135cfe Commit test change, forgotten as part of r131838.
llvm-svn: 131839
2011-05-22 05:31:47 +00:00
Nick Lewycky a68ec83b36 Teach the inliner to emit llvm.lifetime.start/end, to scope the local variables
of the inlinee to the code representing the original function.

llvm-svn: 131838
2011-05-22 05:22:10 +00:00
Nick Lewycky 1c8af13719 Fix grammar in test.
llvm-svn: 131831
2011-05-22 01:16:00 +00:00
Benjamin Kramer fda5dc4968 Revert "InstCombine: Turn mul.with.overflow(X, 2) into the cheaper add.with.overflow(X, X)"
It's better to do this in codegen, mul.with.overflow(X, 2) is more canonical because it has only one use on "X".

llvm-svn: 131798
2011-05-21 18:31:42 +00:00
Benjamin Kramer 691731eb9c InstCombine: Turn mul.with.overflow(X, 2) into the cheaper add.with.overflow(X, X)
llvm-svn: 131789
2011-05-21 09:22:06 +00:00
Evan Cheng e8d2e9eb35 Revert r131664 and fix it in instcombine instead. rdar://9467055
llvm-svn: 131708
2011-05-20 00:54:37 +00:00
Stuart Hastings ae012a7525 Move test to Transforms/InstCombine.
llvm-svn: 131634
2011-05-19 05:53:22 +00:00
Rafael Espindola 3f60a0b411 Add test for PR9946.
llvm-svn: 131621
2011-05-19 02:35:26 +00:00
Eli Friedman 41e509a33d More instcombine cleanup, towards improving debug line info.
llvm-svn: 131604
2011-05-18 23:58:37 +00:00
Dan Gohman 3268e4d692 When forming an ICmpZero LSRUse, normalize the non-IV operand
of the comparison, so that the resulting expression is fully
normalized. This fixes PR9939.

llvm-svn: 131576
2011-05-18 21:02:18 +00:00
Eli Friedman 49346010f8 More instcombine cleanup aimed towards improving debug line info.
llvm-svn: 131559
2011-05-18 19:57:14 +00:00
Eli Friedman 96254a0d53 Start trying to make InstCombine preserve more debug info. The idea here is to set the debug location on the IRBuilder, which will be then right location in most cases. This should magically give many transformations debug locations, and fixing places which are missing a debug location will usually just means changing the code creating it to use the IRBuilder.
As an example, the change to InstCombineCalls catches a common case where a call to a bitcast of a function is rewritten.

Chris, does this approach look reasonable?

llvm-svn: 131516
2011-05-18 01:28:27 +00:00
Stuart Hastings a7ae4552af Drop lli, revise test.
llvm-svn: 131452
2011-05-17 02:38:59 +00:00
Rafael Espindola 2050af838d Don't do tail calls in a function that call setjmp. The stack might be
corrupted when setjmp returns again.

llvm-svn: 131399
2011-05-16 03:05:33 +00:00
Benjamin Kramer cb7e56e592 Disable test harder.
llvm-svn: 131363
2011-05-14 19:30:39 +00:00
Stuart Hastings 3c2fd1cf62 Disable this test while I revise it. rdar://problem/9267970
llvm-svn: 131350
2011-05-14 18:39:05 +00:00
Benjamin Kramer d96205c4e5 SimplifyCFG: Use ComputeMaskedBits to prune dead cases from switch instructions.
llvm-svn: 131345
2011-05-14 15:57:25 +00:00
Stuart Hastings 66a82b966e Avoid combining GEPs that might overflow at runtime.
rdar://problem/9267970

Patch by Julien Lerouge!

llvm-svn: 131339
2011-05-14 05:55:10 +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
Galina Kistanova a335f5aeeb Move few target-dependant tests to appropriate directories.
llvm-svn: 131002
2011-05-06 18:24:46 +00:00
Duncan Sands a071c82900 Fix PR9820: a read-only call differs from a load in that a load doesn't
return the pointer being dereferenced, it returns the pointee, but a call
might return the pointer itself.

llvm-svn: 130979
2011-05-06 10:30:37 +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
Benjamin Kramer 9aa91b1f4e InstCombine: Turn (zext A) udiv (zext B) into (zext (A udiv B)). Same for urem or constant B.
This obviously helps a lot if the division would be turned into a libcall
(think i64 udiv on i386), but div is also one of the few remaining instructions
on modern CPUs that become more expensive when the bitwidth gets bigger.

This also helps register pressure on i386 when dividing chars, divb needs
two 8-bit parts of a 16 bit register as input where divl uses two registers.

int foo(unsigned char a) { return a/10; }
int bar(unsigned char a, unsigned char b) { return a/b; }

compiles into (x86_64)
_foo:
  imull $205, %edi, %eax
  shrl  $11, %eax
  ret
_bar:
  movzbl        %dil, %eax
  divb  %sil, %al
  movzbl        %al, %eax
  ret

llvm-svn: 130615
2011-04-30 18:16:07 +00:00
Benjamin Kramer 57b3df59b9 Use SimplifyDemandedBits on div instructions.
This folds away silly stuff like (a&255)/1000 -> 0.

llvm-svn: 130614
2011-04-30 18:16:00 +00:00
Benjamin Kramer 6a50bbd284 FileCheckize.
llvm-svn: 130613
2011-04-30 18:15:53 +00:00