llvm-project/llvm/test/Transforms/SimplifyCFG
Roman Lebedev 1d51dc38d8
[SimplifyCFG][LoopRotate] SimplifyCFG: disable common instruction hoisting by default, enable late in pipeline
I've been looking at missed vectorizations in one codebase.
One particular thing that stands out is that some of the loops
reach vectorizer in a rather mangled form, with weird PHI's,
and some of the loops aren't even in a rotated form.

After taking a more detailed look, that happened because
the loop's headers were too big by then. It is evident that
SimplifyCFG's common code hoisting transform is at fault there,
because the pattern it handles is precisely the unrotated
loop basic block structure.

Surprizingly, `SimplifyCFGOpt::HoistThenElseCodeToIf()` is enabled
by default, and is always run, unlike it's friend, common code sinking
transform, `SinkCommonCodeFromPredecessors()`, which is not enabled
by default and is only run once very late in the pipeline.

I'm proposing to harmonize this, and disable common code hoisting
until //late// in pipeline. Definition of //late// may vary,
here currently i've picked the same one as for code sinking,
but i suppose we could enable it as soon as right after
loop rotation happens.

Experimentation shows that this does indeed unsurprizingly help,
more loops got rotated, although other issues remain elsewhere.

Now, this undoubtedly seriously shakes phase ordering.
This will undoubtedly be a mixed bag in terms of both compile- and
run- time performance, codesize. Since we no longer aggressively
hoist+deduplicate common code, we don't pay the price of said hoisting
(which wasn't big). That may allow more loops to be rotated,
so we pay that price. That, in turn, that may enable all the transforms
that require canonical (rotated) loop form, including but not limited to
vectorization, so we pay that too. And in general, no deduplication means
more [duplicate] instructions going through the optimizations. But there's still
late hoisting, some of them will be caught late.

As per benchmarks i've run {F12360204}, this is mostly within the noise,
there are some small improvements, some small regressions.
One big regression i saw i fixed in rG8d487668d09fb0e4e54f36207f07c1480ffabbfd, but i'm sure
this will expose many more pre-existing missed optimizations, as usual :S

llvm-compile-time-tracker.com thoughts on this:
http://llvm-compile-time-tracker.com/compare.php?from=e40315d2b4ed1e38962a8f33ff151693ed4ada63&to=c8289c0ecbf235da9fb0e3bc052e3c0d6bff5cf9&stat=instructions
* this does regress compile-time by +0.5% geomean (unsurprizingly)
* size impact varies; for ThinLTO it's actually an improvement

The largest fallout appears to be in GVN's load partial redundancy
elimination, it spends *much* more time in
`MemoryDependenceResults::getNonLocalPointerDependency()`.
Non-local `MemoryDependenceResults` is widely-known to be, uh, costly.
There does not appear to be a proper solution to this issue,
other than silencing the compile-time performance regression
by tuning cut-off thresholds in `MemoryDependenceResults`,
at the cost of potentially regressing run-time performance.
D84609 attempts to move in that direction, but the path is unclear
and is going to take some time.

If we look at stats before/after diffs, some excerpts:
* RawSpeed (the target) {F12360200}
  * -14 (-73.68%) loops not rotated due to the header size (yay)
  * -272 (-0.67%) `"Number of live out of a loop variables"` - good for vectorizer
  * -3937 (-64.19%) common instructions hoisted
  * +561 (+0.06%) x86 asm instructions
  * -2 basic blocks
  * +2418 (+0.11%) IR instructions
* vanilla test-suite + RawSpeed + darktable  {F12360201}
  * -36396 (-65.29%) common instructions hoisted
  * +1676 (+0.02%) x86 asm instructions
  * +662 (+0.06%) basic blocks
  * +4395 (+0.04%) IR instructions

It is likely to be sub-optimal for when optimizing for code size,
so one might want to change tune pipeline by enabling sinking/hoisting
when optimizing for size.

Reviewed By: mkazantsev

Differential Revision: https://reviews.llvm.org/D84108
2020-07-29 20:05:30 +03:00
..
AArch64 [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
AMDGPU
ARM [NFC][ARM] Add SimplifyCFG test 2020-07-17 14:07:40 +01:00
Hexagon [llvm] Fix missing FileCheck directive colons 2020-04-06 09:59:08 -06:00
Mips
PowerPC [PowerPC] add store (load float*) pattern to isProfitableToHoist 2020-07-21 20:55:13 -04:00
RISCV
SPARC
X86 [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
1elt-ptr-vec-alignment-crash.ll [Analysis] isDereferenceableAndAlignedPointer(): don't crash on `bitcast <1 x ???*> to ???*` 2020-06-27 18:30:59 +03:00
2002-05-21-PHIElimination.ll
2002-09-24-PHIAssertion.ll
2003-03-07-DominateProblem.ll
2003-08-05-InvokeCrash.ll
2003-08-17-BranchFold.ll
2003-08-17-BranchFoldOrdering.ll
2003-08-17-FoldSwitch-dbg.ll
2003-08-17-FoldSwitch.ll
2004-12-10-SimplifyCFGCrash.ll
2005-06-16-PHICrash.ll
2005-08-01-PHIUpdateFail.ll
2005-10-02-InvokeSimplify.ll
2005-12-03-IncorrectPHIFold.ll
2006-02-17-InfiniteUnroll.ll
2006-06-12-InfLoop.ll
2006-08-03-Crash.ll
2006-10-19-UncondDiv.ll
2006-12-08-Ptr-ICmp-Branch.ll
2007-11-22-InvokeNoUnwind.ll
2007-12-21-Crash.ll
2008-01-02-hoist-fp-add.ll
2008-05-16-PHIBlockMerge.ll
2008-07-13-InfLoopMiscompile.ll
2008-09-08-MultiplePred.ll
2008-09-17-SpeculativeHoist.ll
2008-10-03-SpeculativelyExecuteBeforePHI.ll
2008-12-06-SingleEntryPhi.ll
2008-12-16-DCECond.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
2009-01-18-PHIPropCrash.ll
2009-05-12-externweak.ll
2011-03-08-UnreachableUse.ll
2011-09-05-TrivialLPad.ll
BrUnwind.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
ConditionalTrappingConstantExpr.ll [SimplifyCFG] regenerate test checks; NFC 2020-03-13 14:12:28 -04:00
DeadSetCC.ll
EmptyBlockMerge.ll
EqualPHIEdgeBlockMerge.ll
ForwardSwitchConditionToPHI.ll [SimplifyCFG] Regenerate test checks (NFC) 2020-06-28 20:51:02 +02:00
HoistCode.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
InfLoop.ll
PHINode.ll
PR9946.ll
PR16069.ll
PR17073.ll [SimplifyCFG] regenerate complete test checks; NFC 2020-03-13 14:12:28 -04:00
PR25267.ll
PR27615-simplify-cond-br.ll
PhiBlockMerge.ll
PhiBlockMerge2.ll
PhiEliminate.ll
PhiEliminate2.ll
PhiEliminate3.ll
PhiNoEliminate.ll
UncondBranchToHeader.ll
UncondBranchToReturn.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
UnreachableEliminate.ll [IR] Convert null-pointer-is-valid into an enum attribute 2020-05-15 19:41:07 +02:00
assume.ll
attr-convergent.ll
attr-noduplicate.ll
basictest.ll [SimplifyCFG] Update debug location when folding branch to common destination 2020-06-18 12:33:32 -07:00
bbi-23595.ll
branch-cond-merge.ll
branch-cond-prop.ll
branch-fold-dbg.ll
branch-fold-test.ll
branch-fold-three.ll
branch-fold-threshold.ll
branch-fold.ll
branch-phi-thread.ll
callbr-destinations.ll [SimplifyCFG] Skip merging return blocks if it would break a CallBr. 2020-03-10 14:59:13 +01:00
clamp.ll
common-code-hoisting.ll [SimplifyCFG][LoopRotate] SimplifyCFG: disable common instruction hoisting by default, enable late in pipeline 2020-07-29 20:05:30 +03:00
common-dest-folding.ll
constantexprs.ll [CostModel] Avoid traditional ConstantExpr crashy pitfails 2020-06-26 22:48:10 +03:00
convergent.ll [SimplifyCFG] Do not create unneeded PR Phi in block with convergent calls 2020-07-22 13:53:50 +07:00
dbginfo.ll
dce-cond-after-folding-terminator.ll
debug-info-thread-phi.ll
div-rem-pairs.ll
drop-debug-loc-when-speculating.ll [SimplifyCFG] Drop debug loc in SpeculativelyExecuteBB 2020-06-23 18:25:52 -07:00
duplicate-landingpad.ll [SimplifyCFG] Regenerate test checks (NFC) 2020-06-28 20:51:02 +02:00
duplicate-phis.ll
empty-catchpad.ll
extract-cost.ll [SimplifyCFG] add test for chain of empty block conditional branches; NFC 2020-03-13 14:39:31 -04:00
fold-debug-info.ll
fold-debug-location.ll [SimplifyCFG] Update debug location when folding branch to common destination 2020-06-18 12:33:32 -07:00
gepcost.ll
guards.ll
hoist-common-code.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
hoist-dbgvalue-inlined.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
hoist-dbgvalue.ll
hoist-with-range.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
implied-and-or.ll
implied-cond-matching-false-dest.ll
implied-cond-matching-imm.ll
implied-cond-matching.ll
implied-cond.ll
indirectbr.ll
inline-asm-sink.ll
invoke.ll [IR] Convert null-pointer-is-valid into an enum attribute 2020-05-15 19:41:07 +02:00
invoke_unwind.ll [IR] Convert profile metadata in createCallMatchingInvoke() 2020-06-20 12:10:31 +07:00
iterative-simplify.ll
lifetime-landingpad.ll Fix lifetime call in landingpad blocking Simplifycfg pass 2020-04-09 13:07:32 -07:00
lifetime.ll
merge-cond-stores-2.ll
merge-cond-stores.ll [InstCombine] Always try to invert non-canonical predicate of an icmp 2020-07-04 18:12:04 +03:00
multiple-phis.ll
no-md-sink.ll
no_speculative_loads_with_asan.ll
no_speculative_loads_with_tsan.ll
nomerge.ll Add nomerge function attribute to supress tail merge optimization in simplifyCFG 2020-05-12 16:49:20 -07:00
noreturn-call.ll
opt-for-fuzzing.ll
phi-undef-loadstore.ll [IR] Convert null-pointer-is-valid into an enum attribute 2020-05-15 19:41:07 +02:00
pr33605.ll [llvm] Fix missing FileCheck directive colons 2020-04-06 09:59:08 -06:00
pr34131.ll
pr35774.ll
pr39807.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
pr46638.ll [InstSimplify] Handle not inserted instruction gracefully (PR46638) 2020-07-08 21:43:32 +02:00
preserve-branchweights-partial.ll
preserve-branchweights-switch-create.ll
preserve-branchweights.ll
preserve-llvm-loop-metadata.ll
preserve-load-metadata-2.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
preserve-load-metadata-3.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
preserve-load-metadata.ll [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag 2020-07-20 10:29:57 +03:00
preserve-make-implicit-on-switch-to-br.ll
preserve-store-alignment.ll
rangereduce.ll
return-merge.ll
safe-abs.ll
seh-nounwind.ll
select-gep.ll
signbit-like-value-extension.ll
sink-common-code.ll Allow replacing intrinsic operands with variables 2020-03-23 15:51:57 -04:00
speculate-call.ll
speculate-dbgvalue.ll
speculate-math.ll
speculate-store.ll
speculate-vector-ops.ll
speculate-with-offset.ll
statepoint-invoke-unwind.ll
suppress-zero-branch-weights.ll
switch-dead-default.ll [SimplifyCFG] Make test more robust (NFC) 2020-06-28 20:51:03 +02:00
switch-masked-bits.ll
switch-on-const-select.ll
switch-profmd.ll
switch-range-to-icmp.ll
switch-simplify-crash.ll
switch-to-br.ll
switch-to-icmp.ll
switch-to-select-multiple-edge-per-block-phi.ll
switch-to-select-two-case.ll
switch_create-custom-dl.ll
switch_create.ll
switch_msan.ll
switch_switch_fold.ll
switch_thread.ll
switch_undef.ll
trap-debugloc.ll
trap-no-null-opt-debugloc.ll [IR] Convert null-pointer-is-valid into an enum attribute 2020-05-15 19:41:07 +02:00
trapping-load-unreachable.ll [IR] Convert null-pointer-is-valid into an enum attribute 2020-05-15 19:41:07 +02:00
two-entry-phi-fold-crash.ll [SimplifyCFG] Fix crash in the EXPENSIVE_CHECKS build 2020-07-16 15:34:41 -06:00
two-entry-phi-return.ll
unprofitable-pr.ll [SimplifyCFG] Fix inconsistency in block size assessment for threading 2020-06-30 12:40:07 +07:00
unreachable-cleanuppad.ll
unreachable_assume.ll
unsigned-multiplication-will-overflow.ll
volatile-phioper.ll
wc-widen-block.ll [SimplifyCFG] Regenerate test checks (NFC) 2020-06-28 20:51:02 +02:00
wineh-unreachable.ll