Commit Graph

3289 Commits

Author SHA1 Message Date
Duncan Sands
c087e20331 Turn X-(X-Y) into Y. According to my auto-simplifier this is the most common
simplification present in fully optimized code (I think instcombine fails to
transform some of these when "X-Y" has more than one use).  Fires here and
there all over the test-suite, for example it eliminates 8 subtractions in
the final IR for 445.gobmk, 2 subs in 447.dealII, 2 in paq8p etc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123442 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 15:26:10 +00:00
Duncan Sands
cf80bc1d4a Factorize common code out of the InstructionSimplify shift logic. Add in
threading of shifts over selects and phis while there.  This fires here and
there in the testsuite, to not much effect.  For example when compiling spirit
it fires 5 times, during early-cse, resulting in 6 more cse simplifications,
and 3 more terminators being folded by jump threading, but the final bitcode
doesn't change in any interesting way: other optimizations would have caught
the opportunity anyway, only later.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123441 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 14:44:12 +00:00
Duncan Sands
62becca681 Rename this test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123440 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 14:16:33 +00:00
Chris Lattner
bdb6b7f9c7 relax testcase a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123433 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 07:46:33 +00:00
Duncan Sands
c43cee3fbb Move some shift transforms out of instcombine and into InstructionSimplify.
While there, I noticed that the transform "undef >>a X -> undef" was wrong.
For example if X is 2 then the top two bits must be equal, so the result can
not be anything.  I fixed this in the constant folder as well.  Also, I made
the transform for "X << undef" stronger: it now folds to undef always, even
though X might be zero.  This is in accordance with the LangRef, but I must
admit that it is fairly aggressive.  Also, I added "i32 X << 32 -> undef"
following the LangRef and the constant folder, likewise fairly aggressive.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123417 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-14 00:37:45 +00:00
Bob Wilson
704d1347c5 Extend SROA to handle arrays accessed as homogeneous structs and vice versa.
This is a minor extension of SROA to handle a special case that is
important for some ARM NEON operations.  Some of the NEON intrinsics
return multiple values, which are handled as struct types containing
multiple elements of the same vector type.  The corresponding return
types declared in the arm_neon.h header have equivalent arrays.  We
need SROA to recognize that it can split up those arrays and structs
into separate vectors, even though they are not always accessed with
the same type.  SROA already handles loads and stores of an entire
alloca by using insertvalue/extractvalue to access the individual
pieces, and that code works the same regardless of whether the type
is a struct or an array.  So, all that needs to be done is to check
for compatible arrays and homogeneous structs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123381 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-13 17:45:11 +00:00
Bob Wilson
694a10e7d8 Make SROA more aggressive with allocas containing padding.
SROA only split up structs and arrays one level at a time, so padding can
only cause trouble if it is located in between the struct or array elements.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123380 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-13 17:45:08 +00:00
Duncan Sands
6dc91253ab The most common simplification missed by instsimplify in unoptimized bitcode
is "X != 0 -> X" when X is a boolean.  This occurs a lot because of the way
llvm-gcc converts gcc's conditional expressions.  Add this, and a few other
similar transforms for completeness.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123372 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-13 08:56:29 +00:00
Chris Lattner
d318fc2ceb revert 123144, reenabling the rest of memset formation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123302 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-12 03:25:15 +00:00
Chris Lattner
d2e905027b revert r123146 which disabled code that wasn't the root cause
of the bootstrap miscompare issue.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123299 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-12 01:52:23 +00:00
Chris Lattner
86099ba2b5 merge tests into one crash.ll test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123220 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 07:50:07 +00:00
Chris Lattner
93767fdb61 remove a bogus assertion: the latch block of a loop is not
neccesarily an uncond branch to the header.  This fixes 
PR8955 (the assertion tripping).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123219 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 07:47:59 +00:00
Chandler Carruth
15ed90c859 Teach constant folding to perform conversions from constant floating
point values to their integer representation through the SSE intrinsic
calls. This is the last part of a README.txt entry for which I have real
world examples.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123206 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 01:07:24 +00:00
Chandler Carruth
f7b0047f5f FileCheck-ize a test, and move a no-longer calling test case to another
file and make it actually test something...

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123205 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 01:07:20 +00:00
Owen Anderson
da1c122da5 Fix a random missed optimization by making InstCombine more aggressive when determining which bits are demanded by
a comparison against a constant.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123203 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-11 00:36:45 +00:00
Chandler Carruth
9cc9f50abc Teach instcombine about the rest of the SSE and SSE2 conversion
intrinsics element dependencies. Reviewed by Nick.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123161 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 07:19:37 +00:00
Chandler Carruth
fdc8f2d260 Fold two related tests into the newly FileCheck-ized test, migrating
them to FileCheck as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123154 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 02:53:58 +00:00
Chandler Carruth
548e581dcb Clean up and FileCheck-ize a test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123153 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 02:53:54 +00:00
Chris Lattner
f86c75da4d fix typo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123148 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 02:33:34 +00:00
Chris Lattner
a806be66c1 another (more) aggressive attempt to bring llvm-gcc-i386-linux-selfhost
back to life.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123146 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 00:47:34 +00:00
Chris Lattner
d8408270f3 temporarily disable memset formation from memsets in an effort to restore buildbot stability.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123144 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-09 23:52:48 +00:00
Tobias Grosser
aa2be84356 Instcombine: Fix pattern where the sext did not dominate the icmp using it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123121 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-09 16:00:11 +00:00
Chris Lattner
d90a192279 Merge memsets followed by neighboring memsets and other stores into
larger memsets.  Among other things, this fixes rdar://8760394 and
allows us to handle "Example 2" from http://blog.regehr.org/archives/320,
compiling it into a single 4096-byte memset:

