llvm-project/llvm/lib/Transforms
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
..
Hello Finegrainify namespacification 2004-01-09 06:12:26 +00:00
IPO Restore old inlining heuristic. As the comment indicates, this is a nasty 2004-03-15 06:38:14 +00:00
Instrumentation Initial support for edge profiling 2004-03-08 17:54:34 +00:00
Scalar Okay, so there is no reasonable way for tail duplication to update SSA form, 2004-03-16 23:29:09 +00:00
Utils This code was both incredibly complex and incredibly broken. Fix it. 2004-03-16 23:23:11 +00:00
ExprTypeConvert.cpp Punt if we see gigantic PHI nodes. This improves a huge interpreter loop 2004-03-16 19:52:53 +00:00
LevelRaise.cpp Adjust to the changed StructType interface. In particular, getElementTypes() is gone. 2004-02-09 04:37:31 +00:00
Makefile Added LLVM copyright notice to Makefiles. 2003-10-20 22:26:57 +00:00
TransformInternals.cpp Adjust to the changed StructType interface. In particular, getElementTypes() is gone. 2004-02-09 04:37:31 +00:00
TransformInternals.h Put all LLVM code into the llvm namespace, as per bug 109. 2003-11-11 22:41:34 +00:00