[all-commits] [llvm/llvm-project] 4f7e5d: [SROA] For non-speculatable `load`s of `select`s -...
Roman Lebedev via All-commits
all-commits at lists.llvm.org
Thu Dec 8 09:20:17 PST 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 4f7e5d22060e8a89237ffb93c3e7be6e92fee8fe
https://github.com/llvm/llvm-project/commit/4f7e5d22060e8a89237ffb93c3e7be6e92fee8fe
Author: Roman Lebedev <lebedev.ri at gmail.com>
Date: 2022-12-08 (Thu, 08 Dec 2022)
Changed paths:
M llvm/include/llvm/Transforms/Scalar.h
M llvm/include/llvm/Transforms/Scalar/SROA.h
M llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
M llvm/lib/Passes/PassBuilder.cpp
M llvm/lib/Passes/PassBuilderPipelines.cpp
M llvm/lib/Passes/PassRegistry.def
M llvm/lib/Transforms/Scalar/SROA.cpp
M llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
M llvm/test/Transforms/SROA/2009-02-20-InstCombine-SROA.ll
M llvm/test/Transforms/SROA/address-spaces.ll
M llvm/test/Transforms/SROA/addrspacecast.ll
M llvm/test/Transforms/SROA/alignment.ll
M llvm/test/Transforms/SROA/alloca-address-space.ll
M llvm/test/Transforms/SROA/assume.ll
M llvm/test/Transforms/SROA/basictest.ll
M llvm/test/Transforms/SROA/big-endian.ll
M llvm/test/Transforms/SROA/dbg-addr-diamond.ll
M llvm/test/Transforms/SROA/dbg-inline.ll
M llvm/test/Transforms/SROA/dbg-single-piece.ll
M llvm/test/Transforms/SROA/dead-inst.ll
M llvm/test/Transforms/SROA/fca.ll
M llvm/test/Transforms/SROA/ignore-droppable.ll
M llvm/test/Transforms/SROA/invariant-group.ll
M llvm/test/Transforms/SROA/irregular-type.ll
M llvm/test/Transforms/SROA/lifetime-intrinsic.ll
M llvm/test/Transforms/SROA/mem-par-metadata-sroa-cast.ll
M llvm/test/Transforms/SROA/mem-par-metadata-sroa.ll
M llvm/test/Transforms/SROA/non-capturing-call-readonly.ll
M llvm/test/Transforms/SROA/non-integral-pointers.ll
M llvm/test/Transforms/SROA/phi-and-select.ll
M llvm/test/Transforms/SROA/phi-catchswitch.ll
M llvm/test/Transforms/SROA/phi-gep.ll
M llvm/test/Transforms/SROA/phi-speculate-different-load-types.ll
M llvm/test/Transforms/SROA/phi-with-duplicate-pred.ll
M llvm/test/Transforms/SROA/pointer-offset-size.ll
M llvm/test/Transforms/SROA/ppcf128-no-fold.ll
M llvm/test/Transforms/SROA/pr26972.ll
M llvm/test/Transforms/SROA/pr37267.ll
M llvm/test/Transforms/SROA/preserve-nonnull.ll
M llvm/test/Transforms/SROA/scalable-vectors.ll
M llvm/test/Transforms/SROA/select-gep.ll
M llvm/test/Transforms/SROA/select-load.ll
M llvm/test/Transforms/SROA/slice-order-independence.ll
M llvm/test/Transforms/SROA/slice-width.ll
M llvm/test/Transforms/SROA/sroa-common-type-fail-promotion.ll
M llvm/test/Transforms/SROA/std-clamp.ll
M llvm/test/Transforms/SROA/tbaa-struct.ll
M llvm/test/Transforms/SROA/tbaa-struct2.ll
M llvm/test/Transforms/SROA/tbaa-subload.ll
M llvm/test/Transforms/SROA/vector-conversion.ll
M llvm/test/Transforms/SROA/vector-lifetime-intrinsic.ll
M llvm/test/Transforms/SROA/vector-promotion-different-size.ll
M llvm/test/Transforms/SROA/vector-promotion.ll
M llvm/test/Transforms/SROA/vectors-of-pointers.ll
Log Message:
-----------
[SROA] For non-speculatable `load`s of `select`s -- split block, insert then/else blocks, form two-entry PHI node, take 2
Currently, SROA is CFG-preserving.
Not doing so does not affect any pipeline test. (???)
Internally, SROA requires Dominator Tree, and uses it solely for the final `-mem2reg` call.
By design, we can't really SROA alloca if their address escapes somehow,
but we have logic to deal with `load` of `select`/`PHI`,
where at least one of the possible addresses prevents promotion,
by speculating the `load`s and `select`ing between loaded values.
As one would expect, that requires ensuring that the speculation is actually legal.
Even ignoring complexity bailouts, that logic does not deal with everything,
e.g. `isSafeToLoadUnconditionally()` does not recurse into hands of `select`.
There can also be cases where the load is genuinely non-speculate.
So if we can't prove that the load can be speculated,
unfold the select, produce two-entry phi node, and perform predicated load.
Now, that transformation must obviously update Dominator Tree,
since we require it later on. Doing so is trivial.
Additionally, we don't want to do this for the final SROA invocation (D136806).
In the end, this ends up having negative (!) compile-time cost:
https://llvm-compile-time-tracker.com/compare.php?from=c6d7e80ec4c17a415673b1cfd25924f98ac83608&to=ddf9600365093ea50d7e278696cbfa01641c959d&stat=instructions:u
Though indeed, this only deals with `select`s, `PHI`s are still using speculation.
Should we update some more analysis?
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D138238
This reverts commit 739611870d3b06605afe25cc07833f6a62de9545,
and recommits 03e6d9d9d1d48e43f3efc35eb75369b90d4510d5
with a fixed assertion - we should check that DTU is there,
not just assert false...
More information about the All-commits
mailing list