Commit Graph

84 Commits

Author SHA1 Message Date
Chris Lattner
7e1ff8d2d9 remove debugging code :-/
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23392 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-19 23:50:15 +00:00
Chris Lattner
eaba3a194c Implement SimplifyCFG/branch-phi-thread.ll, the most trivial case of threading
control across branches with determined outcomes.  More generality to follow.
This triggers a couple thousand times in specint.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23391 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-19 23:49:37 +00:00
Chris Lattner
6306d07aa8 Fix Transforms/SimplifyCFG/2005-08-03-PHIFactorCrash.ll, a problem that
occurred while bugpointing another testcase


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22621 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 17:59:45 +00:00
Chris Lattner
1aad921c18 Finally, add the required constraint checks to fix Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll
the right way


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22615 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 00:59:12 +00:00
Chris Lattner
dc88dbeafa Simplify some code, add the correct pred checks
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22613 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 00:38:27 +00:00
Chris Lattner
3b3efc7797 Refactor code out of PropagatePredecessorsForPHIs, turning it into a pure function with no side-effects
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22612 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 00:29:26 +00:00
Chris Lattner
d423b8b6ca use splice instead of remove/insert to avoid some symtab operations
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22611 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 00:23:42 +00:00
Chris Lattner
2bdcb56146 move two functions up in the file, use SafeToMergeTerminators to eliminate
some duplicated code


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22610 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 00:19:45 +00:00
Chris Lattner
7e66348cba Rip some code out of the main SimplifyCFG function into a subfunction and
call it from the only place it is live.  No functionality changes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22609 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 00:11:16 +00:00
Chris Lattner
17de414965 Disable this patch:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20050801/027345.html

