1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
llvm-mirror/test/Transforms/SimplifyCFG
James Molloy 17b2066590 [SimplifyCFG] Merge conditional stores
We can often end up with conditional stores that cannot be speculated. They can come from fairly simple, idiomatic code:

  if (c & flag1)
    *a = x;
  if (c & flag2)
    *a = y;
  ...

There is no dominating or post-dominating store to a, so it is not legal to move the store unconditionally to the end of the sequence and cache the intermediate result in a register, as we would like to.

It is, however, legal to merge the stores together and do the store once:

  tmp = undef;
  if (c & flag1)
    tmp = x;
  if (c & flag2)
    tmp = y;
  if (c & flag1 || c & flag2)
    *a = tmp;

The real power in this optimization is that it allows arbitrary length ladders such as these to be completely and trivially if-converted. The typical code I'd expect this to trigger on often uses binary-AND with constants as the condition (as in the above example), which means the ending condition can simply be truncated into a single binary-AND too: 'if (c & (flag1|flag2))'. As in the general case there are bitwise operators here, the ladder can often be optimized further too.

This optimization involves potentially increasing register pressure. Even in the simplest case, the lifetime of the first predicate is extended. This can be elided in some cases such as using binary-AND on constants, but not in the general case. Threading 'tmp' through all branches can also increase register pressure.

The optimization as in this patch is enabled by default but kept in a very conservative mode. It will only optimize if it thinks the resultant code should be if-convertable, and additionally if it can thread 'tmp' through at least one existing PHI, so it will only ever in the worst case create one more PHI and extend the lifetime of a predicate.

This doesn't trigger much in LNT, unfortunately, but it does trigger in a big way in a third party test suite.