_mad_synth_mute:                        ## @mad_synth_mute
## BB#0:                                ## %entry
	pushq	%rax
	movl	$4096, %esi             ## imm = 0x1000
	callq	___bzero
	popq	%rax
	ret



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123089 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 21:19:19 +00:00
Chris Lattner
9fa11e94b5 fix an issue in IsPointerOffset that prevented us from recognizing that
P and P+1 are relative to the same base pointer.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123087 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 21:07:56 +00:00
Chris Lattner
06511264f8 enhance memcpyopt to merge a store and a subsequent
memset into a single larger memset.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123086 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 20:54:51 +00:00
Chris Lattner
355f5778aa merge two tests and filecheckify
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123082 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 20:27:22 +00:00
Chris Lattner
5d37370a6f When loop rotation happens, it is *very* common for the duplicated condbr
to be foldable into an uncond branch.  When this happens, we can make a
much simpler CFG for the loop, which is important for nested loop cases
where we want the outer loop to be aggressively optimized.

Handle this case more aggressively.  For example, previously on
phi-duplicate.ll we would get this:


define void @test(i32 %N, double* %G) nounwind ssp {
entry:
  %cmp1 = icmp slt i64 1, 1000
  br i1 %cmp1, label %bb.nph, label %for.end

bb.nph:                                           ; preds = %entry
  br label %for.body

for.body:                                         ; preds = %bb.nph, %for.cond
  %j.02 = phi i64 [ 1, %bb.nph ], [ %inc, %for.cond ]
  %arrayidx = getelementptr inbounds double* %G, i64 %j.02
  %tmp3 = load double* %arrayidx
  %sub = sub i64 %j.02, 1
  %arrayidx6 = getelementptr inbounds double* %G, i64 %sub
  %tmp7 = load double* %arrayidx6
  %add = fadd double %tmp3, %tmp7
  %arrayidx10 = getelementptr inbounds double* %G, i64 %j.02
  store double %add, double* %arrayidx10
  %inc = add nsw i64 %j.02, 1
  br label %for.cond

for.cond:                                         ; preds = %for.body
  %cmp = icmp slt i64 %inc, 1000
  br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge

for.cond.for.end_crit_edge:                       ; preds = %for.cond
  br label %for.end

for.end:                                          ; preds = %for.cond.for.end_crit_edge, %entry
  ret void
}

Now we get the much nicer:

