llvm-project/llvm/lib/Transforms/Scalar
Chris Lattner 95057f6ad1 Okay, so there is no reasonable way for tail duplication to update SSA form,
as it is making effectively arbitrary modifications to the CFG and we don't
have a domset/domfrontier implementations that can handle the dynamic updates.
Instead of having a bunch of code that doesn't actually work in practice,
just demote any potentially tricky values to the stack (causing the problem
to go away entirely).  Later invocations of mem2reg will rebuild SSA for us.

This fixes all of the major performance regressions with tail duplication
from LLVM 1.1.  For example, this loop:

---
int popcount(int x) {
  int result = 0;
  while (x != 0) {
    result = result + (x & 0x1);
    x = x >> 1;
  }
  return result;
}
---
Used to be compiled into:

int %popcount(int %X) {
entry:
	br label %loopentry

loopentry:		; preds = %entry, %no_exit
	%x.0 = phi int [ %X, %entry ], [ %tmp.9, %no_exit ]		; <int> [#uses=3]
	%result.1.0 = phi int [ 0, %entry ], [ %tmp.6, %no_exit ]		; <int> [#uses=2]
	%tmp.1 = seteq int %x.0, 0		; <bool> [#uses=1]
	br bool %tmp.1, label %loopexit, label %no_exit

no_exit:		; preds = %loopentry
	%tmp.4 = and int %x.0, 1		; <int> [#uses=1]
	%tmp.6 = add int %tmp.4, %result.1.0		; <int> [#uses=1]
	%tmp.9 = shr int %x.0, ubyte 1		; <int> [#uses=1]
	br label %loopentry

loopexit:		; preds = %loopentry
	ret int %result.1.0
}

And is now compiled into:

int %popcount(int %X) {
entry:
        br label %no_exit

no_exit:                ; preds = %entry, %no_exit
        %x.0.0 = phi int [ %X, %entry ], [ %tmp.9, %no_exit ]          ; <int> [#uses=2]
        %result.1.0.0 = phi int [ 0, %entry ], [ %tmp.6, %no_exit ]             ; <int> [#uses=1]
        %tmp.4 = and int %x.0.0, 1              ; <int> [#uses=1]
        %tmp.6 = add int %tmp.4, %result.1.0.0          ; <int> [#uses=2]
        %tmp.9 = shr int %x.0.0, ubyte 1                ; <int> [#uses=2]
        %tmp.1 = seteq int %tmp.9, 0            ; <bool> [#uses=1]
        br bool %tmp.1, label %loopexit, label %no_exit

loopexit:               ; preds = %no_exit
        ret int %tmp.6
}

llvm-svn: 12457
2004-03-16 23:29:09 +00:00
..
ADCE.cpp Fix the count of the number of instructions removed 2004-02-01 05:15:07 +00:00
BasicBlockPlacement.cpp Remove obsolete comment. Unreachable blocks will automatically be left at the 2004-02-11 05:20:50 +00:00
ConstantProp.cpp Add header file I accidentally removed in teh shuffle 2004-01-12 19:15:20 +00:00
CorrelatedExprs.cpp Remove use of the ConstantHandling interfaces 2004-01-12 19:12:50 +00:00
DCE.cpp Finegrainify namespacification 2004-01-09 06:02:20 +00:00
DecomposeMultiDimRefs.cpp Finegrainify namespacification 2004-01-09 06:02:20 +00:00
GCSE.cpp Add counters for the number of calls elimianted 2004-03-15 05:46:59 +00:00
IndVarSimplify.cpp Improve encapsulation in the Loop and LoopInfo classes by eliminating the 2004-01-08 00:09:44 +00:00
InstructionCombining.cpp Add some debugging output 2004-03-13 23:54:27 +00:00
LICM.cpp Implement LICM of calls in simple cases. This is sufficient to move around 2004-03-15 04:11:30 +00:00
LoopSimplify.cpp Fix a regression from this patch: 2004-03-16 06:00:15 +00:00
LowerAllocations.cpp Don't emit things like malloc(16*1). Allocation instructions are fixed arity now. 2004-03-03 01:40:53 +00:00
LowerInvoke.cpp Disable tail duplication in a case that breaks on Olden/tsp 2004-03-01 01:12:13 +00:00
LowerSwitch.cpp Do not create empty basic blocks when the lowerswitch pass expects blocks to 2004-03-14 04:14:31 +00:00
Makefile Added LLVM copyright notice to Makefiles. 2003-10-20 22:26:57 +00:00
Mem2Reg.cpp Finegrainify namespacification 2004-01-09 06:02:20 +00:00
PRE.cpp Finegrainify namespacification 2004-01-09 06:02:20 +00:00
PiNodeInsertion.cpp Finegrainify namespacification 2004-01-09 06:02:20 +00:00
Reassociate.cpp Finegrainify namespacification 2004-01-09 06:02:20 +00:00
SCCP.cpp Do not try to optimize PHI nodes with incredibly high degree. This reduces SCCP 2004-03-16 19:49:59 +00:00
ScalarReplAggregates.cpp Finegrainify namespacification 2003-12-02 17:43:55 +00:00
SimplifyCFG.cpp Finegrainify namespacification 2004-01-09 06:02:20 +00:00
SymbolStripping.cpp Update obsolete comments 2004-01-10 21:36:49 +00:00
TailDuplication.cpp Okay, so there is no reasonable way for tail duplication to update SSA form, 2004-03-16 23:29:09 +00:00
TailRecursionElimination.cpp Adjust to the new BasicBlock ctor, which requires a function parameter 2004-02-04 03:58:28 +00:00