llvm-6502/lib/Transforms/Scalar
Evan Cheng ae16d6b972 SimplifyCFG has stopped duplicating returns into predecessors to canonicalize IR
to have single return block (at least getting there) for optimizations. This
is general goodness but it would prevent some tailcall optimizations.
One specific case is code like this:
int f1(void);
int f2(void);
int f3(void);
int f4(void);
int f5(void);
int f6(void);
int foo(int x) {
  switch(x) {
  case 1: return f1();
  case 2: return f2();
  case 3: return f3();
  case 4: return f4();
  case 5: return f5();
  case 6: return f6();
  }
}

=>
LBB0_2:                                 ## %sw.bb
  callq   _f1
  popq    %rbp
  ret
LBB0_3:                                 ## %sw.bb1
  callq   _f2
  popq    %rbp
  ret
LBB0_4:                                 ## %sw.bb3
  callq   _f3
  popq    %rbp
  ret

This patch teaches codegenprep to duplicate returns when the return value
is a phi and where the phi operands are produced by tail calls followed by
an unconditional branch:

sw.bb7:                                           ; preds = %entry
  %call8 = tail call i32 @f5() nounwind
  br label %return
sw.bb9:                                           ; preds = %entry
  %call10 = tail call i32 @f6() nounwind
  br label %return
return:
  %retval.0 = phi i32 [ %call10, %sw.bb9 ], [ %call8, %sw.bb7 ], ... [ 0, %entry ]
  ret i32 %retval.0

This allows codegen to generate better code like this:

LBB0_2:                                 ## %sw.bb
        jmp     _f1                     ## TAILCALL
LBB0_3:                                 ## %sw.bb1
        jmp     _f2                     ## TAILCALL
LBB0_4:                                 ## %sw.bb3
        jmp     _f3                     ## TAILCALL

rdar://9147433


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127953 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-19 17:17:39 +00:00
..
ADCE.cpp Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which 2010-10-19 17:21:58 +00:00
BasicBlockPlacement.cpp Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which 2010-10-19 17:21:58 +00:00
CMakeLists.txt Unbreak CMake build. 2011-02-28 23:56:33 +00:00
CodeGenPrepare.cpp SimplifyCFG has stopped duplicating returns into predecessors to canonicalize IR 2011-03-19 17:17:39 +00:00
ConstantProp.cpp Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which 2010-10-19 17:21:58 +00:00
CorrelatedValuePropagation.cpp Fix PR8790, another instance where unreachable code can cause instruction simplification to fail, 2010-12-15 00:55:35 +00:00
DCE.cpp Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which 2010-10-19 17:21:58 +00:00
DeadStoreElimination.cpp Give GetUnderlyingObject a TargetData, to keep it in sync 2011-01-24 18:53:32 +00:00
EarlyCSE.cpp Duncan deftly points out that readnone functions aren't 2011-01-03 23:38:13 +00:00
GVN.cpp Give GetUnderlyingObject a TargetData, to keep it in sync 2011-01-24 18:53:32 +00:00
IndVarSimplify.cpp Remove TargetData and ValueTracking includes. I didn't mean for them to sneak in my last checkin. 2011-03-18 00:36:39 +00:00
JumpThreading.cpp prevent jump threading from merging blocks when their address is 2011-02-18 04:43:06 +00:00
LICM.cpp While sinking an instruction, do not lose llvm.dbg.value intrinsic. 2011-03-08 03:06:19 +00:00
LoopDeletion.cpp Make LoopDeletion work on loops with multiple edges, as long as the incoming 2011-02-22 22:25:39 +00:00
LoopIdiomRecognize.cpp Added SCEV::NoWrapFlags to manage unsigned, signed, and self wrap 2011-03-14 16:50:06 +00:00
LoopInstSimplify.cpp LoopInstSimplify preserves ScalarEvolution. 2011-02-11 06:08:25 +00:00
LoopRotation.cpp Do not hoist @llvm.dbg.value. Here, @llvm.dbg.value is "referring" a value that is modified inside loop. 2011-02-14 23:03:23 +00:00
LoopStrengthReduce.cpp Added SCEV::NoWrapFlags to manage unsigned, signed, and self wrap 2011-03-14 16:50:06 +00:00
LoopUnrollPass.cpp Remove dead code, that I apparently wrote a while back. We seem to be doing well enough 2011-01-17 22:39:54 +00:00
LoopUnswitch.cpp Make LoopUnswitch preserve ScalarEvolution by just forgetting everything about 2011-02-11 06:08:28 +00:00
LowerAtomic.cpp Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which 2010-10-19 17:21:58 +00:00
Makefile make -fno-rtti the default unless a directory builds with REQUIRES_RTTI. 2010-01-24 20:43:08 +00:00
MemCpyOptimizer.cpp Spelling fix: consequtive -> consecutive. 2011-02-15 09:23:02 +00:00
Reassociate.cpp RecursivelyDeleteTriviallyDeadInstructions only needs a 2011-03-10 20:57:44 +00:00
Reg2Mem.cpp Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which 2010-10-19 17:21:58 +00:00
Scalar.cpp Delete the GEPSplitter experiment. 2011-02-28 19:47:47 +00:00
ScalarReplAggregates.cpp Fix a comment. 2011-03-16 08:13:42 +00:00
SCCP.cpp SCCP doesn't actually preserve the CFG. It will delete and insert terminator 2011-01-21 08:38:09 +00:00
SimplifyCFGPass.cpp Get rid of static constructors for pass registration. Instead, every pass exposes an initializeMyPassFunction(), which 2010-10-19 17:21:58 +00:00
SimplifyLibCalls.cpp Preserve line number information while simplifying libcalls. 2011-03-09 21:27:52 +00:00
Sink.cpp Add helper functions for computing the Location of load, store, 2010-11-11 21:50:19 +00:00
TailDuplication.cpp Replace calls to ConstantFoldInstruction with calls to SimplifyInstruction 2010-11-23 20:26:33 +00:00
TailRecursionElimination.cpp Unbreak the MSVC build. 2011-01-29 20:06:16 +00:00