llvm-svn: 252051
2015-11-04 15:28:04 +00:00
..
AArch64 [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
AMDGPU AMDGPU: Fix some places missed in rename 2015-06-19 17:39:03 +00:00
PowerPC [CodeGenPrepare] Removed duplicate logic. SimplifyCFG already knows how to speculate calls to cttz/ctlz. 2015-02-13 14:15:48 +00:00
SPARC
X86 Changed renaming of local symbols by inserting a dot vefore the numeric suffix. 2015-05-12 16:47:30 +00:00
2002-05-21-PHIElimination.ll
2002-09-24-PHIAssertion.ll
2003-03-07-DominateProblem.ll
2003-08-05-InvokeCrash.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
2003-08-17-BranchFold.ll
2003-08-17-BranchFoldOrdering.ll
2003-08-17-FoldSwitch-dbg.ll [opaque pointer type] Add textual IR support for explicit type parameter to gep operator 2015-03-13 18:20:45 +00:00
2003-08-17-FoldSwitch.ll
2004-12-10-SimplifyCFGCrash.ll
2005-06-16-PHICrash.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2005-08-01-PHIUpdateFail.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
2005-10-02-InvokeSimplify.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
2005-12-03-IncorrectPHIFold.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2006-02-17-InfiniteUnroll.ll
2006-06-12-InfLoop.ll
2006-08-03-Crash.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2006-10-19-UncondDiv.ll
2006-12-08-Ptr-ICmp-Branch.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2007-11-22-InvokeNoUnwind.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
2007-12-21-Crash.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
2008-01-02-hoist-fp-add.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2008-05-16-PHIBlockMerge.ll
2008-07-13-InfLoopMiscompile.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
2008-09-08-MultiplePred.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2008-09-17-SpeculativeHoist.ll
2008-10-03-SpeculativelyExecuteBeforePHI.ll
2008-12-06-SingleEntryPhi.ll
2008-12-16-DCECond.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
2009-01-18-PHIPropCrash.ll
2009-01-19-UnconditionalTrappingConstantExpr.ll
2009-05-12-externweak.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
2010-03-30-InvokeCrash.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
2011-03-08-UnreachableUse.ll
2011-09-05-TrivialLPad.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
assume.ll Add @llvm.assume, lowering, and some basic properties 2014-07-25 21:13:35 +00:00
attr-noduplicate.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
basictest.ll DI: Require subprogram definitions to be distinct 2015-08-28 20:26:49 +00:00
branch-cond-merge.ll
branch-cond-prop.ll
branch-fold-dbg.ll DI: Require subprogram definitions to be distinct 2015-08-28 20:26:49 +00:00
branch-fold-test.ll
branch-fold-threshold.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
branch-fold.ll
branch-phi-thread.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
BrUnwind.ll
clamp.ll [SimplifyCFG] Add test for r229099 2015-02-13 11:08:40 +00:00
common-dest-folding.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
CoveredLookupTable.ll
dbginfo.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
dce-cond-after-folding-terminator.ll
DeadSetCC.ll
duplicate-landingpad.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
duplicate-phis.ll
empty-cleanuppad.ll [WinEH] Pull Adjectives and CatchObj out of the catchpad arg list 2015-09-16 20:16:27 +00:00
EmptyBlockMerge.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
EqualPHIEdgeBlockMerge.ll
extract-cost.ll
ForwardSwitchConditionToPHI.ll
hoist-common-code.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
hoist-dbgvalue.ll DI: Require subprogram definitions to be distinct 2015-08-28 20:26:49 +00:00
hoist-with-range.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
HoistCode.ll
implied-cond.ll [SimplifyCFG] Constant fold a branch implied by it's incoming edge 2015-10-29 03:11:49 +00:00
indirectbr.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
invoke_unwind.ll Revert rL251061 [SimplifyCFG] Extend SimplifyResume to handle phi of trivial landing pad. 2015-10-23 21:13:01 +00:00
invoke.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
iterative-simplify.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
lifetime.ll SimplifyCFG: Avoid miscompilations due to removed lifetime intrinsics. 2014-07-30 21:04:00 +00:00
MagicPointer.ll [opaque pointer type] Add textual IR support for explicit type parameter to gep operator 2015-03-13 18:20:45 +00:00
merge-cond-stores.ll [SimplifyCFG] Merge conditional stores 2015-11-04 15:28:04 +00:00
multiple-phis.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
no_speculative_loads_with_asan.ll [asan] Disabling speculative loads under asan. Patch by Mike Aizatsky 2015-10-14 00:21:05 +00:00
no_speculative_loads_with_tsan.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
noreturn-call.ll
phi-undef-loadstore.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
PhiBlockMerge2.ll
PhiBlockMerge.ll [SimplifyCFG] Swap to using TargetTransformInfo for cost 2015-02-11 12:15:41 +00:00
PhiEliminate2.ll
PhiEliminate3.ll
PhiEliminate.ll
PHINode.ll
PhiNoEliminate.ll
PR9946.ll
PR16069.ll
PR17073.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
PR25267.ll [SimplifyCFG] Don't use-after-free an SSA value 2015-10-21 18:22:24 +00:00
preserve-branchweights-partial.ll IR: Make metadata typeless in assembly 2014-12-15 19:07:53 +00:00
preserve-branchweights-switch-create.ll IR: Make metadata typeless in assembly 2014-12-15 19:07:53 +00:00
preserve-branchweights.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
preserve-load-metadata-2.ll Preserve load alignment and dereferenceable metadata during some transformations 2015-11-02 17:53:51 +00:00
preserve-load-metadata-3.ll Preserve load alignment and dereferenceable metadata during some transformations 2015-11-02 17:53:51 +00:00
preserve-load-metadata.ll Preserve load alignment and dereferenceable metadata during some transformations 2015-11-02 17:53:51 +00:00
preserve-make-implicit-on-switch-to-br.ll [ConstantFoldTerminator] Preserve make.implicit metadata when converting SwitchInst to BranchInst 2015-08-07 19:30:12 +00:00
return-merge.ll
seh-nounwind.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
select-gep.ll [opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction 2015-02-27 19:29:02 +00:00
sink-common-code.ll [SimplifyCFG] Revise common code sinking 2014-12-23 08:26:55 +00:00
speculate-math.ll set div/rem default values to 'expensive' in TargetTransformInfo's cost model 2015-09-23 22:28:18 +00:00
speculate-store.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
speculate-vector-ops.ll
speculate-with-offset.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
SpeculativeExec.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
statepoint-invoke-unwind.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
switch_create.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
switch_switch_fold.ll
switch_thread.ll
switch-dead-default.ll [SimplifyCFG] Use known bits to eliminate dead switch defaults 2015-09-10 17:44:47 +00:00
switch-masked-bits.ll
switch-on-const-select.ll
switch-range-to-icmp.ll SimplifyCFG: don't remove unreachable default switch destinations 2015-01-26 19:52:32 +00:00
switch-simplify-crash.ll
switch-to-br.ll Add some tests for SimplifyCFG's ConstantFoldTerminator(). NFC. 2014-12-04 22:19:25 +00:00
switch-to-icmp.ll
switch-to-select-multiple-edge-per-block-phi.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
switch-to-select-two-case.ll SimplifyCFG: don't remove unreachable default switch destinations 2015-01-26 19:52:32 +00:00
trap-debugloc.ll DI: Require subprogram definitions to be distinct 2015-08-28 20:26:49 +00:00
trapping-load-unreachable.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
two-entry-phi-return.ll
UncondBranchToReturn.ll
unreachable-blocks.ll [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
UnreachableEliminate.ll Move the personality function from LandingPadInst to Function 2015-06-17 20:52:32 +00:00
volatile-phioper.ll [opaque pointer type] Add textual IR support for explicit type parameter to the call instruction 2015-04-16 23:24:18 +00:00
wineh-unreachable.ll [SimplifyCFG] Don't DCE catchret because the successor is unreachable 2015-10-27 22:43:56 +00:00