llvm-project/llvm/test/Transforms/SCCP
Akira Hatanaka 1900503595 [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of
explicitly emitting retainRV or claimRV calls in the IR

This reapplies ed4718eccb, which was reverted
because it was causing a miscompile. The bug that was causing the miscompile
has been fixed in 75805dce5f.

Original commit message:

Background:

This fixes a longstanding problem where llvm breaks ARC's autorelease
optimization (see the link below) by separating calls from the marker
instructions or retainRV/claimRV calls. The backend changes are in
https://reviews.llvm.org/D92569.

https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue

What this patch does to fix the problem:

- The front-end adds operand bundle "clang.arc.attachedcall" to calls,
  which indicates the call is implicitly followed by a marker
  instruction and an implicit retainRV/claimRV call that consumes the
  call result. In addition, it emits a call to
  @llvm.objc.clang.arc.noop.use, which consumes the call result, to
  prevent the middle-end passes from changing the return type of the
  called function. This is currently done only when the target is arm64
  and the optimization level is higher than -O0.

- ARC optimizer temporarily emits retainRV/claimRV calls after the calls
  with the operand bundle in the IR and removes the inserted calls after
  processing the function.

- ARC contract pass emits retainRV/claimRV calls after the call with the
  operand bundle. It doesn't remove the operand bundle on the call since
  the backend needs it to emit the marker instruction. The retainRV and
  claimRV calls are emitted late in the pipeline to prevent optimization
  passes from transforming the IR in a way that makes it harder for the
  ARC middle-end passes to figure out the def-use relationship between
  the call and the retainRV/claimRV calls (which is the cause of
  PR31925).

- The function inliner removes an autoreleaseRV call in the callee if
  nothing in the callee prevents it from being paired up with the
  retainRV/claimRV call in the caller. It then inserts a release call if
  claimRV is attached to the call since autoreleaseRV+claimRV is
  equivalent to a release. If it cannot find an autoreleaseRV call, it
  tries to transfer the operand bundle to a function call in the callee.
  This is important since the ARC optimizer can remove the autoreleaseRV
  returning the callee result, which makes it impossible to pair it up
  with the retainRV/claimRV call in the caller. If that fails, it simply
  emits a retain call in the IR if retainRV is attached to the call and
  does nothing if claimRV is attached to it.

- SCCP refrains from replacing the return value of a call with a
  constant value if the call has the operand bundle. This ensures the
  call always has at least one user (the call to
  @llvm.objc.clang.arc.noop.use).

- This patch also fixes a bug in replaceUsesOfNonProtoConstant where
  multiple operand bundles of the same kind were being added to a call.

Future work:

- Use the operand bundle on x86-64.

- Fix the auto upgrader to convert call+retainRV/claimRV pairs into
  calls with the operand bundles.

rdar://71443534

Differential Revision: https://reviews.llvm.org/D92808
2021-03-04 11:22:30 -08:00
..
2002-05-02-MissSecondInst.ll
2002-05-20-MissedIncomingValue.ll
2002-05-21-InvalidSimplify.ll [SimplifyCFG] TryToSimplifyUncondBranchFromEmptyBlock() already knows how to preserve DomTree 2020-12-17 01:03:49 +03:00
2002-08-30-GetElementPtrTest.ll
2003-06-24-OverdefinedPHIValue.ll [SimplifyCFG] MergeBlockIntoPredecessor() already knows how to preserve DomTree 2020-12-17 01:03:49 +03:00
2003-08-26-InvokeHandling.ll
2004-11-16-DeadInvoke.ll
2004-12-10-UndefBranchBug.ll [SCCP] Reduce the number of times ResolvedUndefsIn is called for large modules. 2020-10-09 15:24:16 -07:00
2006-10-23-IPSCCP-Crash.ll
2006-12-04-PackedType.ll
2006-12-19-UndefBug.ll Recommit "[SCCP] Remove forcedconstant, go to overdefined instead" 2020-02-15 18:36:44 +01:00
2007-05-16-InvokeCrash.ll
2008-01-27-UndefCorrelate.ll
2008-04-22-multiple-ret-sccp.ll
2008-05-23-UndefCallFold.ll
2008-06-09-WeakProp.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
2009-01-14-IPSCCP-Invoke.ll
2009-05-27-VectorOperandZero.ll
2009-09-24-byval-ptr.ll OpaquePtr: Bulk update tests to use typed byval 2020-11-20 14:00:46 -05:00
PR16052.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
PR26044.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
PR43857.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
apfloat-basictest.ll
apint-array.ll
apint-basictest.ll
apint-basictest2.ll
apint-basictest3.ll
apint-basictest4.ll
apint-bigarray.ll
apint-bigint.ll
apint-bigint2.ll Revert "Recommit "[SCCP] Do not replace deref'able ptr with un-deref'able one."" 2020-09-29 09:18:19 +01:00
apint-ipsccp1.ll
apint-ipsccp2.ll
apint-ipsccp3.ll Recommit "[SCCP] Remove forcedconstant, go to overdefined instead" 2020-02-15 18:36:44 +01:00
apint-ipsccp4.ll
apint-load.ll
apint-phi.ll
apint-select.ll Recommit "[SCCP] Remove forcedconstant, go to overdefined instead" 2020-02-15 18:36:44 +01:00
apint-xor.ll [SCCP] Add a few more tests for conditional propagation,XOR. 2020-03-22 21:43:33 +00:00
arg-count-mismatch.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
arg-type-mismatch.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
assume.ll [SCCP] Propagate inequalities 2020-08-04 20:20:52 +02:00
atomic-load-store.ll
atomic.ll
binaryops-constexprs.ll [SCCP] Add test case for binary ops with constant expressions. 2020-04-09 13:38:43 +01:00
binaryops-range-special-cases.ll [SCCP] Use constant ranges for PHI nodes. 2020-03-19 12:45:33 +00:00
bitcast.ll
calltest.ll [SimplifyCFG] MergeBlockIntoPredecessor() already knows how to preserve DomTree 2020-12-17 01:03:49 +03:00
clang-arc-rv.ll [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of 2021-03-04 11:22:30 -08:00
comdat-ipo.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
conditions-iter-order.ll [SCCP] Add a few more tests for conditional propagation,XOR. 2020-03-22 21:43:33 +00:00
conditions-ranges-with-undef.ll [SCCP] Use ranges for predicate info conditions. 2020-04-07 11:09:18 +01:00
conditions-ranges.ll [PredicateInfo] Handle logical and/or 2021-01-20 21:03:07 +01:00
constant-range-struct.ll [SCCP] Switch to widen at PHIs, stores and call edges. 2020-05-29 11:59:17 +01:00
constant-struct.ll
crash.ll
dangling-block-address.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
deadarg.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
definite-initializer.ll
domtree-update.ll Reapply [SCCP] Directly remove non-feasible edges 2020-07-25 14:52:35 +02:00
dont-zap-return.ll
float-nan-simplification.ll Recommit "[SCCP] Use SimplifyBinOp for non-integer constant/expressions & overdef." 2020-04-14 11:48:52 +01:00
float-phis.ll [ValueLattice] Add new state for undef constants. 2020-03-14 17:19:59 +00:00
fp-bc-icmp-const-fold.ll Re-land "[PowerPC] Remove QPX/A2Q BGQ/BGP CNK support" 2020-07-28 14:00:11 +00:00
global-alias-constprop.ll
global.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
indirectbr.ll Revert "Recommit "[SCCP] Do not replace deref'able ptr with un-deref'able one."" 2020-09-29 09:18:19 +01:00
int-phis.ll [ValueLattice] Add new state for undef constants. 2020-03-14 17:19:59 +00:00
intrinsics.ll [SCCP] Compute ranges for supported intrinsics 2020-09-07 22:16:06 +02:00
ip-add-range-to-call.ll [SCCP] Add range metadata to call sites with known return ranges. 2020-07-21 10:06:54 +01:00
ip-constant-ranges.ll [SCCP] Use ranges for predicate info conditions. 2020-04-07 11:09:18 +01:00
ip-ranges-binaryops.ll [SCCP] Use constant ranges for binary operators. 2020-03-19 09:35:48 +00:00
ip-ranges-casts.ll [SCCP] Turn sext into zext for non-negative ranges. 2020-06-19 10:17:55 +01:00
ip-ranges-phis.ll [SCCP] Use constant ranges for PHI nodes. 2020-03-19 12:45:33 +00:00
ip-ranges-select.ll [ConstantFold] Fold the comparison of bitcasted global values 2020-10-20 12:41:49 -07:00
ip-ranges-sext.ll [SCCP] Turn sext into zext for non-negative ranges. 2020-06-19 10:17:55 +01:00
ipsccp-addr-taken.ll
ipsccp-basic.ll Recommit "[SCCP] Remove forcedconstant, go to overdefined instead" 2020-02-15 18:36:44 +01:00
ipsccp-branch-unresolved-undef.ll
ipsccp-clear-returned.ll [IPSCCP] Fix a bug that the "returned" attribute is not cleared when function is optimized to return undef 2020-09-02 11:21:48 -04:00
ipsccp-cycles.ll [SCCP] Switch to widen at PHIs, stores and call edges. 2020-05-29 11:59:17 +01:00
ipsccp-phi-one-pred-dead.ll
ipsccp-predinfo-order.ll
ipsccp-preserve-analysis.ll [NewPM] Don't print 'Invalidating all non-preserved analyses' 2020-07-30 19:40:29 -07:00
ipsccp-range-crashes.ll [SCCP] Precommit some additional tests for integer ranges. 2020-03-18 11:34:04 +00:00
ipsccp-ssa-copy-nested-conds.ll [SCCP] Add tests with AND/OR branch conditions. 2020-04-09 16:39:13 +01:00
ipscp-drop-argmemonly.ll [IPSCCP] Drop argmemonly after replacing pointer argument. 2020-07-25 11:52:14 +01:00
latticeval-invalidate.ll
load-store-range.ll [SCCP] Support ranges for loads and stores. 2020-04-26 13:16:47 +01:00
loadtest.ll [SCCP] Do not mark unknown loads as overdefined. 2020-02-20 22:48:58 +01:00
loadtest2.ll [SCCP] Do not mark unknown loads as overdefined. 2020-02-20 22:48:58 +01:00
logical-nuke.ll Recommit "[SCCP] Remove forcedconstant, go to overdefined instead" 2020-02-15 18:36:44 +01:00
metadata.ll [SCCP] Propagate inequalities 2020-08-04 20:20:52 +02:00
multiple_callbacks.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
musttail-call.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
naked-return.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
openmp_parallel_for.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
overdefined-div.ll
phi-cycle.ll [ValueLattice] Distinguish between constant ranges with/without undef. 2020-03-31 12:50:20 +01:00
phis.ll [SCCP] Use constant ranges for PHI nodes. 2020-03-19 12:45:33 +00:00
pr27712.ll
pr35357.ll
pr45185-range-predinfo.ll Recommit "[SCCP] Use ValueLatticeElement instead of LatticeVal (NFCI)" 2020-03-13 17:03:22 +00:00
predicateinfo-cond.ll Reapply [SCCP] Directly remove non-feasible edges 2020-07-25 14:52:35 +02:00
preserve-analysis.ll [NewPM] Pin tests with -debug-pass to legacy PM 2020-09-22 17:54:25 -07:00
pthreads.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
range-and-ip.ll [ValueLattice] Distinguish between constant ranges with/without undef. 2020-03-31 12:50:20 +01:00
range-and.ll [ValueLattice] Distinguish between constant ranges with/without undef. 2020-03-31 12:50:20 +01:00
ranges-sext.ll [SCCP] Turn sext into zext for non-negative ranges. 2020-06-19 10:17:55 +01:00
recursion.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
remove-call-inst.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
replace-dereferenceable-ptr-with-undereferenceable.ll Revert "Recommit "[SCCP] Do not replace deref'able ptr with un-deref'able one."" 2020-09-29 09:18:19 +01:00
resolvedundefsin-tracked-fn.ll [SCCP] Reduce the number of times ResolvedUndefsIn is called for large modules. 2020-10-09 15:24:16 -07:00
return-argument.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
return-constant.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
return-constants.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
return-zapped.ll
retvalue-undef.ll
sccptest.ll
select.ll [SCCP] Use constant ranges for select, if cond is overdefined. 2020-03-18 09:26:02 +00:00
solve-after-each-resolving-undefs-for-function.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
struct-arg-resolve-undefs.ll
switch-constantfold-crash.ll Reapply [SCCP] Directly remove non-feasible edges 2020-07-25 14:52:35 +02:00
switch-multiple-undef.ll Recommit "[SCCP] Remove forcedconstant, go to overdefined instead" 2020-02-15 18:36:44 +01:00
switch-undef-constantfoldterminator.ll
switch.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
thread_local_acs.ll Recommit "[IPConstProp] Remove and move tests to SCCP." 2020-08-02 22:23:54 +01:00
ub-shift.ll Recommit "[SCCP] Use SimplifyBinOp for non-integer constant/expressions & overdef." 2020-04-14 11:48:52 +01:00
ubsan_overflow.ll
undef-resolve.ll [ConstantFold] Fold the comparison of bitcasted global values 2020-10-20 12:41:49 -07:00
user-with-multiple-uses.ll [SCCP] Move tests using only ipsccp from IPConstantProp to SCCP (NFC). 2020-07-09 17:16:15 +01:00
vector-bitcast.ll [SCCP] Handle bitcast of vector constants. 2020-11-03 12:58:39 +00:00
widening.ll Reapply [SCCP] Directly remove non-feasible edges 2020-07-25 14:52:35 +02:00