Commit Graph

1085 Commits

Author SHA1 Message Date
Chris Lattner
95a959dc1a Teach instcombine to increase the alignment of memset/memcpy/memmove when
the pointer is known to come from either a global variable, alloca or
malloc.  This allows us to compile this:

  P = malloc(28);
  memset(P, 0, 28);

into explicit stores on PPC instead of a memset call.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26577 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-06 20:18:44 +00:00
Chris Lattner
220b0cf3e4 Make vector narrowing more effective, implementing
Transforms/InstCombine/vec_narrow.ll.  This add support for narrowing
extract_element(insertelement) also.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26538 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-05 00:22:33 +00:00
Chris Lattner
e5022fe4cd Add factoring of multiplications, e.g. turning A*A+A*B into A*(A+B).
Testcase here: Transforms/Reassociate/mulfactor.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26524 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-04 09:31:13 +00:00
Chris Lattner
ab51f3fa96 Canonicalize (X+C1)*C2 -> X*C2+C1*C2
This implements Transforms/InstCombine/add.ll:test31


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26519 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-04 06:04:02 +00:00
Chris Lattner
21959390c1 Change this to work with renamed intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26484 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-03 01:34:17 +00:00
Chris Lattner
db3f873bd8 Generalize the REM folding code to handle another case Nick Lewycky
pointed out: realize the AND can provide factors and look through Casts.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26469 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-02 06:50:58 +00:00
Chris Lattner
06e1e25368 Fix a regression in a patch from a couple of days ago. This fixes
Transforms/InstCombine/2006-02-28-Crash.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26427 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 19:47:20 +00:00
Chris Lattner
9794392781 Implement rem.ll:test[7-9] and PR712
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26415 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 05:49:21 +00:00
Chris Lattner
6c9951b0da Simplify some code now that the RHS of a rem can't be 0
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26413 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 05:40:55 +00:00
Chris Lattner
19ccd5c757 Rearrange some code, fold "rem X, 0", implementing rem.ll:test6
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26411 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 05:30:45 +00:00
Chris Lattner
3e88a4d700 Merge two almost-identical pieces of code.
Make this code more powerful by using ComputeMaskedBits instead of looking
for an AND operand.  This lets us fold this:

int %test23(int %a) {
        %tmp.1 = and int %a, 1
        %tmp.2 = seteq int %tmp.1, 0
        %tmp.3 = cast bool %tmp.2 to int  ;; xor tmp1, 1
        ret int %tmp.3
}

into: xor (and a, 1), 1


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26396 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-27 02:38:23 +00:00
Chris Lattner
26ab9a9218 Fold (A^B) == A -> B == 0
and  (A-B) == A  ->  B == 0


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26394 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-27 01:44:11 +00:00
Chris Lattner
02bd1b3e94 Fold (X|C1)^C2 -> X^(C1|C2) when possible. This implements
InstCombine/or.ll:test23.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26385 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-26 19:57:54 +00:00
Chris Lattner
97f37a439c Fix a problem that Nate noticed that boils down to an over conservative check
in the code that does "select C, (X+Y), (X-Y) --> (X+(select C, Y, (-Y)))".
We now compile this loop:

LBB1_1: ; no_exit
        add r6, r2, r3
        subf r3, r2, r3
        cmpwi cr0, r2, 0
        addi r7, r5, 4
        lwz r2, 0(r5)
        addi r4, r4, 1
        blt cr0, LBB1_4 ; no_exit
LBB1_3: ; no_exit
        mr r3, r6
LBB1_4: ; no_exit
        cmpwi cr0, r4, 16
        mr r5, r7
        bne cr0, LBB1_1 ; no_exit

into this instead:

LBB1_1: ; no_exit
        srawi r6, r2, 31
        add r2, r2, r6
        xor r6, r2, r6
        addi r7, r5, 4
        lwz r2, 0(r5)
        addi r4, r4, 1
        add r3, r3, r6
        cmpwi cr0, r4, 16
        mr r5, r7
        bne cr0, LBB1_1 ; no_exit


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26356 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-24 18:05:58 +00:00
Chris Lattner
f8bf116f80 Fix Regression/Transforms/LoopUnswitch/2006-02-22-UnswitchCrash.ll, which
caused SPASS to fail building last night.

We can't trivially unswitch a loop if the exit block has phi nodes in it,
because we don't know which predecessor to use.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26320 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-22 23:55:00 +00:00
Chris Lattner
bd28e3f8ef Add some comments, simplify some code, and fix a bug that caused rewriting
to rewrite with the wrong value.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26311 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-22 06:37:14 +00:00
Chris Lattner
a6fc94b71e improved support for branch folding, still not enabled.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26289 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 07:57:38 +00:00
Jeff Cohen
bce4805d6f Fix bugs identified by VC++.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26287 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 03:20:33 +00:00
Chris Lattner
db41024a85 Implement deletion of dead blocks, currently disabled.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26285 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 02:42:34 +00:00
Chris Lattner
caf4893536 a previous patch completely disabled trivial unswitching, this fixees it.
Thanks to nate for pointing this out :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26280 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 01:32:04 +00:00
Chris Lattner
f4412d890d initial trivial support for folding branches that have now-constant destinations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26279 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 01:27:45 +00:00
Chris Lattner
25cae0fd1c When unswitching a loop, make sure to update loop info with exit blocks in
the right loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26277 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 00:55:32 +00:00
Chris Lattner
0017d480cc Fix loops where the header has an exit, fixing a loop-unswitch crash on crafty
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26258 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-17 06:39:56 +00:00
Chris Lattner
52221f7b16 start of some new simplification code, not thoroughly tested, use at your own
risk :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26248 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-17 00:31:07 +00:00
Nate Begeman
368e18d56a Rework the SelectionDAG-based implementations of SimplifyDemandedBits
and ComputeMaskedBits to match the new improved versions in instcombine.
Tested against all of multisource/benchmarks on ppc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26238 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 21:11:51 +00:00
Chris Lattner
10cd9bbde7 Change SplitBlock to increment a BasicBlock::iterator, not an Instruction*. Apparently they do different things :)
This fixes a testcase that nate reduced from spass.