This breaks real programs and only fixes an obscure regression testcase.  A
real fix is in development.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22606 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 23:31:38 +00:00
Chris Lattner
f5e982daa8 Change a place to use an arbitrary value instead of null, when possible
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22605 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 23:29:23 +00:00
Chris Lattner
1593ac259d This code was very close, but not quite right. It did not take into
consideration the case where a reference in an unreachable block could
occur.  This fixes Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll,
something I ran into while bugpoint'ing another pass.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22584 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 03:24:05 +00:00
Chris Lattner
0289929c62 Don't crash on: X = phi (X, X).
This fixes PR584 and Transforms/SimplifyCFG/2005-06-16-PHICrash.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22232 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-17 01:45:53 +00:00
Chris Lattner
42eb7524ef Fix Transforms/SimplifyCFG/switch-simplify-crash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22158 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-20 22:19:54 +00:00
Chris Lattner
16d0db2da8 Make sure to preserve the calling convention when changing an invoke into
a call.  This fixes Prolangs-C++/deriv2, kimwitu++, and Misc-C++/bigfib
on X86 with -enable-x86-fastcc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22023 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-14 12:21:56 +00:00
Misha Brukman
fd93908ae8 Remove trailing whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21427 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-21 23:48:37 +00:00
Chris Lattner
bf5d4fb7d8 Teach simplifycfg that setcc is cheap and non-trapping, so that it can
convert this:

        %tmp.1 = seteq int %i, 0                ; <bool> [#uses=1]
        br bool %tmp.1, label %shortcirc_done, label %shortcirc_next

shortcirc_next:         ; preds = %entry
        %tmp.4 = seteq int %j, 0                ; <bool> [#uses=1]
        br label %shortcirc_done

shortcirc_done:         ; preds = %shortcirc_next, %entry
        %shortcirc_val = phi bool [ %tmp.4, %shortcirc_next ], [ true, %entry ]         ; <bool> [#uses=1]

to this:
        %tmp.1 = seteq int %i, 0                ; <bool> [#uses=1]
        %tmp.4 = seteq int %j, 0                ; <bool> [#uses=1]
        %shortcirc_val = select bool %tmp.1, bool true, bool %tmp.4             ; <bool> [#uses=1]

... which is later simplified by instcombine into an or.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21388 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-21 05:31:13 +00:00
Chris Lattner
151c80be81 Get rid of this for_each loop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21253 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-12 18:51:33 +00:00
Chris Lattner
da895d6337 Fix spelling, patch contributed by Gabor Greif!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20343 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-27 06:18:25 +00:00
Chris Lattner
be54dcc8a9 remove extraneous cast
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20334 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-26 18:33:28 +00:00
Chris Lattner
623369ac56 Implement Transforms/SimplifyCFG/switch_thread.ll
This does a simple form of "jump threading", which eliminates CFG edges that
are provably dead.  This triggers 90 times in the external tests, and
eliminating CFG edges is always always a good thing! :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20300 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-24 06:17:52 +00:00
Chris Lattner
378805969e switchinst ctor now takes a hint for the number of cases that it will have.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19898 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-29 00:38:26 +00:00
Chris Lattner
13b2f764c0 Implement SimplifyCFG/DeadSetCC.ll
SimplifyCFG is one of those passes that we use for final cleanup: it should
not rely on other passes to clean up its garbage.  This fixes the "why are
trivially dead setcc's in the output of gccas" problem.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19212 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-01 16:02:12 +00:00
Chris Lattner
7613437db9 Fix Regression/Transforms/SimplifyCFG/2004-12-10-SimplifyCFGCrash.ll,
and the failure on make_dparser last night.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18766 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-10 17:42:31 +00:00
Chris Lattner
0f535c6fa8 Squelch warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18381 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-30 07:47:34 +00:00
Chris Lattner
6f9e571529 Alkis noticed that this variable is dead. Thanks!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18369 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-30 04:01:44 +00:00
Chris Lattner
37dc938bbe If we have something like this:
if (x) {
    code
    ...
  } else {
    code
    ...
  }

Turn it into:

  code
  if (x) {
    ...
  } else {
    ...
  }

This reduces code size and in some common cases allows us to completely
eliminate the conditional.  This turns several if/then/else blocks in loops
into straightline code in 179.art, turning the loops into single basic blocks
(good for modsched even!).

Maybe now brg will leave me alone ;-)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18366 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-30 00:29:14 +00:00
Chris Lattner
bfd3e52701 Do not compute the predecessor list for a block unless we need it.
This speeds up simplifycfg on this program, from 44.87s to 0.29s (with
a profiled build):

 #define CL0(a) case a: goto c;
 #define CL1(a) CL0(a##0) CL0(a##1) CL0(a##2) CL0(a##3) CL0(a##4) CL0(a##5) \
 CL0(a##6) CL0(a##7) CL0(a##8) CL0(a##9)
 #define CL2(a) CL1(a##0) CL1(a##1) CL1(a##2) CL1(a##3) CL1(a##4) CL1(a##5) \
 CL1(a##6) CL1(a##7) CL1(a##8) CL1(a##9)
 #define CL3(a) CL2(a##0) CL2(a##1) CL2(a##2) CL2(a##3) CL2(a##4) CL2(a##5) \
 CL2(a##6) CL2(a##7) CL2(a##8) CL2(a##9)
 #define CL4(a) CL3(a##0) CL3(a##1) CL3(a##2) CL3(a##3) CL3(a##4) CL3(a##5) \
 CL3(a##6) CL3(a##7) CL3(a##8) CL3(a##9)

 void f();

 void a() {
     int b;
  c: switch (b) {
         CL4(1)
     }
 }

This testcase is contrived to expose N^2 behavior, but this patch should speedup
simplifycfg on any programs that use large switch statements.  This testcase
comes from GCC PR17895.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17389 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-01 06:53:58 +00:00
Reid Spencer
4e073a871b Eliminate compilation warning on uninitialized variable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17163 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-22 16:10:39 +00:00
Chris Lattner
698f96f7c8 Simplify code by deleting instructions that preceed unreachable instructions.
Simplify code by simplifying terminators that branch to blocks that start
with an unreachable instruction.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17116 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-18 04:07:22 +00:00
Chris Lattner
9c07866ef8 When converting phi nodes into select instructions, we shouldn't promote PHI
nodes unless we KNOW that we are able to promote all of them.

This fixes: test/Regression/Transforms/SimplifyCFG/PhiNoEliminate.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16973 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-14 05:13:36 +00:00
Chris Lattner
0ed7f42c1b Do not insert trivially dead select instructions, which allows us to
potentially fold more in one pass.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16583 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-29 05:43:32 +00:00
Reid Spencer
2da5c3dda6 Convert code to compile with vc7.1.
Patch contributed by Paolo Invernizzi. Thanks Paolo!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16368 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-15 17:06:42 +00:00
Alkis Evlogimenos
20aa474f8f Fixes to make LLVM compile with vc7.1.
Patch contributed by Paolo Invernizzi!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16152 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-03 18:19:51 +00:00
Reid Spencer
551ccae044 Changes For Bug 352
Move include/Config and include/Support into include/llvm/Config,
include/llvm/ADT and include/llvm/Support. From here on out, all LLVM
public header files must be under include/llvm/.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16137 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-01 22:55:40 +00:00
Brian Gaeke
7848e68c16 These files don't need to include <iostream> since they include "Support/Debug.h".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15089 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-21 20:50:33 +00:00
Chris Lattner
af17b1df84 Implement SimplifyCFG/BrUnwind.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15022 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-20 01:17:38 +00:00
Reid Spencer
460f16c625 bug 122:
- Minimize redundant isa<GlobalValue> usage


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14948 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:32:14 +00:00
Chris Lattner
30b4344767 Progress on PR341
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14840 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 02:06:12 +00:00
Reid Spencer
954da37bb4 Add #include <iostream> since Value.h does not #include it any more.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14622 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-04 12:19:56 +00:00
Chris Lattner
2636c1be17 *FINALLY* Fix a really nasty nondeterministic bug that has been haunting us
since May 1st.  In this code, the pred iterator was being invalidated sometimes
causing the wrong entries to be added to PHI nodes.

The fix for this is to defererence and safe the *PI value before we hack on
branch instructions, which changes use/def chains, which SOMETIMES invalidates
the iterator.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14278 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-21 07:19:01 +00:00
Chris Lattner
218a8223e6 Add some DEBUG output to the simplifycfg routines
Fix another non-deterministic behavior, this one should actually speed up the
code though as it was doing silly things.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14258 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-20 01:13:18 +00:00
Chris Lattner
1654cff8e8 Do not sort by the address of LLVM ConstantInt* objects. This produces
nondeterministic results that depend on where these objects land in memory.
Instead, sort by the value of the constant, which is stable.

Before this patch, the -simplifycfg pass run from two different compilers
could cause different code to be generated, though it was semantically the
same:

@@ -12258,8 +12258,8 @@
        %s_addr.1 = phi sbyte* [ %s, %entry ], [ %inc.0, %no_exit ]             ; <sbyte*> [#uses=5]
        %tmp.1 = load sbyte* %s_addr.1          ; <sbyte> [#uses=1]
        switch sbyte %tmp.1, label %no_exit [
-                sbyte 0, label %loopexit
                 sbyte 46, label %loopexit
+                sbyte 0, label %loopexit
        ]

We need to stomp all of this stuff out.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14243 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 07:02:14 +00:00
Chris Lattner
bdcc0b8c55 Do not clone arbitrary condition instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13316 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-02 05:19:36 +00:00
Chris Lattner
12fe2b1b82 Do not infinitely "unroll" single BB loops.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13315 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-02 05:02:03 +00:00
Chris Lattner
a1f79fb08b Dont' merge terminators that are needed to select PHI node values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13312 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-02 01:00:44 +00:00
Chris Lattner
e67fa05036 Implement SimplifyCFG/branch-cond-merge.ll
Turning "if (A < B && B < C)" into "if (A < B & B < C)"


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13311 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 23:35:43 +00:00
Chris Lattner
951fdb9764 Fix my missing parens
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13307 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 22:41:51 +00:00
Chris Lattner
92da2c2053 Implement SimplifyCFG/branch-cond-prop.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13306 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 22:36:37 +00:00
Chris Lattner
570751c2a7 Fold code like:
if (C)
    V1 |= V2;

into:
  Vx = V1 | V2;
  V1 = select C, V1, Vx

when the expression can be evaluated unconditionally and is *cheap* to
execute.  This limited form of if conversion is quite handy in lots of cases.
For example, it turns this testcase into straight-line code:

int in0 ; int in1 ; int in2 ; int in3 ;
int in4 ; int in5 ; int in6 ; int in7 ;
int in8 ; int in9 ; int in10; int in11;
int in12; int in13; int in14; int in15;
long output;

void mux(void) {
  output =
      (in0   ?  0x00000001 : 0) | (in1   ?  0x00000002 : 0) |
      (in2   ?  0x00000004 : 0) | (in3   ?  0x00000008 : 0) |
      (in4   ?  0x00000010 : 0) | (in5   ?  0x00000020 : 0) |
      (in6   ?  0x00000040 : 0) | (in7   ?  0x00000080 : 0) |
      (in8   ?  0x00000100 : 0) | (in9   ?  0x00000200 : 0) |
      (in10  ?  0x00000400 : 0) | (in11  ?  0x00000800 : 0) |
      (in12  ?  0x00001000 : 0) | (in13  ?  0x00002000 : 0) |
      (in14  ?  0x00004000 : 0) | (in15  ?  0x00008000 : 0) ;
}


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12798 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-09 22:50:22 +00:00