define void @test(i32 %N, double* %G) nounwind ssp {
entry:
  br label %for.body

for.body:                                         ; preds = %entry, %for.body
  %j.01 = phi i64 [ 1, %entry ], [ %inc, %for.body ]
  %arrayidx = getelementptr inbounds double* %G, i64 %j.01
  %tmp3 = load double* %arrayidx
  %sub = sub i64 %j.01, 1
  %arrayidx6 = getelementptr inbounds double* %G, i64 %sub
  %tmp7 = load double* %arrayidx6
  %add = fadd double %tmp3, %tmp7
  %arrayidx10 = getelementptr inbounds double* %G, i64 %j.01
  store double %add, double* %arrayidx10
  %inc = add nsw i64 %j.01, 1
  %cmp = icmp slt i64 %inc, 1000
  br i1 %cmp, label %for.body, label %for.end

for.end:                                          ; preds = %for.body
  ret void
}

With all of these recent changes, we are now able to compile:

void foo(char *X) {
 for (int i = 0; i != 100; ++i) 
   for (int j = 0; j != 100; ++j)
     X[j+i*100] = 0;
}

into a single memset of 10000 bytes.  This series of changes
should also be helpful for other nested loop scenarios as well.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123079 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 19:59:06 +00:00
Chris Lattner
0e4a1543ab Three major changes:
1. Rip out LoopRotate's domfrontier updating code.  It isn't
   needed now that LICM doesn't use DF and it is super complex
   and gross.
2. Make DomTree updating code a lot simpler and faster.  The 
   old loop over all the blocks was just to find a block??
3. Change the code that inserts the new preheader to just use
   SplitCriticalEdge instead of doing an overcomplex 
   reimplementation of it.

No behavior change, except for the name of the inserted preheader.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123072 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 18:52:51 +00:00
Frits van Bommel
b686eb9186 Fix a bug in r123034 (trying to sext/zext non-integers) and clean up a little.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123061 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 10:51:36 +00:00
Chris Lattner
d9ec3572f3 Have loop-rotate simplify instructions (yay instsimplify!) as it clones
them into the loop preheader, eliminating silly instructions like
"icmp i32 0, 100" in fixed tripcount loops.  This also better exposes the 
bigger problem with loop rotate that I'd like to fix: once this has been
folded, the duplicated conditional branch *often* turns into an uncond branch.

Not aggressively handling this is pessimizing later loop optimizations 
somethin' fierce by making "dominates all exit blocks" checks fail.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123060 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08 08:24:46 +00:00
Tobias Grosser
46431d7a93 InstCombine: Match min/max hidden by sext/zext
X = sext x; x >s c ? X : C+1 --> X = sext x; X <s C+1 ? C+1 : X
X = sext x; x <s c ? X : C-1 --> X = sext x; X >s C-1 ? C-1 : X
X = zext x; x >u c ? X : C+1 --> X = zext x; X <u C+1 ? C+1 : X
X = zext x; x <u c ? X : C-1 --> X = zext x; X >u C-1 ? C-1 : X
X = sext x; x >u c ? X : C+1 --> X = sext x; X <u C+1 ? C+1 : X
X = sext x; x <u c ? X : C-1 --> X = sext x; X >u C-1 ? C-1 : X

Instead of calculating this with mixed types promote all to the
larger type. This enables scalar evolution to analyze this
expression. PR8866

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123034 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-07 21:33:14 +00:00
Benjamin Kramer
eaff66a895 Revert 122959, it needs more thought. Add it back to README.txt with additional notes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123030 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-07 20:42:20 +00:00
Benjamin Kramer
8143a84c46 InstCombine: Turn _chk functions into the "unsafe" variant if length and max langth are equal.
This happens when we take the (non-constant) length from a malloc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122961 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-06 14:22:52 +00:00
Benjamin Kramer
240d42d185 InstCombine: If we call llvm.objectsize on a malloc call we can replace it with the size passed to malloc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122959 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-06 13:11:05 +00:00
Benjamin Kramer
783a5c2b69 InstCombine: Teach llvm.objectsize folding to look through GEPs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122958 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-06 13:07:49 +00:00
Chris Lattner
8cd4efb6a5 implement constant folding support for an exotic constant expr:
ret i64 ptrtoint (i8* getelementptr ([1000 x i8]* @X, i64 1, i64 sub (i64 0, i64 ptrtoint ([1000 x i8]* @X to i64))) to i64)