Also included are a couple minor code changes that don't affect the generated
code at all.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26235 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 19:36:22 +00:00
Jeff Cohen
21c107ab0f Fix VC++ warning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26228 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 04:07:37 +00:00
Chris Lattner
f17c42d409 fix a bug where we unswitched the wrong way
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26225 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 01:24:41 +00:00
Chris Lattner
a48654ef23 Implement trivial unswitching for switch stmts. This allows us to trivial
unswitch this loop on 2 before sweating to unswitch on 1/3.

void test4(int N, int i, int C, int*P, int*Q) {
  int j;
  for (j = 0; j < N; ++j) {
    switch (C) {                // general unswitching.
    default: P[i+j] = 0; break;
    case 1: Q[i+j] = 0; break;
    case 3: P[i+j] = Q[i+j]; break;
    case 2: break;              //  TRIVIAL UNSWITCH on C==2
    }
  }
}


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26223 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 22:52:05 +00:00
Chris Lattner
4e1323969c make "trivial" unswitching significantly more general. It can now handle
this for example:

  for (j = 0; j < N; ++j) {     // trivial unswitch
    if (C)
      P[i+j] = 0;
  }

turning it into the obvious code without bothering to duplicate an empty loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26220 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 22:03:36 +00:00
Chris Lattner
3fdde110eb Checking the wrong value. This caused us to emit silly code like
Y = seteq bool X, true
instead of just using X :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26215 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 19:05:52 +00:00
Chris Lattner
6d9d13d2e4 more refactoring, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26194 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 01:44:42 +00:00
Chris Lattner
fed5d9dbd3 pull some code out into a function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26191 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 00:07:43 +00:00
Chris Lattner
3dd4c402de Use statistics to keep track of what flavors of loops we are unswitching
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26157 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-14 01:01:41 +00:00
Chris Lattner
2082ad9b41 Implement Instcombine/and.ll:test34
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26155 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-13 23:07:23 +00:00
Chris Lattner
f345fe4d9a If any of the sign extended bits are demanded, the input sign bit is demanded
for a sign extension.

This fixes InstCombine/2006-02-13-DemandedMiscompile.ll and Ptrdist/bc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26152 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-13 22:41:07 +00:00
Chris Lattner
c15637bafc Be careful not to request or look at bits shifted in from outside the size
of the input.  This fixes the mediabench/gsm/toast failure last night.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26138 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-13 06:09:08 +00:00
Chris Lattner
8d6bbdbbcb remove some more dead special case code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26135 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-12 08:07:37 +00:00
Chris Lattner
f8c36f502b Eliminate special case hacks that are superceded by general purpose hacks
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26134 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-12 08:02:11 +00:00
Chris Lattner
bf5d8a8270 Three changes:
1. Teach GetConstantInType to handle boolean constants.
2. Teach instcombine to fold (compare X, CST) when X has known 0/1 bits.
   Testcase here: set.ll:test22
3. Improve the "(X >> c1) & C2 == 0" folding code to allow a noop cast
   between the shift and and.  More aggressive bitfolding for other reasons
   was turning signed shr's into unsigned shr's, leaving the noop cast in
   the way.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26131 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-12 02:07:56 +00:00
Chris Lattner
255d8919b6 Port the recent innovations in ComputeMaskedBits to SimplifyDemandedBits.
This allows us to simplify on conditions where bits are not known, but they
are not demanded either!  This also fixes a couple of bugs in
ComputeMaskedBits that were exposed during this work.

In the future, swaths of instcombine should be removed, as this code
subsumes a bunch of ad-hockery.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26122 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 09:31:47 +00:00
Chris Lattner
c23580969f implement unswitching of loops with switch stmts and selects in them
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26114 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 00:43:37 +00:00
Chris Lattner
e825593bf2 Update PHI nodes in successors of exit blocks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26113 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 23:26:14 +00:00
Chris Lattner
b2bc315eac Reform the unswitching code in terms of edge splitting, not block splitting.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26112 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 23:16:39 +00:00
Chris Lattner
81be2e961b Fix a case where UnswitchTrivialCondition broke critical edges with
phi's in the successors


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26108 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 19:08:15 +00:00
Chris Lattner
708e1a5c9c add some notes, move some code around. Implement unswitching of loops
with branches on partially invariant computations.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26104 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 02:30:37 +00:00
Chris Lattner
dd3ee6d086 Move code around to be more logical, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26103 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 02:01:22 +00:00
Chris Lattner
4d1ca946ea When unswitching a trivial loop, do admit we are doing it! :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26102 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 01:36:35 +00:00
Chris Lattner
4c41d49a92 Implement unconditional unswitching of 'trivial' loops, those loops that contain
branches in their entry block that control whether or not the loop is a noop or not.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26101 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 01:24:09 +00:00
Chris Lattner
f4f5f4e56f Simplify control flow a bit, note that unswitch preserves canonical loop form
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26098 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-09 22:15:42 +00:00