to "ret i64 1000".  This allows us to correctly compute the trip count
on a loop in PR8883, which occurs with std::fill on a char array.  This
allows us to transform it into a memset with a constant size.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122950 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-06 06:19:46 +00:00
Chris Lattner
43b40a4620 fix an off-by-one bug that caused a crash analyzing
ashr's with huge shift amounts, PR8896


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122814 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-04 18:19:15 +00:00
Chris Lattner
e41d3c015c Teach loop-idiom to turn a loop containing a memset into a larger memset
when safe.

The testcase is basically this nested loop:
void foo(char *X) {
  for (int i = 0; i != 100; ++i) 
    for (int j = 0; j != 100; ++j)
      X[j+i*100] = 0;
}

which gets turned into a single memset now.  clang -O3 doesn't optimize
this yet though due to a phase ordering issue I haven't analyzed yet.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122806 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-04 07:46:33 +00:00
Chris Lattner
e508dd4c75 Duncan deftly points out that readnone functions aren't
invalidated by stores, so they can be handled as 'simple'
operations.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122785 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-03 23:38:13 +00:00
Chris Lattner
75637154c3 earlycse can do trivial with-a-block dead store
elimination as well.  This deletes 60 stores in 176.gcc
that largely come from bitfield code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122736 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-03 04:17:24 +00:00
Chris Lattner
ef87fc2e0a now that loads are in their own table, we can implement
store->load forwarding.  This allows EarlyCSE to zap 600 more
loads from 176.gcc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122732 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-03 03:46:34 +00:00
Chris Lattner
03d49e955e add a testcase for readonly call CSE
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122730 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-03 03:33:47 +00:00
Chris Lattner
8e7f0d70c7 Teach EarlyCSE to do trivial CSE of loads and read-only calls.
On 176.gcc, this catches 13090 loads and calls, and increases the
number of simple instructions CSE'd from 29658 to 36208.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122727 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-03 03:18:43 +00:00
Chris Lattner
91139ccd99 add DEBUG and -stats output to earlycse.
Teach it to CSE the rest of the non-side-effecting instructions.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122716 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 23:19:45 +00:00
Chris Lattner
cc9eab26b3 Enhance earlycse to do CSE of casts, instsimplify and die.
Add a testcase.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122715 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 23:04:14 +00:00
Chris Lattner
63f9c3c49a fix a miscompilation of tramp3d-v4: when forming a memcpy, we have to make
sure that the loop we're promoting into a memcpy doesn't mutate the input
of the memcpy.  Before we were just checking that the dest of the memcpy
wasn't mod/ref'd by the loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122712 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 21:14:18 +00:00
Chris Lattner
8e08e73f0e If a loop iterates exactly once (has backedge count = 0) then don't
mess with it.  We'd rather peel/unroll it than convert all of its 
stores into memsets.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122711 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 20:24:21 +00:00
Chris Lattner
62c50fdf69 enhance loop idiom recognition to scan *all* unconditionally executed
blocks in a loop, instead of just the header block.  This makes it more
aggressive, able to handle Duncan's Ada examples.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122704 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 19:01:03 +00:00
Duncan Sands
67fb341f8b Fix PR8702 by not having LoopSimplify claim to preserve LCSSA form. As described
in the PR, the pass could break LCSSA form when inserting preheaders.  It probably
would be easy enough to fix this, but since currently we always go into LCSSA form
after running this pass, doing so is not urgent.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122695 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 13:38:21 +00:00
Chris Lattner
cf078f2b20 Allow loop-idiom to run on multiple BB loops, but still only scan the loop
header for now for memset/memcpy opportunities.  It turns out that loop-rotate
is successfully rotating loops, but *DOESN'T MERGE THE BLOCKS*, turning "for 
loops" into 2 basic block loops that loop-idiom was ignoring.

With this fix, we form many *many* more memcpy and memsets than before, including
on the "history" loops in the viterbi benchmark, which look like this:

        for (j=0; j<MAX_history; ++j) {
          history_new[i][j+1] = history[2*i][j];
        }

Transforming these loops into memcpy's speeds up the viterbi benchmark from
11.98s to 3.55s on my machine.  Woo.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122685 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-02 07:58:36 +00:00