Skip to content

[IR] Remove size argument from lifetime intrinsics #150248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Jul 23, 2025

Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).

Copy link

github-actions bot commented Jul 23, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions c,cl,h,cpp -- clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGCall.h clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprAgg.cpp clang/lib/CodeGen/CodeGenFunction.h clang/test/C/C11/n1285_1.c clang/test/CodeGen/AArch64/ABI-align-packed.c clang/test/CodeGen/AArch64/byval-temp.c clang/test/CodeGen/AArch64/pure-scalable-args.c clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp clang/test/CodeGen/aggregate-assign-call.c clang/test/CodeGen/attr-counted-by.c clang/test/CodeGen/cleanup-destslot-simple.c clang/test/CodeGen/dominating-store-to-return.c clang/test/CodeGen/lifetime-sanitizer.c clang/test/CodeGen/lifetime.c clang/test/CodeGen/lifetime2.c clang/test/CodeGen/lifetime3.cpp clang/test/CodeGen/math-libcalls-tbaa.c clang/test/CodeGen/nofpclass.c clang/test/CodeGen/temporary-lifetime-exceptions.cpp clang/test/CodeGen/temporary-lifetime.cpp clang/test/CodeGen/union-tbaa1.c clang/test/CodeGenCXX/amdgcn_declspec_get.cpp clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp clang/test/CodeGenCXX/destructors.cpp clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp clang/test/CodeGenCXX/stack-reuse-exceptions.cpp clang/test/CodeGenCXX/stack-reuse-miscompile.cpp clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl clang/test/CodeGenOpenCL/amdgpu-printf.cl clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl clang/test/CodeGenOpenCL/implicit-addrspacecast-function-parameter.cl clang/test/OpenMP/bug54082.c clang/test/OpenMP/bug56913.c clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp flang/include/flang/Optimizer/Builder/FIRBuilder.h flang/lib/Optimizer/Builder/FIRBuilder.cpp flang/lib/Optimizer/Transforms/StackArrays.cpp llvm/include/llvm/Analysis/StackLifetime.h llvm/include/llvm/CodeGen/SelectionDAG.h llvm/include/llvm/CodeGen/SelectionDAGNodes.h llvm/include/llvm/IR/IRBuilder.h llvm/lib/Analysis/MemoryDependenceAnalysis.cpp llvm/lib/Analysis/MemoryLocation.cpp llvm/lib/Analysis/StackLifetime.cpp llvm/lib/CodeGen/AtomicExpandPass.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp llvm/lib/IR/AutoUpgrade.cpp llvm/lib/IR/IRBuilder.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Target/AArch64/AArch64StackTagging.cpp llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp llvm/lib/Transforms/Coroutines/CoroFrame.cpp llvm/lib/Transforms/IPO/ExpandVariadics.cpp llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp llvm/lib/Transforms/Scalar/NewGVN.cpp llvm/lib/Transforms/Scalar/SROA.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/lib/Transforms/Utils/Local.cpp llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp llvm/unittests/Analysis/MemorySSATest.cpp llvm/unittests/IR/IRBuilderTest.cpp mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
index 900da7645..03305de3a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
@@ -941,11 +941,8 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
       OS << " [TF=" << TF << ']';
   } else if (const AddrSpaceCastSDNode *ASC =
                dyn_cast<AddrSpaceCastSDNode>(this)) {
-    OS << '['
-       << ASC->getSrcAddressSpace()
-       << " -> "
-       << ASC->getDestAddressSpace()
-       << ']';
+    OS << '[' << ASC->getSrcAddressSpace() << " -> "
+       << ASC->getDestAddressSpace() << ']';
   } else if (const auto *AA = dyn_cast<AssertAlignSDNode>(this)) {
     OS << '<' << AA->getAlign().value() << '>';
   }

@nikic nikic force-pushed the lifetime-size branch 2 times, most recently from a56aec7 to ef647f8 Compare July 25, 2025 15:18
@nikic nikic marked this pull request as ready for review July 25, 2025 15:25
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AArch64 backend:AMDGPU backend:MIPS backend:RISC-V backend:PowerPC backend:SystemZ backend:WebAssembly backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. llvm:codegen llvm:globalisel mlir:llvm PGO Profile Guided Optimizations mlir flang Flang issues not falling into any other category llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes backend:SPIR-V backend:NVPTX coroutines C++20 coroutines llvm:SelectionDAG SelectionDAGISel as well compiler-rt:sanitizer flang:fir-hlfir llvm:ir llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Jul 25, 2025
@llvmbot llvmbot added the clang:openmp OpenMP related changes to Clang label Jul 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

@llvm/pr-subscribers-backend-systemz
@llvm/pr-subscribers-llvm-globalisel
@llvm/pr-subscribers-backend-risc-v
@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-amdgpu

Author: Nikita Popov (nikic)

Changes

Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).


Patch is 1.54 MiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/150248.diff

479 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-11)
  • (modified) clang/lib/CodeGen/CGCall.cpp (+16-31)
  • (modified) clang/lib/CodeGen/CGCall.h (+2-6)
  • (modified) clang/lib/CodeGen/CGDecl.cpp (+14-19)
  • (modified) clang/lib/CodeGen/CGExpr.cpp (+6-14)
  • (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3-7)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+8-16)
  • (modified) clang/test/C/C11/n1285_1.c (+22-22)
  • (modified) clang/test/CodeGen/AArch64/ABI-align-packed.c (+28-28)
  • (modified) clang/test/CodeGen/AArch64/byval-temp.c (+12-12)
  • (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+5-5)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+2-2)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp (+2-2)
  • (modified) clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp (+4-4)
  • (modified) clang/test/CodeGen/aggregate-assign-call.c (+11-11)
  • (modified) clang/test/CodeGen/attr-counted-by.c (+4-4)
  • (modified) clang/test/CodeGen/cleanup-destslot-simple.c (+12-12)
  • (modified) clang/test/CodeGen/dominating-store-to-return.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime-sanitizer.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime2.c (+9-9)
  • (modified) clang/test/CodeGen/lifetime3.cpp (+8-8)
  • (modified) clang/test/CodeGen/math-libcalls-tbaa.c (+6-6)
  • (modified) clang/test/CodeGen/nofpclass.c (+4-4)
  • (modified) clang/test/CodeGen/temporary-lifetime-exceptions.cpp (+6-6)
  • (modified) clang/test/CodeGen/temporary-lifetime.cpp (+24-24)
  • (modified) clang/test/CodeGen/union-tbaa1.c (+2-2)
  • (modified) clang/test/CodeGenCXX/amdgcn_declspec_get.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+20-20)
  • (modified) clang/test/CodeGenCXX/destructors.cpp (+7-7)
  • (modified) clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/stack-reuse-exceptions.cpp (+30-30)
  • (modified) clang/test/CodeGenCXX/stack-reuse-miscompile.cpp (+3-3)
  • (modified) clang/test/CodeGenObjC/arc-blocks.m (+9-9)
  • (modified) clang/test/CodeGenObjC/arc-precise-lifetime.m (+34-34)
  • (modified) clang/test/CodeGenObjC/arc-ternary-op.m (+6-6)
  • (modified) clang/test/CodeGenObjC/arc.m (+51-51)
  • (modified) clang/test/CodeGenObjC/exceptions.m (+2-2)
  • (modified) clang/test/CodeGenObjCXX/arc-move.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/arc-references.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/arc.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/literals.mm (+6-6)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl (+16-16)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-printf.cl (+2-2)
  • (modified) clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (+14-14)
  • (modified) clang/test/CodeGenOpenCL/implicit-addrspacecast-function-parameter.cl (+2-2)
  • (modified) clang/test/Headers/__clang_hip_cmath.hip (+8-8)
  • (modified) clang/test/Headers/__clang_hip_math.hip (+80-80)
  • (modified) clang/test/OpenMP/bug54082.c (+12-12)
  • (modified) clang/test/OpenMP/bug56913.c (+2-2)
  • (modified) clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp (+96-96)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+4-5)
  • (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+4-4)
  • (modified) flang/lib/Optimizer/Transforms/StackArrays.cpp (+2-2)
  • (modified) flang/test/Transforms/stack-arrays-lifetime.fir (+4-4)
  • (modified) llvm/docs/LangRef.rst (+4-8)
  • (modified) llvm/include/llvm/Analysis/StackLifetime.h (-2)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+2-3)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+3-7)
  • (modified) llvm/include/llvm/IR/IRBuilder.h (+2-7)
  • (modified) llvm/include/llvm/IR/Intrinsics.td (+6-10)
  • (modified) llvm/lib/Analysis/MemoryDependenceAnalysis.cpp (+2-6)
  • (modified) llvm/lib/Analysis/MemoryLocation.cpp (+11-1)
  • (modified) llvm/lib/Analysis/StackLifetime.cpp (+1-41)
  • (modified) llvm/lib/CodeGen/AtomicExpandPass.cpp (+6-7)
  • (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+10-5)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+3-9)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-4)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp (-2)
  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+13-13)
  • (modified) llvm/lib/IR/IRBuilder.cpp (+4-16)
  • (modified) llvm/lib/IR/Verifier.cpp (+1-1)
  • (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+1-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp (+13-16)
  • (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+1-1)
  • (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+6-15)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+8-12)
  • (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+3-6)
  • (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+13-40)
  • (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+4-23)
  • (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+2-4)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+5-25)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp (+1-1)
  • (modified) llvm/test/Analysis/BasicAA/modref.ll (+5-5)
  • (modified) llvm/test/Analysis/BasicAA/phi-values-usage.ll (+2-2)
  • (modified) llvm/test/Analysis/CallGraph/ignore-assumelike-calls.ll (+2-2)
  • (modified) llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll (+1-2)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+8-8)
  • (modified) llvm/test/Analysis/KernelInfo/openmp/nvptx.ll (+9-9)
  • (modified) llvm/test/Analysis/LazyValueAnalysis/invalidation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Analysis/MemorySSA/phi-translation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/pr43044.ll (+1-1)
  • (modified) llvm/test/Analysis/MemorySSA/pr49859.ll (+11-11)
  • (modified) llvm/test/Analysis/MemorySSA/renamephis.ll (+1-1)
  • (modified) llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/sdiv.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/srem.ll (+4-4)
  • (modified) llvm/test/Analysis/ScopedNoAliasAA/alias-scope-merging.ll (+4-4)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll (+205-226)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/local.ll (+28-28)
  • (modified) llvm/test/Assembler/auto_upgrade_intrinsics.ll (+6-6)
  • (modified) llvm/test/Assembler/autoupgrade-lifetime-intrinsics.ll (+11-6)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/vararg.mir (+1-1)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-initializer-merge.ll (+42-42)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-merge-past-memcpy.mir (+4-4)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-untag-placement.ll (+7-7)
  • (modified) llvm/test/CodeGen/AMDGPU/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/BPF/loop-exit-cond.ll (+8-8)
  • (modified) llvm/test/CodeGen/BPF/vla.ll (+10-10)
  • (modified) llvm/test/CodeGen/NVPTX/frameindex-lifetime.ll (+2-2)
  • (modified) llvm/test/CodeGen/NVPTX/variadics-lowering.ll (+8-8)
  • (modified) llvm/test/CodeGen/SPIRV/llvm-intrinsics/lifetime.ll (+14-12)
  • (modified) llvm/test/CodeGen/WebAssembly/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/WebAssembly/returned.ll (+2-2)
  • (modified) llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll (+6-6)
  • (modified) llvm/test/CodeGen/X86/select-optimize.ll (+3-3)
  • (modified) llvm/test/CodeGen/X86/swap.ll (+18-25)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll (+4-7)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime.ll (+12-75)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/remove-memory-effects.ll (+2-2)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/X86/alloca.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-coloring.ll (+6-6)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll (+28-70)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll (+39-39)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/ARM32/vararg-arm32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg-loongarch64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mips.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mipsel.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppc.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppcle.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/RISCV32/vararg-riscv32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/alloca.ll (+10-8)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_call.ll (+10-10)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_debug_info.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_llvm_launder_invariant.ll (+4-4)
  • (modified) llvm/test/Transforms/AddDiscriminators/call.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/PowerPC/cmpxchg.ll (+2-2)
  • (modified) llvm/test/Transforms/AtomicExpand/RISCV/atomicrmw-fp.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/SPARC/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/AtomicExpand/X86/expand-atomic-libcall.ll (+4-4)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack.ll (+14-15)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll (+16-17)
  • (modified) llvm/test/Transforms/Attributor/liveness.ll (+8-8)
  • (modified) llvm/test/Transforms/Attributor/noalias.ll (+14-10)
  • (modified) llvm/test/Transforms/Attributor/openmp_parallel.ll (+39-37)
  • (modified) llvm/test/Transforms/Attributor/reduced/register_benchmark_test.ll (+2-2)
  • (modified) llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll (+60-58)
  • (modified) llvm/test/Transforms/CodeExtractor/LoopExtractor_alloca.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca2.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca4.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca5.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineInvokeProducesOutVal.ll (+2-2)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_gep.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_hoist.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_multiple.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_unsafe.ll (+8-8)
  • (modified) llvm/test/Transforms/CodeGenPrepare/ARM/tailcall-dup.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeGenPrepare/X86/tailcall-assume-xbb.ll (+4-4)
  • (modified) llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-intrinsics.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-06.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-07.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-08.ll (+6-6)
  • (removed) llvm/test/Transforms/Coroutines/coro-alloca-09.ll (-57)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-infinite-loop-bug.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-start-bug.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-byval-param.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-elide-musttail.ll (+1-1)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-00.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-01.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-03.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-04.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-05.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-lifetime-end.ll (+7-7)
  • (modified) llvm/test/Transforms/Coroutines/coro-only-destroy-when-complete.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-02.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-dbg.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail-chain-pgo-counter-promo.ll (+11-11)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail5.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail6.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail7.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-no-lifetime.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-01.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-02.ll (+5-5)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-03.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-04.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-transform-must-elide.ll (+2-2)
  • (modified) llvm/test/Transforms/CorrelatedValuePropagation/alloca.ll (+4-4)
  • (modified) llvm/test/Transforms/DCE/basic.ll (+4-4)
  • (modified) llvm/test/Transforms/DeadStoreElimination/batchaa-caching-new-pointers.ll (+18-18)
  • (modified) llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/dominate.ll (+3-3)
  • (modified) llvm/test/Transforms/DeadStoreElimination/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/DeadStoreElimination/lifetime.ll (+8-116)
  • (modified) llvm/test/Transforms/DeadStoreElimination/memcpy-lifetimes.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-loop-carried-dependence.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll (+2-2)
  • (modified) llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/simple.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll (+10-10)
  • (modified) llvm/test/Transforms/EarlyCSE/memoryssa.ll (+20-20)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-linkage.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-simple.ll (+16-16)
  • (modified) llvm/test/Transforms/ExpandVariadics/indirect-calls.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/intrinsics.ll (+22-22)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-byval-byref.ll (+12-12)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-indirect.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-integers.ll (+30-30)
  • (modified) llvm/test/Transforms/GVN/cond_br2.ll (+4-4)
  • (modified) llvm/test/Transforms/GVN/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Transforms/GVN/opt-remarks.ll (+2-2)
  • (modified) llvm/test/Transforms/GVN/vscale.ll (+6-6)
  • (modified) llvm/test/Transforms/GVNHoist/pr29034.ll (+2-2)
  • (modified) llvm/test/Transforms/GVNSink/lifetime.ll (+13-13)
  • (modified) llvm/test/Transforms/GlobalOpt/dead-store-status.ll (+4-4)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-3.ll (+8-8)
  • (modified) llvm/test/Transforms/HotColdSplit/sink-multiple-bitcasts-of-allocas-pr42451.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace-1.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/different-intrinsics.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/different-order-phi-merges.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/duplicate-merging-phis.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/exit-block-phi-node-value-attribution.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/exit-phi-nodes-incoming-value-constant-argument.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/extraction.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/gvn-output-set-overload.ll (+6-6)
  • (modified) llvm/test/Transforms/IROutliner/gvn-phi-debug.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/illegal-assumes.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memcpy.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memmove.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-vaarg.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits-not-in-first-outlined.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-outputs-ordering.ll (+10-10)
  • (modified) llvm/test/Transforms/IROutliner/must-capture-all-phi-nodes-begin.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/no-external-block-entries.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/one-external-incoming-block-phi-node.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/outline-memcpy.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-memmove.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-vaarg-intrinsic.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-bitcasts.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-branches-phi-nodes.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-cost-model.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-different-output-blocks.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-exits-to-phi-node.ll (+4-4)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3f784fc8e798f..1254b0f38966a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5981,8 +5981,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
 
     // Create a temporary array to hold the sizes of local pointer arguments
     // for the block. \p First is the position of the first size argument.
-    auto CreateArrayForSizeVar = [=](unsigned First)
-        -> std::tuple<llvm::Value *, llvm::Value *, llvm::Value *> {
+    auto CreateArrayForSizeVar =
+        [=](unsigned First) -> std::pair<llvm::Value *, llvm::Value *> {
       llvm::APInt ArraySize(32, NumArgs - First);
       QualType SizeArrayTy = getContext().getConstantArrayType(
           getContext().getSizeType(), ArraySize, nullptr,
@@ -5995,9 +5995,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       // actually the Alloca ascasted to the default AS, hence the
       // stripPointerCasts()
       llvm::Value *Alloca = TmpPtr->stripPointerCasts();
-      llvm::Value *TmpSize = EmitLifetimeStart(
-          CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), Alloca);
       llvm::Value *ElemPtr;
+      EmitLifetimeStart(Alloca);
       // Each of the following arguments specifies the size of the corresponding
       // argument passed to the enqueued block.
       auto *Zero = llvm::ConstantInt::get(IntTy, 0);
@@ -6014,7 +6013,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       }
       // Return the Alloca itself rather than a potential ascast as this is only
       // used by the paired EmitLifetimeEnd.
-      return {ElemPtr, TmpSize, Alloca};
+      return {ElemPtr, Alloca};
     };
 
     // Could have events and/or varargs.
@@ -6026,7 +6025,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::Value *Kernel =
           Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
       auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(4);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(4);
 
       // Create a vector of the arguments, as well as a constant value to
       // express to the runtime the number of variadic arguments.
@@ -6041,8 +6040,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     // Any calls now have event arguments passed.
@@ -6107,15 +6105,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       ArgTys.push_back(Int32Ty);
       Name = "__enqueue_kernel_events_varargs";
 
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(7);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(7);
       Args.push_back(ElemPtr);
       ArgTys.push_back(ElemPtr->getType());
 
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     llvm_unreachable("Unexpected enqueue_kernel signature");
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d9bd443455e0f..6e0c2c11a9f3b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4319,10 +4319,7 @@ static void emitWriteback(CodeGenFunction &CGF,
 
   if (writeback.WritebackExpr) {
     CGF.EmitIgnoredExpr(writeback.WritebackExpr);
-
-    if (writeback.LifetimeSz)
-      CGF.EmitLifetimeEnd(writeback.LifetimeSz,
-                          writeback.Temporary.getBasePointer());
+    CGF.EmitLifetimeEnd(writeback.Temporary.getBasePointer());
     return;
   }
 
@@ -5282,7 +5279,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  llvm::Value *UnusedReturnSizePtr = nullptr;
+  bool NeedSRetLifetimeEnd = false;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
     // For virtual function pointer thunks and musttail calls, we must always
     // forward an incoming SRet pointer to the callee, because a local alloca
@@ -5296,11 +5293,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       SRetPtr = ReturnValue.getAddress();
     } else {
       SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
-      if (HaveInsertPoint() && ReturnValue.isUnused()) {
-        llvm::TypeSize size =
-            CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-        UnusedReturnSizePtr = EmitLifetimeStart(size, SRetPtr.getBasePointer());
-      }
+      if (HaveInsertPoint() && ReturnValue.isUnused())
+        NeedSRetLifetimeEnd = EmitLifetimeStart(SRetPtr.getBasePointer());
     }
     if (IRFunctionArgs.hasSRetArg()) {
       // A mismatch between the allocated return value's AS and the target's
@@ -5484,15 +5478,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         Val = Builder.CreateFreeze(Val);
       IRCallArgs[FirstIRArg] = Val;
 
-      // Emit lifetime markers for the temporary alloca.
-      llvm::TypeSize ByvalTempElementSize =
-          CGM.getDataLayout().getTypeAllocSize(AI.getElementType());
-      llvm::Value *LifetimeSize =
-          EmitLifetimeStart(ByvalTempElementSize, AI.getPointer());
-
-      // Add cleanup code to emit the end lifetime marker after the call.
-      if (LifetimeSize) // In case we disabled lifetime markers.
-        CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
+      // Emit lifetime markers for the temporary alloca and add cleanup code to
+      // emit the end lifetime marker after the call.
+      if (EmitLifetimeStart(AI.getPointer()))
+        CallLifetimeEndAfterCall.emplace_back(AI);
 
       // Generate the copy.
       I->copyInto(*this, AI);
@@ -5653,9 +5642,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       auto unpaddedCoercionType = ArgInfo.getUnpaddedCoerceAndExpandType();
       auto *unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoercionType);
 
-      llvm::Value *tempSize = nullptr;
       Address addr = Address::invalid();
       RawAddress AllocaAddr = RawAddress::invalid();
+      bool NeedLifetimeEnd = false;
       if (I->isAggregate()) {
         addr = I->hasLValue() ? I->getKnownLValue().getAddress()
                               : I->getKnownRValue().getAggregateAddress();
@@ -5665,7 +5654,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         assert(RV.isScalar()); // complex should always just be direct
 
         llvm::Type *scalarType = RV.getScalarVal()->getType();
-        auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
         auto scalarAlign = CGM.getDataLayout().getPrefTypeAlign(scalarType);
 
         // Materialize to a temporary.
@@ -5674,7 +5662,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
                                     layout->getAlignment(), scalarAlign)),
                                 "tmp",
                                 /*ArraySize=*/nullptr, &AllocaAddr);
-        tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
+        NeedLifetimeEnd = EmitLifetimeStart(AllocaAddr.getPointer());
 
         Builder.CreateStore(RV.getScalarVal(), addr);
       }
@@ -5699,10 +5687,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       }
       assert(IRArgPos == FirstIRArg + NumIRArgs);
 
-      if (tempSize) {
-        EmitLifetimeEnd(tempSize, AllocaAddr.getPointer());
-      }
-
+      if (NeedLifetimeEnd)
+        EmitLifetimeEnd(AllocaAddr.getPointer());
       break;
     }
 
@@ -5871,9 +5857,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // can't depend on being inside of an ExprWithCleanups, so we need to manually
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
-  if (UnusedReturnSizePtr)
-    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr,
-                                         UnusedReturnSizePtr);
+  if (NeedSRetLifetimeEnd)
+    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
 
@@ -6007,7 +5992,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // insertion point; this allows the rest of IRGen to discard
   // unreachable code.
   if (CI->doesNotReturn()) {
-    if (UnusedReturnSizePtr)
+    if (NeedSRetLifetimeEnd)
       PopCleanupBlock();
 
     // Strip away the noreturn attribute to better diagnose unreachable UB.
@@ -6122,7 +6107,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       case ABIArgInfo::InAlloca:
       case ABIArgInfo::Indirect: {
         RValue ret = convertTempToRValue(SRetPtr, RetTy, SourceLocation());
-        if (UnusedReturnSizePtr)
+        if (NeedSRetLifetimeEnd)
           PopCleanupBlock();
         return ret;
       }
diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 0b4e3f9cb0365..3157b7f16f294 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -289,9 +289,6 @@ class CallArgList : public SmallVector<CallArg, 8> {
     /// An Expression (optional) that performs the writeback with any required
     /// casting.
     const Expr *WritebackExpr;
-
-    // Size for optional lifetime end on the temporary.
-    llvm::Value *LifetimeSz;
   };
 
   struct CallArgCleanup {
@@ -321,9 +318,8 @@ class CallArgList : public SmallVector<CallArg, 8> {
   }
 
   void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse,
-                    const Expr *writebackExpr = nullptr,
-                    llvm::Value *lifetimeSz = nullptr) {
-    Writeback writeback = {srcLV, temporary, toUse, writebackExpr, lifetimeSz};
+                    const Expr *writebackExpr = nullptr) {
+    Writeback writeback = {srcLV, temporary, toUse, writebackExpr};
     Writebacks.push_back(writeback);
   }
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 04f13c7d7a6a3..d224b09522d86 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1347,30 +1347,27 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) {
 }
 
 /// Emit a lifetime.begin marker if some criteria are satisfied.
-/// \return a pointer to the temporary size Value if a marker was emitted, null
-/// otherwise
-llvm::Value *CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
-                                                llvm::Value *Addr) {
+/// \return whether the marker was emitted.
+bool CodeGenFunction::EmitLifetimeStart(llvm::Value *Addr) {
   if (!ShouldEmitLifetimeMarkers)
-    return nullptr;
+    return false;
 
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::Value *SizeV = llvm::ConstantInt::get(
-      Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue());
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {Addr});
   C->setDoesNotThrow();
-  return SizeV;
+  return true;
 }
 
-void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
+void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Addr) {
+  if (!ShouldEmitLifetimeMarkers)
+    return;
+
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Addr});
   C->setDoesNotThrow();
 }
 
@@ -1628,9 +1625,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
         // is rare.
         if (!Bypasses.IsBypassed(&D) &&
             !(!getLangOpts().CPlusPlus && hasLabelBeenSeenInCurrentScope())) {
-          llvm::TypeSize Size = CGM.getDataLayout().getTypeAllocSize(allocaTy);
-          emission.SizeForLifetimeMarkers =
-              EmitLifetimeStart(Size, AllocaAddr.getPointer());
+          emission.UseLifetimeMarkers =
+              EmitLifetimeStart(AllocaAddr.getPointer());
         }
       } else {
         assert(!emission.useLifetimeMarkers());
@@ -1723,9 +1719,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
 
   // Make sure we call @llvm.lifetime.end.
   if (emission.useLifetimeMarkers())
-    EHStack.pushCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                         emission.getOriginalAllocatedAddress(),
-                                         emission.getSizeForLifetimeMarkers());
+    EHStack.pushCleanup<CallLifetimeEnd>(
+        NormalEHLifetimeMarker, emission.getOriginalAllocatedAddress());
 
   // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
   // calls for local variables. We are exempting volatile variables and
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 85c768807572f..576307d707b69 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -577,11 +577,9 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
   } else {
     switch (M->getStorageDuration()) {
     case SD_Automatic:
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
+      if (EmitLifetimeStart(Alloca.getPointer())) {
         pushCleanupAfterFullExpr<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                                  Alloca, Size);
+                                                  Alloca);
       }
       break;
 
@@ -612,11 +610,8 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
             Block, llvm::BasicBlock::iterator(Block->back())));
       }
 
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
-        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca,
-                                             Size);
+      if (EmitLifetimeStart(Alloca.getPointer())) {
+        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca);
       }
 
       if (OldConditional) {
@@ -5743,13 +5738,10 @@ LValue CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
   llvm::Value *Addr = TempLV.getAddress().getBasePointer();
   llvm::Type *ElTy = ConvertTypeForMem(TempLV.getType());
 
-  llvm::TypeSize Sz = CGM.getDataLayout().getTypeAllocSize(ElTy);
-
-  llvm::Value *LifetimeSize = EmitLifetimeStart(Sz, Addr);
+  EmitLifetimeStart(Addr);
 
   Address TmpAddr(Addr, ElTy, TempLV.getAlignment());
-  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast(),
-                    LifetimeSize);
+  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast());
   Args.add(RValue::get(TmpAddr, *this), Ty);
   return TempLV;
 }
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index cad6731173700..e2f11b86b2053 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -300,16 +300,12 @@ void AggExprEmitter::withReturnValueSlot(
   Address RetAddr = Address::invalid();
 
   EHScopeStack::stable_iterator LifetimeEndBlock;
-  llvm::Value *LifetimeSizePtr = nullptr;
   llvm::IntrinsicInst *LifetimeStartInst = nullptr;
   if (!UseTemp) {
     RetAddr = Dest.getAddress();
   } else {
     RetAddr = CGF.CreateMemTempWithoutCast(RetTy, "tmp");
-    llvm::TypeSize Size =
-        CGF.CGM.getDataLayout().getTypeAllocSize(CGF.ConvertTypeForMem(RetTy));
-    LifetimeSizePtr = CGF.EmitLifetimeStart(Size, RetAddr.getBasePointer());
-    if (LifetimeSizePtr) {
+    if (CGF.EmitLifetimeStart(RetAddr.getBasePointer())) {
       LifetimeStartInst =
           cast<llvm::IntrinsicInst>(std::prev(Builder.GetInsertPoint()));
       assert(LifetimeStartInst->getIntrinsicID() ==
@@ -317,7 +313,7 @@ void AggExprEmitter::withReturnValueSlot(
              "Last insertion wasn't a lifetime.start?");
 
       CGF.pushFullExprCleanup<CodeGenFunction::CallLifetimeEnd>(
-          NormalEHLifetimeMarker, RetAddr, LifetimeSizePtr);
+          NormalEHLifetimeMarker, RetAddr);
       LifetimeEndBlock = CGF.EHStack.stable_begin();
     }
   }
@@ -338,7 +334,7 @@ void AggExprEmitter::withReturnValueSlot(
     // Since we're not guaranteed to be in an ExprWithCleanups, clean up
     // eagerly.
     CGF.DeactivateCleanupBlock(LifetimeEndBlock, LifetimeStartInst);
-    CGF.EmitLifetimeEnd(LifetimeSizePtr, RetAddr.getBasePointer());
+    CGF.EmitLifetimeEnd(RetAddr.getBasePointer());
   }
 }
 
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 6c32c98cec011..272587f7fa4b5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -701,14 +701,12 @@ class CodeGenFunction : public CodeGenTypeCache {
     bool isRedundantBeforeReturn() override { return true; }
 
     llvm::Value *Addr;
-    llvm::Value *Size;
 
   public:
-    CallLifetimeEnd(RawAddress addr, llvm::Value *size)
-        : Addr(addr.getPointer()), Size(size) {}
+    CallLifetimeEnd(RawAddress addr) : Addr(addr.getPointer()) {}
 
     void Emit(CodeGenFunction &CGF, Flags flags) override {
-      CGF.EmitLifetimeEnd(Size, Addr);
+      CGF.EmitLifetimeEnd(Addr);
     }
   };
 
@@ -3233,8 +3231,8 @@ class CodeGenFunction : public CodeGenTypeCache {
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
 
-  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
-  void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
+  bool EmitLifetimeStart(llvm::Value *Addr);
+  void EmitLifetimeEnd(llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
@@ -3417,8 +3415,8 @@ class CodeGenFunction : public CodeGenTypeCache {
     /// initializer.
     bool IsConstantAggregate;
 
-    /// Non-null if we should use lifetime annotations.
-    llvm::Value *SizeForLifetimeMarkers;
+    /// True if lifetime markers should be used.
+    bool UseLifetimeMarkers;
 
     /// Address with original alloca instruction. Invalid if the variable was
     /// emitted as a global constant.
@@ -3432,20 +3430,14 @@ class CodeGenFunction : public CodeGenTypeCache {
     AutoVarEmission(const VarDecl &variable)
         : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
           IsEscapingByRef(false), IsConstantAggregate(false),
-          SizeForLifetimeMarkers(nullptr), AllocaAddr(RawAddress::invalid()) {}
+          UseLifetimeMarkers(false), AllocaAddr(RawAddress::invalid()) {}
 
     bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
 
   public:
     static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
 
-    bool useLifetimeMarkers() const {
-      return SizeForLifetimeMarkers != nullptr;
-    }
-    llvm::Value *getSizeForLifetimeMarkers() const {
-      assert(useLifetimeMarkers());
-      return SizeForLifetimeMarkers;
-    }
+    bool useLifetimeMarkers() const { return UseLifetimeMarkers; }
 
     /// Returns the raw, allocated address, which is not necessarily
     /// the address of the object itself. It is casted to default
diff --git a/clang/test/C/C11/n1285_1.c b/clang/test/C/C11/n1285_1.c
index 50100042e82fd..25b68e3145b04 100644
--- a/clang/test/C/C11/n1285_1.c
+++ b/clang/test/C/C11/n1285_1.c
@@ -26,16 +26,16 @@ struct X f(void);
 ...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

@llvm/pr-subscribers-backend-webassembly

Author: Nikita Popov (nikic)

Changes

Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).


Patch is 1.54 MiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/150248.diff

479 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-11)
  • (modified) clang/lib/CodeGen/CGCall.cpp (+16-31)
  • (modified) clang/lib/CodeGen/CGCall.h (+2-6)
  • (modified) clang/lib/CodeGen/CGDecl.cpp (+14-19)
  • (modified) clang/lib/CodeGen/CGExpr.cpp (+6-14)
  • (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3-7)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+8-16)
  • (modified) clang/test/C/C11/n1285_1.c (+22-22)
  • (modified) clang/test/CodeGen/AArch64/ABI-align-packed.c (+28-28)
  • (modified) clang/test/CodeGen/AArch64/byval-temp.c (+12-12)
  • (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+5-5)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+2-2)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp (+2-2)
  • (modified) clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp (+4-4)
  • (modified) clang/test/CodeGen/aggregate-assign-call.c (+11-11)
  • (modified) clang/test/CodeGen/attr-counted-by.c (+4-4)
  • (modified) clang/test/CodeGen/cleanup-destslot-simple.c (+12-12)
  • (modified) clang/test/CodeGen/dominating-store-to-return.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime-sanitizer.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime2.c (+9-9)
  • (modified) clang/test/CodeGen/lifetime3.cpp (+8-8)
  • (modified) clang/test/CodeGen/math-libcalls-tbaa.c (+6-6)
  • (modified) clang/test/CodeGen/nofpclass.c (+4-4)
  • (modified) clang/test/CodeGen/temporary-lifetime-exceptions.cpp (+6-6)
  • (modified) clang/test/CodeGen/temporary-lifetime.cpp (+24-24)
  • (modified) clang/test/CodeGen/union-tbaa1.c (+2-2)
  • (modified) clang/test/CodeGenCXX/amdgcn_declspec_get.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+20-20)
  • (modified) clang/test/CodeGenCXX/destructors.cpp (+7-7)
  • (modified) clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/stack-reuse-exceptions.cpp (+30-30)
  • (modified) clang/test/CodeGenCXX/stack-reuse-miscompile.cpp (+3-3)
  • (modified) clang/test/CodeGenObjC/arc-blocks.m (+9-9)
  • (modified) clang/test/CodeGenObjC/arc-precise-lifetime.m (+34-34)
  • (modified) clang/test/CodeGenObjC/arc-ternary-op.m (+6-6)
  • (modified) clang/test/CodeGenObjC/arc.m (+51-51)
  • (modified) clang/test/CodeGenObjC/exceptions.m (+2-2)
  • (modified) clang/test/CodeGenObjCXX/arc-move.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/arc-references.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/arc.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/literals.mm (+6-6)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl (+16-16)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-printf.cl (+2-2)
  • (modified) clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (+14-14)
  • (modified) clang/test/CodeGenOpenCL/implicit-addrspacecast-function-parameter.cl (+2-2)
  • (modified) clang/test/Headers/__clang_hip_cmath.hip (+8-8)
  • (modified) clang/test/Headers/__clang_hip_math.hip (+80-80)
  • (modified) clang/test/OpenMP/bug54082.c (+12-12)
  • (modified) clang/test/OpenMP/bug56913.c (+2-2)
  • (modified) clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp (+96-96)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+4-5)
  • (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+4-4)
  • (modified) flang/lib/Optimizer/Transforms/StackArrays.cpp (+2-2)
  • (modified) flang/test/Transforms/stack-arrays-lifetime.fir (+4-4)
  • (modified) llvm/docs/LangRef.rst (+4-8)
  • (modified) llvm/include/llvm/Analysis/StackLifetime.h (-2)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+2-3)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+3-7)
  • (modified) llvm/include/llvm/IR/IRBuilder.h (+2-7)
  • (modified) llvm/include/llvm/IR/Intrinsics.td (+6-10)
  • (modified) llvm/lib/Analysis/MemoryDependenceAnalysis.cpp (+2-6)
  • (modified) llvm/lib/Analysis/MemoryLocation.cpp (+11-1)
  • (modified) llvm/lib/Analysis/StackLifetime.cpp (+1-41)
  • (modified) llvm/lib/CodeGen/AtomicExpandPass.cpp (+6-7)
  • (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+10-5)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+3-9)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-4)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp (-2)
  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+13-13)
  • (modified) llvm/lib/IR/IRBuilder.cpp (+4-16)
  • (modified) llvm/lib/IR/Verifier.cpp (+1-1)
  • (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+1-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp (+13-16)
  • (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+1-1)
  • (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+6-15)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+8-12)
  • (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+3-6)
  • (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+13-40)
  • (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+4-23)
  • (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+2-4)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+5-25)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp (+1-1)
  • (modified) llvm/test/Analysis/BasicAA/modref.ll (+5-5)
  • (modified) llvm/test/Analysis/BasicAA/phi-values-usage.ll (+2-2)
  • (modified) llvm/test/Analysis/CallGraph/ignore-assumelike-calls.ll (+2-2)
  • (modified) llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll (+1-2)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+8-8)
  • (modified) llvm/test/Analysis/KernelInfo/openmp/nvptx.ll (+9-9)
  • (modified) llvm/test/Analysis/LazyValueAnalysis/invalidation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Analysis/MemorySSA/phi-translation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/pr43044.ll (+1-1)
  • (modified) llvm/test/Analysis/MemorySSA/pr49859.ll (+11-11)
  • (modified) llvm/test/Analysis/MemorySSA/renamephis.ll (+1-1)
  • (modified) llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/sdiv.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/srem.ll (+4-4)
  • (modified) llvm/test/Analysis/ScopedNoAliasAA/alias-scope-merging.ll (+4-4)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll (+205-226)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/local.ll (+28-28)
  • (modified) llvm/test/Assembler/auto_upgrade_intrinsics.ll (+6-6)
  • (modified) llvm/test/Assembler/autoupgrade-lifetime-intrinsics.ll (+11-6)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/vararg.mir (+1-1)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-initializer-merge.ll (+42-42)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-merge-past-memcpy.mir (+4-4)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-untag-placement.ll (+7-7)
  • (modified) llvm/test/CodeGen/AMDGPU/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/BPF/loop-exit-cond.ll (+8-8)
  • (modified) llvm/test/CodeGen/BPF/vla.ll (+10-10)
  • (modified) llvm/test/CodeGen/NVPTX/frameindex-lifetime.ll (+2-2)
  • (modified) llvm/test/CodeGen/NVPTX/variadics-lowering.ll (+8-8)
  • (modified) llvm/test/CodeGen/SPIRV/llvm-intrinsics/lifetime.ll (+14-12)
  • (modified) llvm/test/CodeGen/WebAssembly/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/WebAssembly/returned.ll (+2-2)
  • (modified) llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll (+6-6)
  • (modified) llvm/test/CodeGen/X86/select-optimize.ll (+3-3)
  • (modified) llvm/test/CodeGen/X86/swap.ll (+18-25)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll (+4-7)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime.ll (+12-75)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/remove-memory-effects.ll (+2-2)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/X86/alloca.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-coloring.ll (+6-6)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll (+28-70)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll (+39-39)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/ARM32/vararg-arm32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg-loongarch64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mips.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mipsel.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppc.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppcle.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/RISCV32/vararg-riscv32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/alloca.ll (+10-8)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_call.ll (+10-10)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_debug_info.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_llvm_launder_invariant.ll (+4-4)
  • (modified) llvm/test/Transforms/AddDiscriminators/call.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/PowerPC/cmpxchg.ll (+2-2)
  • (modified) llvm/test/Transforms/AtomicExpand/RISCV/atomicrmw-fp.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/SPARC/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/AtomicExpand/X86/expand-atomic-libcall.ll (+4-4)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack.ll (+14-15)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll (+16-17)
  • (modified) llvm/test/Transforms/Attributor/liveness.ll (+8-8)
  • (modified) llvm/test/Transforms/Attributor/noalias.ll (+14-10)
  • (modified) llvm/test/Transforms/Attributor/openmp_parallel.ll (+39-37)
  • (modified) llvm/test/Transforms/Attributor/reduced/register_benchmark_test.ll (+2-2)
  • (modified) llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll (+60-58)
  • (modified) llvm/test/Transforms/CodeExtractor/LoopExtractor_alloca.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca2.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca4.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca5.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineInvokeProducesOutVal.ll (+2-2)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_gep.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_hoist.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_multiple.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_unsafe.ll (+8-8)
  • (modified) llvm/test/Transforms/CodeGenPrepare/ARM/tailcall-dup.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeGenPrepare/X86/tailcall-assume-xbb.ll (+4-4)
  • (modified) llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-intrinsics.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-06.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-07.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-08.ll (+6-6)
  • (removed) llvm/test/Transforms/Coroutines/coro-alloca-09.ll (-57)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-infinite-loop-bug.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-start-bug.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-byval-param.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-elide-musttail.ll (+1-1)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-00.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-01.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-03.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-04.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-05.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-lifetime-end.ll (+7-7)
  • (modified) llvm/test/Transforms/Coroutines/coro-only-destroy-when-complete.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-02.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-dbg.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail-chain-pgo-counter-promo.ll (+11-11)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail5.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail6.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail7.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-no-lifetime.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-01.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-02.ll (+5-5)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-03.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-04.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-transform-must-elide.ll (+2-2)
  • (modified) llvm/test/Transforms/CorrelatedValuePropagation/alloca.ll (+4-4)
  • (modified) llvm/test/Transforms/DCE/basic.ll (+4-4)
  • (modified) llvm/test/Transforms/DeadStoreElimination/batchaa-caching-new-pointers.ll (+18-18)
  • (modified) llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/dominate.ll (+3-3)
  • (modified) llvm/test/Transforms/DeadStoreElimination/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/DeadStoreElimination/lifetime.ll (+8-116)
  • (modified) llvm/test/Transforms/DeadStoreElimination/memcpy-lifetimes.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-loop-carried-dependence.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll (+2-2)
  • (modified) llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/simple.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll (+10-10)
  • (modified) llvm/test/Transforms/EarlyCSE/memoryssa.ll (+20-20)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-linkage.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-simple.ll (+16-16)
  • (modified) llvm/test/Transforms/ExpandVariadics/indirect-calls.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/intrinsics.ll (+22-22)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-byval-byref.ll (+12-12)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-indirect.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-integers.ll (+30-30)
  • (modified) llvm/test/Transforms/GVN/cond_br2.ll (+4-4)
  • (modified) llvm/test/Transforms/GVN/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Transforms/GVN/opt-remarks.ll (+2-2)
  • (modified) llvm/test/Transforms/GVN/vscale.ll (+6-6)
  • (modified) llvm/test/Transforms/GVNHoist/pr29034.ll (+2-2)
  • (modified) llvm/test/Transforms/GVNSink/lifetime.ll (+13-13)
  • (modified) llvm/test/Transforms/GlobalOpt/dead-store-status.ll (+4-4)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-3.ll (+8-8)
  • (modified) llvm/test/Transforms/HotColdSplit/sink-multiple-bitcasts-of-allocas-pr42451.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace-1.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/different-intrinsics.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/different-order-phi-merges.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/duplicate-merging-phis.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/exit-block-phi-node-value-attribution.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/exit-phi-nodes-incoming-value-constant-argument.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/extraction.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/gvn-output-set-overload.ll (+6-6)
  • (modified) llvm/test/Transforms/IROutliner/gvn-phi-debug.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/illegal-assumes.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memcpy.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memmove.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-vaarg.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits-not-in-first-outlined.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-outputs-ordering.ll (+10-10)
  • (modified) llvm/test/Transforms/IROutliner/must-capture-all-phi-nodes-begin.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/no-external-block-entries.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/one-external-incoming-block-phi-node.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/outline-memcpy.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-memmove.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-vaarg-intrinsic.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-bitcasts.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-branches-phi-nodes.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-cost-model.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-different-output-blocks.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-exits-to-phi-node.ll (+4-4)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3f784fc8e798f..1254b0f38966a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5981,8 +5981,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
 
     // Create a temporary array to hold the sizes of local pointer arguments
     // for the block. \p First is the position of the first size argument.
-    auto CreateArrayForSizeVar = [=](unsigned First)
-        -> std::tuple<llvm::Value *, llvm::Value *, llvm::Value *> {
+    auto CreateArrayForSizeVar =
+        [=](unsigned First) -> std::pair<llvm::Value *, llvm::Value *> {
       llvm::APInt ArraySize(32, NumArgs - First);
       QualType SizeArrayTy = getContext().getConstantArrayType(
           getContext().getSizeType(), ArraySize, nullptr,
@@ -5995,9 +5995,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       // actually the Alloca ascasted to the default AS, hence the
       // stripPointerCasts()
       llvm::Value *Alloca = TmpPtr->stripPointerCasts();
-      llvm::Value *TmpSize = EmitLifetimeStart(
-          CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), Alloca);
       llvm::Value *ElemPtr;
+      EmitLifetimeStart(Alloca);
       // Each of the following arguments specifies the size of the corresponding
       // argument passed to the enqueued block.
       auto *Zero = llvm::ConstantInt::get(IntTy, 0);
@@ -6014,7 +6013,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       }
       // Return the Alloca itself rather than a potential ascast as this is only
       // used by the paired EmitLifetimeEnd.
-      return {ElemPtr, TmpSize, Alloca};
+      return {ElemPtr, Alloca};
     };
 
     // Could have events and/or varargs.
@@ -6026,7 +6025,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::Value *Kernel =
           Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
       auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(4);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(4);
 
       // Create a vector of the arguments, as well as a constant value to
       // express to the runtime the number of variadic arguments.
@@ -6041,8 +6040,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     // Any calls now have event arguments passed.
@@ -6107,15 +6105,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       ArgTys.push_back(Int32Ty);
       Name = "__enqueue_kernel_events_varargs";
 
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(7);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(7);
       Args.push_back(ElemPtr);
       ArgTys.push_back(ElemPtr->getType());
 
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     llvm_unreachable("Unexpected enqueue_kernel signature");
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d9bd443455e0f..6e0c2c11a9f3b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4319,10 +4319,7 @@ static void emitWriteback(CodeGenFunction &CGF,
 
   if (writeback.WritebackExpr) {
     CGF.EmitIgnoredExpr(writeback.WritebackExpr);
-
-    if (writeback.LifetimeSz)
-      CGF.EmitLifetimeEnd(writeback.LifetimeSz,
-                          writeback.Temporary.getBasePointer());
+    CGF.EmitLifetimeEnd(writeback.Temporary.getBasePointer());
     return;
   }
 
@@ -5282,7 +5279,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  llvm::Value *UnusedReturnSizePtr = nullptr;
+  bool NeedSRetLifetimeEnd = false;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
     // For virtual function pointer thunks and musttail calls, we must always
     // forward an incoming SRet pointer to the callee, because a local alloca
@@ -5296,11 +5293,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       SRetPtr = ReturnValue.getAddress();
     } else {
       SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
-      if (HaveInsertPoint() && ReturnValue.isUnused()) {
-        llvm::TypeSize size =
-            CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-        UnusedReturnSizePtr = EmitLifetimeStart(size, SRetPtr.getBasePointer());
-      }
+      if (HaveInsertPoint() && ReturnValue.isUnused())
+        NeedSRetLifetimeEnd = EmitLifetimeStart(SRetPtr.getBasePointer());
     }
     if (IRFunctionArgs.hasSRetArg()) {
       // A mismatch between the allocated return value's AS and the target's
@@ -5484,15 +5478,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         Val = Builder.CreateFreeze(Val);
       IRCallArgs[FirstIRArg] = Val;
 
-      // Emit lifetime markers for the temporary alloca.
-      llvm::TypeSize ByvalTempElementSize =
-          CGM.getDataLayout().getTypeAllocSize(AI.getElementType());
-      llvm::Value *LifetimeSize =
-          EmitLifetimeStart(ByvalTempElementSize, AI.getPointer());
-
-      // Add cleanup code to emit the end lifetime marker after the call.
-      if (LifetimeSize) // In case we disabled lifetime markers.
-        CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
+      // Emit lifetime markers for the temporary alloca and add cleanup code to
+      // emit the end lifetime marker after the call.
+      if (EmitLifetimeStart(AI.getPointer()))
+        CallLifetimeEndAfterCall.emplace_back(AI);
 
       // Generate the copy.
       I->copyInto(*this, AI);
@@ -5653,9 +5642,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       auto unpaddedCoercionType = ArgInfo.getUnpaddedCoerceAndExpandType();
       auto *unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoercionType);
 
-      llvm::Value *tempSize = nullptr;
       Address addr = Address::invalid();
       RawAddress AllocaAddr = RawAddress::invalid();
+      bool NeedLifetimeEnd = false;
       if (I->isAggregate()) {
         addr = I->hasLValue() ? I->getKnownLValue().getAddress()
                               : I->getKnownRValue().getAggregateAddress();
@@ -5665,7 +5654,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         assert(RV.isScalar()); // complex should always just be direct
 
         llvm::Type *scalarType = RV.getScalarVal()->getType();
-        auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
         auto scalarAlign = CGM.getDataLayout().getPrefTypeAlign(scalarType);
 
         // Materialize to a temporary.
@@ -5674,7 +5662,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
                                     layout->getAlignment(), scalarAlign)),
                                 "tmp",
                                 /*ArraySize=*/nullptr, &AllocaAddr);
-        tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
+        NeedLifetimeEnd = EmitLifetimeStart(AllocaAddr.getPointer());
 
         Builder.CreateStore(RV.getScalarVal(), addr);
       }
@@ -5699,10 +5687,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       }
       assert(IRArgPos == FirstIRArg + NumIRArgs);
 
-      if (tempSize) {
-        EmitLifetimeEnd(tempSize, AllocaAddr.getPointer());
-      }
-
+      if (NeedLifetimeEnd)
+        EmitLifetimeEnd(AllocaAddr.getPointer());
       break;
     }
 
@@ -5871,9 +5857,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // can't depend on being inside of an ExprWithCleanups, so we need to manually
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
-  if (UnusedReturnSizePtr)
-    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr,
-                                         UnusedReturnSizePtr);
+  if (NeedSRetLifetimeEnd)
+    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
 
@@ -6007,7 +5992,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // insertion point; this allows the rest of IRGen to discard
   // unreachable code.
   if (CI->doesNotReturn()) {
-    if (UnusedReturnSizePtr)
+    if (NeedSRetLifetimeEnd)
       PopCleanupBlock();
 
     // Strip away the noreturn attribute to better diagnose unreachable UB.
@@ -6122,7 +6107,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       case ABIArgInfo::InAlloca:
       case ABIArgInfo::Indirect: {
         RValue ret = convertTempToRValue(SRetPtr, RetTy, SourceLocation());
-        if (UnusedReturnSizePtr)
+        if (NeedSRetLifetimeEnd)
           PopCleanupBlock();
         return ret;
       }
diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 0b4e3f9cb0365..3157b7f16f294 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -289,9 +289,6 @@ class CallArgList : public SmallVector<CallArg, 8> {
     /// An Expression (optional) that performs the writeback with any required
     /// casting.
     const Expr *WritebackExpr;
-
-    // Size for optional lifetime end on the temporary.
-    llvm::Value *LifetimeSz;
   };
 
   struct CallArgCleanup {
@@ -321,9 +318,8 @@ class CallArgList : public SmallVector<CallArg, 8> {
   }
 
   void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse,
-                    const Expr *writebackExpr = nullptr,
-                    llvm::Value *lifetimeSz = nullptr) {
-    Writeback writeback = {srcLV, temporary, toUse, writebackExpr, lifetimeSz};
+                    const Expr *writebackExpr = nullptr) {
+    Writeback writeback = {srcLV, temporary, toUse, writebackExpr};
     Writebacks.push_back(writeback);
   }
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 04f13c7d7a6a3..d224b09522d86 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1347,30 +1347,27 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) {
 }
 
 /// Emit a lifetime.begin marker if some criteria are satisfied.
-/// \return a pointer to the temporary size Value if a marker was emitted, null
-/// otherwise
-llvm::Value *CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
-                                                llvm::Value *Addr) {
+/// \return whether the marker was emitted.
+bool CodeGenFunction::EmitLifetimeStart(llvm::Value *Addr) {
   if (!ShouldEmitLifetimeMarkers)
-    return nullptr;
+    return false;
 
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::Value *SizeV = llvm::ConstantInt::get(
-      Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue());
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {Addr});
   C->setDoesNotThrow();
-  return SizeV;
+  return true;
 }
 
-void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
+void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Addr) {
+  if (!ShouldEmitLifetimeMarkers)
+    return;
+
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Addr});
   C->setDoesNotThrow();
 }
 
@@ -1628,9 +1625,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
         // is rare.
         if (!Bypasses.IsBypassed(&D) &&
             !(!getLangOpts().CPlusPlus && hasLabelBeenSeenInCurrentScope())) {
-          llvm::TypeSize Size = CGM.getDataLayout().getTypeAllocSize(allocaTy);
-          emission.SizeForLifetimeMarkers =
-              EmitLifetimeStart(Size, AllocaAddr.getPointer());
+          emission.UseLifetimeMarkers =
+              EmitLifetimeStart(AllocaAddr.getPointer());
         }
       } else {
         assert(!emission.useLifetimeMarkers());
@@ -1723,9 +1719,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
 
   // Make sure we call @llvm.lifetime.end.
   if (emission.useLifetimeMarkers())
-    EHStack.pushCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                         emission.getOriginalAllocatedAddress(),
-                                         emission.getSizeForLifetimeMarkers());
+    EHStack.pushCleanup<CallLifetimeEnd>(
+        NormalEHLifetimeMarker, emission.getOriginalAllocatedAddress());
 
   // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
   // calls for local variables. We are exempting volatile variables and
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 85c768807572f..576307d707b69 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -577,11 +577,9 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
   } else {
     switch (M->getStorageDuration()) {
     case SD_Automatic:
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
+      if (EmitLifetimeStart(Alloca.getPointer())) {
         pushCleanupAfterFullExpr<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                                  Alloca, Size);
+                                                  Alloca);
       }
       break;
 
@@ -612,11 +610,8 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
             Block, llvm::BasicBlock::iterator(Block->back())));
       }
 
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
-        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca,
-                                             Size);
+      if (EmitLifetimeStart(Alloca.getPointer())) {
+        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca);
       }
 
       if (OldConditional) {
@@ -5743,13 +5738,10 @@ LValue CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
   llvm::Value *Addr = TempLV.getAddress().getBasePointer();
   llvm::Type *ElTy = ConvertTypeForMem(TempLV.getType());
 
-  llvm::TypeSize Sz = CGM.getDataLayout().getTypeAllocSize(ElTy);
-
-  llvm::Value *LifetimeSize = EmitLifetimeStart(Sz, Addr);
+  EmitLifetimeStart(Addr);
 
   Address TmpAddr(Addr, ElTy, TempLV.getAlignment());
-  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast(),
-                    LifetimeSize);
+  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast());
   Args.add(RValue::get(TmpAddr, *this), Ty);
   return TempLV;
 }
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index cad6731173700..e2f11b86b2053 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -300,16 +300,12 @@ void AggExprEmitter::withReturnValueSlot(
   Address RetAddr = Address::invalid();
 
   EHScopeStack::stable_iterator LifetimeEndBlock;
-  llvm::Value *LifetimeSizePtr = nullptr;
   llvm::IntrinsicInst *LifetimeStartInst = nullptr;
   if (!UseTemp) {
     RetAddr = Dest.getAddress();
   } else {
     RetAddr = CGF.CreateMemTempWithoutCast(RetTy, "tmp");
-    llvm::TypeSize Size =
-        CGF.CGM.getDataLayout().getTypeAllocSize(CGF.ConvertTypeForMem(RetTy));
-    LifetimeSizePtr = CGF.EmitLifetimeStart(Size, RetAddr.getBasePointer());
-    if (LifetimeSizePtr) {
+    if (CGF.EmitLifetimeStart(RetAddr.getBasePointer())) {
       LifetimeStartInst =
           cast<llvm::IntrinsicInst>(std::prev(Builder.GetInsertPoint()));
       assert(LifetimeStartInst->getIntrinsicID() ==
@@ -317,7 +313,7 @@ void AggExprEmitter::withReturnValueSlot(
              "Last insertion wasn't a lifetime.start?");
 
       CGF.pushFullExprCleanup<CodeGenFunction::CallLifetimeEnd>(
-          NormalEHLifetimeMarker, RetAddr, LifetimeSizePtr);
+          NormalEHLifetimeMarker, RetAddr);
       LifetimeEndBlock = CGF.EHStack.stable_begin();
     }
   }
@@ -338,7 +334,7 @@ void AggExprEmitter::withReturnValueSlot(
     // Since we're not guaranteed to be in an ExprWithCleanups, clean up
     // eagerly.
     CGF.DeactivateCleanupBlock(LifetimeEndBlock, LifetimeStartInst);
-    CGF.EmitLifetimeEnd(LifetimeSizePtr, RetAddr.getBasePointer());
+    CGF.EmitLifetimeEnd(RetAddr.getBasePointer());
   }
 }
 
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 6c32c98cec011..272587f7fa4b5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -701,14 +701,12 @@ class CodeGenFunction : public CodeGenTypeCache {
     bool isRedundantBeforeReturn() override { return true; }
 
     llvm::Value *Addr;
-    llvm::Value *Size;
 
   public:
-    CallLifetimeEnd(RawAddress addr, llvm::Value *size)
-        : Addr(addr.getPointer()), Size(size) {}
+    CallLifetimeEnd(RawAddress addr) : Addr(addr.getPointer()) {}
 
     void Emit(CodeGenFunction &CGF, Flags flags) override {
-      CGF.EmitLifetimeEnd(Size, Addr);
+      CGF.EmitLifetimeEnd(Addr);
     }
   };
 
@@ -3233,8 +3231,8 @@ class CodeGenFunction : public CodeGenTypeCache {
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
 
-  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
-  void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
+  bool EmitLifetimeStart(llvm::Value *Addr);
+  void EmitLifetimeEnd(llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
@@ -3417,8 +3415,8 @@ class CodeGenFunction : public CodeGenTypeCache {
     /// initializer.
     bool IsConstantAggregate;
 
-    /// Non-null if we should use lifetime annotations.
-    llvm::Value *SizeForLifetimeMarkers;
+    /// True if lifetime markers should be used.
+    bool UseLifetimeMarkers;
 
     /// Address with original alloca instruction. Invalid if the variable was
     /// emitted as a global constant.
@@ -3432,20 +3430,14 @@ class CodeGenFunction : public CodeGenTypeCache {
     AutoVarEmission(const VarDecl &variable)
         : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
           IsEscapingByRef(false), IsConstantAggregate(false),
-          SizeForLifetimeMarkers(nullptr), AllocaAddr(RawAddress::invalid()) {}
+          UseLifetimeMarkers(false), AllocaAddr(RawAddress::invalid()) {}
 
     bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
 
   public:
     static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
 
-    bool useLifetimeMarkers() const {
-      return SizeForLifetimeMarkers != nullptr;
-    }
-    llvm::Value *getSizeForLifetimeMarkers() const {
-      assert(useLifetimeMarkers());
-      return SizeForLifetimeMarkers;
-    }
+    bool useLifetimeMarkers() const { return UseLifetimeMarkers; }
 
     /// Returns the raw, allocated address, which is not necessarily
     /// the address of the object itself. It is casted to default
diff --git a/clang/test/C/C11/n1285_1.c b/clang/test/C/C11/n1285_1.c
index 50100042e82fd..25b68e3145b04 100644
--- a/clang/test/C/C11/n1285_1.c
+++ b/clang/test/C/C11/n1285_1.c
@@ -26,16 +26,16 @@ struct X f(void);
 ...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Nikita Popov (nikic)

Changes

Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).


Patch is 1.54 MiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/150248.diff

479 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-11)
  • (modified) clang/lib/CodeGen/CGCall.cpp (+16-31)
  • (modified) clang/lib/CodeGen/CGCall.h (+2-6)
  • (modified) clang/lib/CodeGen/CGDecl.cpp (+14-19)
  • (modified) clang/lib/CodeGen/CGExpr.cpp (+6-14)
  • (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3-7)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+8-16)
  • (modified) clang/test/C/C11/n1285_1.c (+22-22)
  • (modified) clang/test/CodeGen/AArch64/ABI-align-packed.c (+28-28)
  • (modified) clang/test/CodeGen/AArch64/byval-temp.c (+12-12)
  • (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+5-5)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+2-2)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp (+2-2)
  • (modified) clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp (+4-4)
  • (modified) clang/test/CodeGen/aggregate-assign-call.c (+11-11)
  • (modified) clang/test/CodeGen/attr-counted-by.c (+4-4)
  • (modified) clang/test/CodeGen/cleanup-destslot-simple.c (+12-12)
  • (modified) clang/test/CodeGen/dominating-store-to-return.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime-sanitizer.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime2.c (+9-9)
  • (modified) clang/test/CodeGen/lifetime3.cpp (+8-8)
  • (modified) clang/test/CodeGen/math-libcalls-tbaa.c (+6-6)
  • (modified) clang/test/CodeGen/nofpclass.c (+4-4)
  • (modified) clang/test/CodeGen/temporary-lifetime-exceptions.cpp (+6-6)
  • (modified) clang/test/CodeGen/temporary-lifetime.cpp (+24-24)
  • (modified) clang/test/CodeGen/union-tbaa1.c (+2-2)
  • (modified) clang/test/CodeGenCXX/amdgcn_declspec_get.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+20-20)
  • (modified) clang/test/CodeGenCXX/destructors.cpp (+7-7)
  • (modified) clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/stack-reuse-exceptions.cpp (+30-30)
  • (modified) clang/test/CodeGenCXX/stack-reuse-miscompile.cpp (+3-3)
  • (modified) clang/test/CodeGenObjC/arc-blocks.m (+9-9)
  • (modified) clang/test/CodeGenObjC/arc-precise-lifetime.m (+34-34)
  • (modified) clang/test/CodeGenObjC/arc-ternary-op.m (+6-6)
  • (modified) clang/test/CodeGenObjC/arc.m (+51-51)
  • (modified) clang/test/CodeGenObjC/exceptions.m (+2-2)
  • (modified) clang/test/CodeGenObjCXX/arc-move.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/arc-references.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/arc.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/literals.mm (+6-6)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl (+16-16)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-printf.cl (+2-2)
  • (modified) clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (+14-14)
  • (modified) clang/test/CodeGenOpenCL/implicit-addrspacecast-function-parameter.cl (+2-2)
  • (modified) clang/test/Headers/__clang_hip_cmath.hip (+8-8)
  • (modified) clang/test/Headers/__clang_hip_math.hip (+80-80)
  • (modified) clang/test/OpenMP/bug54082.c (+12-12)
  • (modified) clang/test/OpenMP/bug56913.c (+2-2)
  • (modified) clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp (+96-96)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+4-5)
  • (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+4-4)
  • (modified) flang/lib/Optimizer/Transforms/StackArrays.cpp (+2-2)
  • (modified) flang/test/Transforms/stack-arrays-lifetime.fir (+4-4)
  • (modified) llvm/docs/LangRef.rst (+4-8)
  • (modified) llvm/include/llvm/Analysis/StackLifetime.h (-2)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+2-3)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+3-7)
  • (modified) llvm/include/llvm/IR/IRBuilder.h (+2-7)
  • (modified) llvm/include/llvm/IR/Intrinsics.td (+6-10)
  • (modified) llvm/lib/Analysis/MemoryDependenceAnalysis.cpp (+2-6)
  • (modified) llvm/lib/Analysis/MemoryLocation.cpp (+11-1)
  • (modified) llvm/lib/Analysis/StackLifetime.cpp (+1-41)
  • (modified) llvm/lib/CodeGen/AtomicExpandPass.cpp (+6-7)
  • (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+10-5)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+3-9)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-4)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp (-2)
  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+13-13)
  • (modified) llvm/lib/IR/IRBuilder.cpp (+4-16)
  • (modified) llvm/lib/IR/Verifier.cpp (+1-1)
  • (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+1-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp (+13-16)
  • (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+1-1)
  • (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+6-15)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+8-12)
  • (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+3-6)
  • (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+13-40)
  • (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+4-23)
  • (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+2-4)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+5-25)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp (+1-1)
  • (modified) llvm/test/Analysis/BasicAA/modref.ll (+5-5)
  • (modified) llvm/test/Analysis/BasicAA/phi-values-usage.ll (+2-2)
  • (modified) llvm/test/Analysis/CallGraph/ignore-assumelike-calls.ll (+2-2)
  • (modified) llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll (+1-2)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+8-8)
  • (modified) llvm/test/Analysis/KernelInfo/openmp/nvptx.ll (+9-9)
  • (modified) llvm/test/Analysis/LazyValueAnalysis/invalidation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Analysis/MemorySSA/phi-translation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/pr43044.ll (+1-1)
  • (modified) llvm/test/Analysis/MemorySSA/pr49859.ll (+11-11)
  • (modified) llvm/test/Analysis/MemorySSA/renamephis.ll (+1-1)
  • (modified) llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/sdiv.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/srem.ll (+4-4)
  • (modified) llvm/test/Analysis/ScopedNoAliasAA/alias-scope-merging.ll (+4-4)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll (+205-226)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/local.ll (+28-28)
  • (modified) llvm/test/Assembler/auto_upgrade_intrinsics.ll (+6-6)
  • (modified) llvm/test/Assembler/autoupgrade-lifetime-intrinsics.ll (+11-6)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/vararg.mir (+1-1)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-initializer-merge.ll (+42-42)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-merge-past-memcpy.mir (+4-4)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-untag-placement.ll (+7-7)
  • (modified) llvm/test/CodeGen/AMDGPU/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/BPF/loop-exit-cond.ll (+8-8)
  • (modified) llvm/test/CodeGen/BPF/vla.ll (+10-10)
  • (modified) llvm/test/CodeGen/NVPTX/frameindex-lifetime.ll (+2-2)
  • (modified) llvm/test/CodeGen/NVPTX/variadics-lowering.ll (+8-8)
  • (modified) llvm/test/CodeGen/SPIRV/llvm-intrinsics/lifetime.ll (+14-12)
  • (modified) llvm/test/CodeGen/WebAssembly/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/WebAssembly/returned.ll (+2-2)
  • (modified) llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll (+6-6)
  • (modified) llvm/test/CodeGen/X86/select-optimize.ll (+3-3)
  • (modified) llvm/test/CodeGen/X86/swap.ll (+18-25)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll (+4-7)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime.ll (+12-75)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/remove-memory-effects.ll (+2-2)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/X86/alloca.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-coloring.ll (+6-6)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll (+28-70)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll (+39-39)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/ARM32/vararg-arm32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg-loongarch64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mips.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mipsel.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppc.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppcle.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/RISCV32/vararg-riscv32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/alloca.ll (+10-8)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_call.ll (+10-10)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_debug_info.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_llvm_launder_invariant.ll (+4-4)
  • (modified) llvm/test/Transforms/AddDiscriminators/call.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/PowerPC/cmpxchg.ll (+2-2)
  • (modified) llvm/test/Transforms/AtomicExpand/RISCV/atomicrmw-fp.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/SPARC/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/AtomicExpand/X86/expand-atomic-libcall.ll (+4-4)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack.ll (+14-15)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll (+16-17)
  • (modified) llvm/test/Transforms/Attributor/liveness.ll (+8-8)
  • (modified) llvm/test/Transforms/Attributor/noalias.ll (+14-10)
  • (modified) llvm/test/Transforms/Attributor/openmp_parallel.ll (+39-37)
  • (modified) llvm/test/Transforms/Attributor/reduced/register_benchmark_test.ll (+2-2)
  • (modified) llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll (+60-58)
  • (modified) llvm/test/Transforms/CodeExtractor/LoopExtractor_alloca.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca2.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca4.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca5.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineInvokeProducesOutVal.ll (+2-2)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_gep.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_hoist.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_multiple.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_unsafe.ll (+8-8)
  • (modified) llvm/test/Transforms/CodeGenPrepare/ARM/tailcall-dup.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeGenPrepare/X86/tailcall-assume-xbb.ll (+4-4)
  • (modified) llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-intrinsics.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-06.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-07.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-08.ll (+6-6)
  • (removed) llvm/test/Transforms/Coroutines/coro-alloca-09.ll (-57)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-infinite-loop-bug.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-start-bug.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-byval-param.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-elide-musttail.ll (+1-1)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-00.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-01.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-03.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-04.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-05.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-lifetime-end.ll (+7-7)
  • (modified) llvm/test/Transforms/Coroutines/coro-only-destroy-when-complete.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-02.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-dbg.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail-chain-pgo-counter-promo.ll (+11-11)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail5.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail6.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail7.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-no-lifetime.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-01.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-02.ll (+5-5)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-03.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-04.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-transform-must-elide.ll (+2-2)
  • (modified) llvm/test/Transforms/CorrelatedValuePropagation/alloca.ll (+4-4)
  • (modified) llvm/test/Transforms/DCE/basic.ll (+4-4)
  • (modified) llvm/test/Transforms/DeadStoreElimination/batchaa-caching-new-pointers.ll (+18-18)
  • (modified) llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/dominate.ll (+3-3)
  • (modified) llvm/test/Transforms/DeadStoreElimination/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/DeadStoreElimination/lifetime.ll (+8-116)
  • (modified) llvm/test/Transforms/DeadStoreElimination/memcpy-lifetimes.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-loop-carried-dependence.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll (+2-2)
  • (modified) llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/simple.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll (+10-10)
  • (modified) llvm/test/Transforms/EarlyCSE/memoryssa.ll (+20-20)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-linkage.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-simple.ll (+16-16)
  • (modified) llvm/test/Transforms/ExpandVariadics/indirect-calls.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/intrinsics.ll (+22-22)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-byval-byref.ll (+12-12)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-indirect.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-integers.ll (+30-30)
  • (modified) llvm/test/Transforms/GVN/cond_br2.ll (+4-4)
  • (modified) llvm/test/Transforms/GVN/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Transforms/GVN/opt-remarks.ll (+2-2)
  • (modified) llvm/test/Transforms/GVN/vscale.ll (+6-6)
  • (modified) llvm/test/Transforms/GVNHoist/pr29034.ll (+2-2)
  • (modified) llvm/test/Transforms/GVNSink/lifetime.ll (+13-13)
  • (modified) llvm/test/Transforms/GlobalOpt/dead-store-status.ll (+4-4)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-3.ll (+8-8)
  • (modified) llvm/test/Transforms/HotColdSplit/sink-multiple-bitcasts-of-allocas-pr42451.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace-1.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/different-intrinsics.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/different-order-phi-merges.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/duplicate-merging-phis.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/exit-block-phi-node-value-attribution.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/exit-phi-nodes-incoming-value-constant-argument.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/extraction.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/gvn-output-set-overload.ll (+6-6)
  • (modified) llvm/test/Transforms/IROutliner/gvn-phi-debug.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/illegal-assumes.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memcpy.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memmove.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-vaarg.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits-not-in-first-outlined.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-outputs-ordering.ll (+10-10)
  • (modified) llvm/test/Transforms/IROutliner/must-capture-all-phi-nodes-begin.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/no-external-block-entries.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/one-external-incoming-block-phi-node.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/outline-memcpy.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-memmove.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-vaarg-intrinsic.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-bitcasts.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-branches-phi-nodes.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-cost-model.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-different-output-blocks.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-exits-to-phi-node.ll (+4-4)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3f784fc8e798f..1254b0f38966a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5981,8 +5981,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
 
     // Create a temporary array to hold the sizes of local pointer arguments
     // for the block. \p First is the position of the first size argument.
-    auto CreateArrayForSizeVar = [=](unsigned First)
-        -> std::tuple<llvm::Value *, llvm::Value *, llvm::Value *> {
+    auto CreateArrayForSizeVar =
+        [=](unsigned First) -> std::pair<llvm::Value *, llvm::Value *> {
       llvm::APInt ArraySize(32, NumArgs - First);
       QualType SizeArrayTy = getContext().getConstantArrayType(
           getContext().getSizeType(), ArraySize, nullptr,
@@ -5995,9 +5995,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       // actually the Alloca ascasted to the default AS, hence the
       // stripPointerCasts()
       llvm::Value *Alloca = TmpPtr->stripPointerCasts();
-      llvm::Value *TmpSize = EmitLifetimeStart(
-          CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), Alloca);
       llvm::Value *ElemPtr;
+      EmitLifetimeStart(Alloca);
       // Each of the following arguments specifies the size of the corresponding
       // argument passed to the enqueued block.
       auto *Zero = llvm::ConstantInt::get(IntTy, 0);
@@ -6014,7 +6013,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       }
       // Return the Alloca itself rather than a potential ascast as this is only
       // used by the paired EmitLifetimeEnd.
-      return {ElemPtr, TmpSize, Alloca};
+      return {ElemPtr, Alloca};
     };
 
     // Could have events and/or varargs.
@@ -6026,7 +6025,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::Value *Kernel =
           Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
       auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(4);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(4);
 
       // Create a vector of the arguments, as well as a constant value to
       // express to the runtime the number of variadic arguments.
@@ -6041,8 +6040,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     // Any calls now have event arguments passed.
@@ -6107,15 +6105,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       ArgTys.push_back(Int32Ty);
       Name = "__enqueue_kernel_events_varargs";
 
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(7);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(7);
       Args.push_back(ElemPtr);
       ArgTys.push_back(ElemPtr->getType());
 
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     llvm_unreachable("Unexpected enqueue_kernel signature");
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d9bd443455e0f..6e0c2c11a9f3b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4319,10 +4319,7 @@ static void emitWriteback(CodeGenFunction &CGF,
 
   if (writeback.WritebackExpr) {
     CGF.EmitIgnoredExpr(writeback.WritebackExpr);
-
-    if (writeback.LifetimeSz)
-      CGF.EmitLifetimeEnd(writeback.LifetimeSz,
-                          writeback.Temporary.getBasePointer());
+    CGF.EmitLifetimeEnd(writeback.Temporary.getBasePointer());
     return;
   }
 
@@ -5282,7 +5279,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  llvm::Value *UnusedReturnSizePtr = nullptr;
+  bool NeedSRetLifetimeEnd = false;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
     // For virtual function pointer thunks and musttail calls, we must always
     // forward an incoming SRet pointer to the callee, because a local alloca
@@ -5296,11 +5293,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       SRetPtr = ReturnValue.getAddress();
     } else {
       SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
-      if (HaveInsertPoint() && ReturnValue.isUnused()) {
-        llvm::TypeSize size =
-            CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-        UnusedReturnSizePtr = EmitLifetimeStart(size, SRetPtr.getBasePointer());
-      }
+      if (HaveInsertPoint() && ReturnValue.isUnused())
+        NeedSRetLifetimeEnd = EmitLifetimeStart(SRetPtr.getBasePointer());
     }
     if (IRFunctionArgs.hasSRetArg()) {
       // A mismatch between the allocated return value's AS and the target's
@@ -5484,15 +5478,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         Val = Builder.CreateFreeze(Val);
       IRCallArgs[FirstIRArg] = Val;
 
-      // Emit lifetime markers for the temporary alloca.
-      llvm::TypeSize ByvalTempElementSize =
-          CGM.getDataLayout().getTypeAllocSize(AI.getElementType());
-      llvm::Value *LifetimeSize =
-          EmitLifetimeStart(ByvalTempElementSize, AI.getPointer());
-
-      // Add cleanup code to emit the end lifetime marker after the call.
-      if (LifetimeSize) // In case we disabled lifetime markers.
-        CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
+      // Emit lifetime markers for the temporary alloca and add cleanup code to
+      // emit the end lifetime marker after the call.
+      if (EmitLifetimeStart(AI.getPointer()))
+        CallLifetimeEndAfterCall.emplace_back(AI);
 
       // Generate the copy.
       I->copyInto(*this, AI);
@@ -5653,9 +5642,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       auto unpaddedCoercionType = ArgInfo.getUnpaddedCoerceAndExpandType();
       auto *unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoercionType);
 
-      llvm::Value *tempSize = nullptr;
       Address addr = Address::invalid();
       RawAddress AllocaAddr = RawAddress::invalid();
+      bool NeedLifetimeEnd = false;
       if (I->isAggregate()) {
         addr = I->hasLValue() ? I->getKnownLValue().getAddress()
                               : I->getKnownRValue().getAggregateAddress();
@@ -5665,7 +5654,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         assert(RV.isScalar()); // complex should always just be direct
 
         llvm::Type *scalarType = RV.getScalarVal()->getType();
-        auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
         auto scalarAlign = CGM.getDataLayout().getPrefTypeAlign(scalarType);
 
         // Materialize to a temporary.
@@ -5674,7 +5662,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
                                     layout->getAlignment(), scalarAlign)),
                                 "tmp",
                                 /*ArraySize=*/nullptr, &AllocaAddr);
-        tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
+        NeedLifetimeEnd = EmitLifetimeStart(AllocaAddr.getPointer());
 
         Builder.CreateStore(RV.getScalarVal(), addr);
       }
@@ -5699,10 +5687,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       }
       assert(IRArgPos == FirstIRArg + NumIRArgs);
 
-      if (tempSize) {
-        EmitLifetimeEnd(tempSize, AllocaAddr.getPointer());
-      }
-
+      if (NeedLifetimeEnd)
+        EmitLifetimeEnd(AllocaAddr.getPointer());
       break;
     }
 
@@ -5871,9 +5857,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // can't depend on being inside of an ExprWithCleanups, so we need to manually
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
-  if (UnusedReturnSizePtr)
-    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr,
-                                         UnusedReturnSizePtr);
+  if (NeedSRetLifetimeEnd)
+    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
 
@@ -6007,7 +5992,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // insertion point; this allows the rest of IRGen to discard
   // unreachable code.
   if (CI->doesNotReturn()) {
-    if (UnusedReturnSizePtr)
+    if (NeedSRetLifetimeEnd)
       PopCleanupBlock();
 
     // Strip away the noreturn attribute to better diagnose unreachable UB.
@@ -6122,7 +6107,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       case ABIArgInfo::InAlloca:
       case ABIArgInfo::Indirect: {
         RValue ret = convertTempToRValue(SRetPtr, RetTy, SourceLocation());
-        if (UnusedReturnSizePtr)
+        if (NeedSRetLifetimeEnd)
           PopCleanupBlock();
         return ret;
       }
diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 0b4e3f9cb0365..3157b7f16f294 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -289,9 +289,6 @@ class CallArgList : public SmallVector<CallArg, 8> {
     /// An Expression (optional) that performs the writeback with any required
     /// casting.
     const Expr *WritebackExpr;
-
-    // Size for optional lifetime end on the temporary.
-    llvm::Value *LifetimeSz;
   };
 
   struct CallArgCleanup {
@@ -321,9 +318,8 @@ class CallArgList : public SmallVector<CallArg, 8> {
   }
 
   void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse,
-                    const Expr *writebackExpr = nullptr,
-                    llvm::Value *lifetimeSz = nullptr) {
-    Writeback writeback = {srcLV, temporary, toUse, writebackExpr, lifetimeSz};
+                    const Expr *writebackExpr = nullptr) {
+    Writeback writeback = {srcLV, temporary, toUse, writebackExpr};
     Writebacks.push_back(writeback);
   }
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 04f13c7d7a6a3..d224b09522d86 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1347,30 +1347,27 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) {
 }
 
 /// Emit a lifetime.begin marker if some criteria are satisfied.
-/// \return a pointer to the temporary size Value if a marker was emitted, null
-/// otherwise
-llvm::Value *CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
-                                                llvm::Value *Addr) {
+/// \return whether the marker was emitted.
+bool CodeGenFunction::EmitLifetimeStart(llvm::Value *Addr) {
   if (!ShouldEmitLifetimeMarkers)
-    return nullptr;
+    return false;
 
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::Value *SizeV = llvm::ConstantInt::get(
-      Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue());
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {Addr});
   C->setDoesNotThrow();
-  return SizeV;
+  return true;
 }
 
-void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
+void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Addr) {
+  if (!ShouldEmitLifetimeMarkers)
+    return;
+
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Addr});
   C->setDoesNotThrow();
 }
 
@@ -1628,9 +1625,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
         // is rare.
         if (!Bypasses.IsBypassed(&D) &&
             !(!getLangOpts().CPlusPlus && hasLabelBeenSeenInCurrentScope())) {
-          llvm::TypeSize Size = CGM.getDataLayout().getTypeAllocSize(allocaTy);
-          emission.SizeForLifetimeMarkers =
-              EmitLifetimeStart(Size, AllocaAddr.getPointer());
+          emission.UseLifetimeMarkers =
+              EmitLifetimeStart(AllocaAddr.getPointer());
         }
       } else {
         assert(!emission.useLifetimeMarkers());
@@ -1723,9 +1719,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
 
   // Make sure we call @llvm.lifetime.end.
   if (emission.useLifetimeMarkers())
-    EHStack.pushCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                         emission.getOriginalAllocatedAddress(),
-                                         emission.getSizeForLifetimeMarkers());
+    EHStack.pushCleanup<CallLifetimeEnd>(
+        NormalEHLifetimeMarker, emission.getOriginalAllocatedAddress());
 
   // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
   // calls for local variables. We are exempting volatile variables and
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 85c768807572f..576307d707b69 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -577,11 +577,9 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
   } else {
     switch (M->getStorageDuration()) {
     case SD_Automatic:
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
+      if (EmitLifetimeStart(Alloca.getPointer())) {
         pushCleanupAfterFullExpr<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                                  Alloca, Size);
+                                                  Alloca);
       }
       break;
 
@@ -612,11 +610,8 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
             Block, llvm::BasicBlock::iterator(Block->back())));
       }
 
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
-        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca,
-                                             Size);
+      if (EmitLifetimeStart(Alloca.getPointer())) {
+        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca);
       }
 
       if (OldConditional) {
@@ -5743,13 +5738,10 @@ LValue CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
   llvm::Value *Addr = TempLV.getAddress().getBasePointer();
   llvm::Type *ElTy = ConvertTypeForMem(TempLV.getType());
 
-  llvm::TypeSize Sz = CGM.getDataLayout().getTypeAllocSize(ElTy);
-
-  llvm::Value *LifetimeSize = EmitLifetimeStart(Sz, Addr);
+  EmitLifetimeStart(Addr);
 
   Address TmpAddr(Addr, ElTy, TempLV.getAlignment());
-  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast(),
-                    LifetimeSize);
+  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast());
   Args.add(RValue::get(TmpAddr, *this), Ty);
   return TempLV;
 }
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index cad6731173700..e2f11b86b2053 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -300,16 +300,12 @@ void AggExprEmitter::withReturnValueSlot(
   Address RetAddr = Address::invalid();
 
   EHScopeStack::stable_iterator LifetimeEndBlock;
-  llvm::Value *LifetimeSizePtr = nullptr;
   llvm::IntrinsicInst *LifetimeStartInst = nullptr;
   if (!UseTemp) {
     RetAddr = Dest.getAddress();
   } else {
     RetAddr = CGF.CreateMemTempWithoutCast(RetTy, "tmp");
-    llvm::TypeSize Size =
-        CGF.CGM.getDataLayout().getTypeAllocSize(CGF.ConvertTypeForMem(RetTy));
-    LifetimeSizePtr = CGF.EmitLifetimeStart(Size, RetAddr.getBasePointer());
-    if (LifetimeSizePtr) {
+    if (CGF.EmitLifetimeStart(RetAddr.getBasePointer())) {
       LifetimeStartInst =
           cast<llvm::IntrinsicInst>(std::prev(Builder.GetInsertPoint()));
       assert(LifetimeStartInst->getIntrinsicID() ==
@@ -317,7 +313,7 @@ void AggExprEmitter::withReturnValueSlot(
              "Last insertion wasn't a lifetime.start?");
 
       CGF.pushFullExprCleanup<CodeGenFunction::CallLifetimeEnd>(
-          NormalEHLifetimeMarker, RetAddr, LifetimeSizePtr);
+          NormalEHLifetimeMarker, RetAddr);
       LifetimeEndBlock = CGF.EHStack.stable_begin();
     }
   }
@@ -338,7 +334,7 @@ void AggExprEmitter::withReturnValueSlot(
     // Since we're not guaranteed to be in an ExprWithCleanups, clean up
     // eagerly.
     CGF.DeactivateCleanupBlock(LifetimeEndBlock, LifetimeStartInst);
-    CGF.EmitLifetimeEnd(LifetimeSizePtr, RetAddr.getBasePointer());
+    CGF.EmitLifetimeEnd(RetAddr.getBasePointer());
   }
 }
 
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 6c32c98cec011..272587f7fa4b5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -701,14 +701,12 @@ class CodeGenFunction : public CodeGenTypeCache {
     bool isRedundantBeforeReturn() override { return true; }
 
     llvm::Value *Addr;
-    llvm::Value *Size;
 
   public:
-    CallLifetimeEnd(RawAddress addr, llvm::Value *size)
-        : Addr(addr.getPointer()), Size(size) {}
+    CallLifetimeEnd(RawAddress addr) : Addr(addr.getPointer()) {}
 
     void Emit(CodeGenFunction &CGF, Flags flags) override {
-      CGF.EmitLifetimeEnd(Size, Addr);
+      CGF.EmitLifetimeEnd(Addr);
     }
   };
 
@@ -3233,8 +3231,8 @@ class CodeGenFunction : public CodeGenTypeCache {
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
 
-  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
-  void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
+  bool EmitLifetimeStart(llvm::Value *Addr);
+  void EmitLifetimeEnd(llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
@@ -3417,8 +3415,8 @@ class CodeGenFunction : public CodeGenTypeCache {
     /// initializer.
     bool IsConstantAggregate;
 
-    /// Non-null if we should use lifetime annotations.
-    llvm::Value *SizeForLifetimeMarkers;
+    /// True if lifetime markers should be used.
+    bool UseLifetimeMarkers;
 
     /// Address with original alloca instruction. Invalid if the variable was
     /// emitted as a global constant.
@@ -3432,20 +3430,14 @@ class CodeGenFunction : public CodeGenTypeCache {
     AutoVarEmission(const VarDecl &variable)
         : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
           IsEscapingByRef(false), IsConstantAggregate(false),
-          SizeForLifetimeMarkers(nullptr), AllocaAddr(RawAddress::invalid()) {}
+          UseLifetimeMarkers(false), AllocaAddr(RawAddress::invalid()) {}
 
     bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
 
   public:
     static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
 
-    bool useLifetimeMarkers() const {
-      return SizeForLifetimeMarkers != nullptr;
-    }
-    llvm::Value *getSizeForLifetimeMarkers() const {
-      assert(useLifetimeMarkers());
-      return SizeForLifetimeMarkers;
-    }
+    bool useLifetimeMarkers() const { return UseLifetimeMarkers; }
 
     /// Returns the raw, allocated address, which is not necessarily
     /// the address of the object itself. It is casted to default
diff --git a/clang/test/C/C11/n1285_1.c b/clang/test/C/C11/n1285_1.c
index 50100042e82fd..25b68e3145b04 100644
--- a/clang/test/C/C11/n1285_1.c
+++ b/clang/test/C/C11/n1285_1.c
@@ -26,16 +26,16 @@ struct X f(void);
 ...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Nikita Popov (nikic)

Changes

Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).


Patch is 1.54 MiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/150248.diff

479 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-11)
  • (modified) clang/lib/CodeGen/CGCall.cpp (+16-31)
  • (modified) clang/lib/CodeGen/CGCall.h (+2-6)
  • (modified) clang/lib/CodeGen/CGDecl.cpp (+14-19)
  • (modified) clang/lib/CodeGen/CGExpr.cpp (+6-14)
  • (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3-7)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+8-16)
  • (modified) clang/test/C/C11/n1285_1.c (+22-22)
  • (modified) clang/test/CodeGen/AArch64/ABI-align-packed.c (+28-28)
  • (modified) clang/test/CodeGen/AArch64/byval-temp.c (+12-12)
  • (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+5-5)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+2-2)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp (+2-2)
  • (modified) clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp (+4-4)
  • (modified) clang/test/CodeGen/aggregate-assign-call.c (+11-11)
  • (modified) clang/test/CodeGen/attr-counted-by.c (+4-4)
  • (modified) clang/test/CodeGen/cleanup-destslot-simple.c (+12-12)
  • (modified) clang/test/CodeGen/dominating-store-to-return.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime-sanitizer.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime2.c (+9-9)
  • (modified) clang/test/CodeGen/lifetime3.cpp (+8-8)
  • (modified) clang/test/CodeGen/math-libcalls-tbaa.c (+6-6)
  • (modified) clang/test/CodeGen/nofpclass.c (+4-4)
  • (modified) clang/test/CodeGen/temporary-lifetime-exceptions.cpp (+6-6)
  • (modified) clang/test/CodeGen/temporary-lifetime.cpp (+24-24)
  • (modified) clang/test/CodeGen/union-tbaa1.c (+2-2)
  • (modified) clang/test/CodeGenCXX/amdgcn_declspec_get.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+20-20)
  • (modified) clang/test/CodeGenCXX/destructors.cpp (+7-7)
  • (modified) clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/stack-reuse-exceptions.cpp (+30-30)
  • (modified) clang/test/CodeGenCXX/stack-reuse-miscompile.cpp (+3-3)
  • (modified) clang/test/CodeGenObjC/arc-blocks.m (+9-9)
  • (modified) clang/test/CodeGenObjC/arc-precise-lifetime.m (+34-34)
  • (modified) clang/test/CodeGenObjC/arc-ternary-op.m (+6-6)
  • (modified) clang/test/CodeGenObjC/arc.m (+51-51)
  • (modified) clang/test/CodeGenObjC/exceptions.m (+2-2)
  • (modified) clang/test/CodeGenObjCXX/arc-move.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/arc-references.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/arc.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/literals.mm (+6-6)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl (+16-16)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-printf.cl (+2-2)
  • (modified) clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (+14-14)
  • (modified) clang/test/CodeGenOpenCL/implicit-addrspacecast-function-parameter.cl (+2-2)
  • (modified) clang/test/Headers/__clang_hip_cmath.hip (+8-8)
  • (modified) clang/test/Headers/__clang_hip_math.hip (+80-80)
  • (modified) clang/test/OpenMP/bug54082.c (+12-12)
  • (modified) clang/test/OpenMP/bug56913.c (+2-2)
  • (modified) clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp (+96-96)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+4-5)
  • (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+4-4)
  • (modified) flang/lib/Optimizer/Transforms/StackArrays.cpp (+2-2)
  • (modified) flang/test/Transforms/stack-arrays-lifetime.fir (+4-4)
  • (modified) llvm/docs/LangRef.rst (+4-8)
  • (modified) llvm/include/llvm/Analysis/StackLifetime.h (-2)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+2-3)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+3-7)
  • (modified) llvm/include/llvm/IR/IRBuilder.h (+2-7)
  • (modified) llvm/include/llvm/IR/Intrinsics.td (+6-10)
  • (modified) llvm/lib/Analysis/MemoryDependenceAnalysis.cpp (+2-6)
  • (modified) llvm/lib/Analysis/MemoryLocation.cpp (+11-1)
  • (modified) llvm/lib/Analysis/StackLifetime.cpp (+1-41)
  • (modified) llvm/lib/CodeGen/AtomicExpandPass.cpp (+6-7)
  • (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+10-5)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+3-9)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-4)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp (-2)
  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+13-13)
  • (modified) llvm/lib/IR/IRBuilder.cpp (+4-16)
  • (modified) llvm/lib/IR/Verifier.cpp (+1-1)
  • (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+1-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp (+13-16)
  • (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+1-1)
  • (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+6-15)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+8-12)
  • (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+3-6)
  • (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+13-40)
  • (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+4-23)
  • (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+2-4)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+5-25)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp (+1-1)
  • (modified) llvm/test/Analysis/BasicAA/modref.ll (+5-5)
  • (modified) llvm/test/Analysis/BasicAA/phi-values-usage.ll (+2-2)
  • (modified) llvm/test/Analysis/CallGraph/ignore-assumelike-calls.ll (+2-2)
  • (modified) llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll (+1-2)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+8-8)
  • (modified) llvm/test/Analysis/KernelInfo/openmp/nvptx.ll (+9-9)
  • (modified) llvm/test/Analysis/LazyValueAnalysis/invalidation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Analysis/MemorySSA/phi-translation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/pr43044.ll (+1-1)
  • (modified) llvm/test/Analysis/MemorySSA/pr49859.ll (+11-11)
  • (modified) llvm/test/Analysis/MemorySSA/renamephis.ll (+1-1)
  • (modified) llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/sdiv.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/srem.ll (+4-4)
  • (modified) llvm/test/Analysis/ScopedNoAliasAA/alias-scope-merging.ll (+4-4)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll (+205-226)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/local.ll (+28-28)
  • (modified) llvm/test/Assembler/auto_upgrade_intrinsics.ll (+6-6)
  • (modified) llvm/test/Assembler/autoupgrade-lifetime-intrinsics.ll (+11-6)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/vararg.mir (+1-1)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-initializer-merge.ll (+42-42)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-merge-past-memcpy.mir (+4-4)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-untag-placement.ll (+7-7)
  • (modified) llvm/test/CodeGen/AMDGPU/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/BPF/loop-exit-cond.ll (+8-8)
  • (modified) llvm/test/CodeGen/BPF/vla.ll (+10-10)
  • (modified) llvm/test/CodeGen/NVPTX/frameindex-lifetime.ll (+2-2)
  • (modified) llvm/test/CodeGen/NVPTX/variadics-lowering.ll (+8-8)
  • (modified) llvm/test/CodeGen/SPIRV/llvm-intrinsics/lifetime.ll (+14-12)
  • (modified) llvm/test/CodeGen/WebAssembly/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/WebAssembly/returned.ll (+2-2)
  • (modified) llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll (+6-6)
  • (modified) llvm/test/CodeGen/X86/select-optimize.ll (+3-3)
  • (modified) llvm/test/CodeGen/X86/swap.ll (+18-25)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll (+4-7)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime.ll (+12-75)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/remove-memory-effects.ll (+2-2)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/X86/alloca.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-coloring.ll (+6-6)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll (+28-70)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll (+39-39)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/ARM32/vararg-arm32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg-loongarch64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mips.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mipsel.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppc.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppcle.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/RISCV32/vararg-riscv32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/alloca.ll (+10-8)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_call.ll (+10-10)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_debug_info.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_llvm_launder_invariant.ll (+4-4)
  • (modified) llvm/test/Transforms/AddDiscriminators/call.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/PowerPC/cmpxchg.ll (+2-2)
  • (modified) llvm/test/Transforms/AtomicExpand/RISCV/atomicrmw-fp.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/SPARC/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/AtomicExpand/X86/expand-atomic-libcall.ll (+4-4)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack.ll (+14-15)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll (+16-17)
  • (modified) llvm/test/Transforms/Attributor/liveness.ll (+8-8)
  • (modified) llvm/test/Transforms/Attributor/noalias.ll (+14-10)
  • (modified) llvm/test/Transforms/Attributor/openmp_parallel.ll (+39-37)
  • (modified) llvm/test/Transforms/Attributor/reduced/register_benchmark_test.ll (+2-2)
  • (modified) llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll (+60-58)
  • (modified) llvm/test/Transforms/CodeExtractor/LoopExtractor_alloca.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca2.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca4.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca5.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineInvokeProducesOutVal.ll (+2-2)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_gep.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_hoist.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_multiple.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_unsafe.ll (+8-8)
  • (modified) llvm/test/Transforms/CodeGenPrepare/ARM/tailcall-dup.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeGenPrepare/X86/tailcall-assume-xbb.ll (+4-4)
  • (modified) llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-intrinsics.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-06.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-07.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-08.ll (+6-6)
  • (removed) llvm/test/Transforms/Coroutines/coro-alloca-09.ll (-57)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-infinite-loop-bug.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-start-bug.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-byval-param.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-elide-musttail.ll (+1-1)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-00.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-01.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-03.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-04.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-05.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-lifetime-end.ll (+7-7)
  • (modified) llvm/test/Transforms/Coroutines/coro-only-destroy-when-complete.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-02.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-dbg.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail-chain-pgo-counter-promo.ll (+11-11)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail5.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail6.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail7.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-no-lifetime.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-01.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-02.ll (+5-5)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-03.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-04.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-transform-must-elide.ll (+2-2)
  • (modified) llvm/test/Transforms/CorrelatedValuePropagation/alloca.ll (+4-4)
  • (modified) llvm/test/Transforms/DCE/basic.ll (+4-4)
  • (modified) llvm/test/Transforms/DeadStoreElimination/batchaa-caching-new-pointers.ll (+18-18)
  • (modified) llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/dominate.ll (+3-3)
  • (modified) llvm/test/Transforms/DeadStoreElimination/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/DeadStoreElimination/lifetime.ll (+8-116)
  • (modified) llvm/test/Transforms/DeadStoreElimination/memcpy-lifetimes.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-loop-carried-dependence.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll (+2-2)
  • (modified) llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/simple.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll (+10-10)
  • (modified) llvm/test/Transforms/EarlyCSE/memoryssa.ll (+20-20)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-linkage.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-simple.ll (+16-16)
  • (modified) llvm/test/Transforms/ExpandVariadics/indirect-calls.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/intrinsics.ll (+22-22)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-byval-byref.ll (+12-12)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-indirect.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-integers.ll (+30-30)
  • (modified) llvm/test/Transforms/GVN/cond_br2.ll (+4-4)
  • (modified) llvm/test/Transforms/GVN/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Transforms/GVN/opt-remarks.ll (+2-2)
  • (modified) llvm/test/Transforms/GVN/vscale.ll (+6-6)
  • (modified) llvm/test/Transforms/GVNHoist/pr29034.ll (+2-2)
  • (modified) llvm/test/Transforms/GVNSink/lifetime.ll (+13-13)
  • (modified) llvm/test/Transforms/GlobalOpt/dead-store-status.ll (+4-4)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-3.ll (+8-8)
  • (modified) llvm/test/Transforms/HotColdSplit/sink-multiple-bitcasts-of-allocas-pr42451.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace-1.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/different-intrinsics.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/different-order-phi-merges.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/duplicate-merging-phis.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/exit-block-phi-node-value-attribution.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/exit-phi-nodes-incoming-value-constant-argument.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/extraction.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/gvn-output-set-overload.ll (+6-6)
  • (modified) llvm/test/Transforms/IROutliner/gvn-phi-debug.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/illegal-assumes.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memcpy.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memmove.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-vaarg.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits-not-in-first-outlined.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-outputs-ordering.ll (+10-10)
  • (modified) llvm/test/Transforms/IROutliner/must-capture-all-phi-nodes-begin.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/no-external-block-entries.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/one-external-incoming-block-phi-node.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/outline-memcpy.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-memmove.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-vaarg-intrinsic.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-bitcasts.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-branches-phi-nodes.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-cost-model.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-different-output-blocks.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-exits-to-phi-node.ll (+4-4)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3f784fc8e798f..1254b0f38966a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5981,8 +5981,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
 
     // Create a temporary array to hold the sizes of local pointer arguments
     // for the block. \p First is the position of the first size argument.
-    auto CreateArrayForSizeVar = [=](unsigned First)
-        -> std::tuple<llvm::Value *, llvm::Value *, llvm::Value *> {
+    auto CreateArrayForSizeVar =
+        [=](unsigned First) -> std::pair<llvm::Value *, llvm::Value *> {
       llvm::APInt ArraySize(32, NumArgs - First);
       QualType SizeArrayTy = getContext().getConstantArrayType(
           getContext().getSizeType(), ArraySize, nullptr,
@@ -5995,9 +5995,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       // actually the Alloca ascasted to the default AS, hence the
       // stripPointerCasts()
       llvm::Value *Alloca = TmpPtr->stripPointerCasts();
-      llvm::Value *TmpSize = EmitLifetimeStart(
-          CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), Alloca);
       llvm::Value *ElemPtr;
+      EmitLifetimeStart(Alloca);
       // Each of the following arguments specifies the size of the corresponding
       // argument passed to the enqueued block.
       auto *Zero = llvm::ConstantInt::get(IntTy, 0);
@@ -6014,7 +6013,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       }
       // Return the Alloca itself rather than a potential ascast as this is only
       // used by the paired EmitLifetimeEnd.
-      return {ElemPtr, TmpSize, Alloca};
+      return {ElemPtr, Alloca};
     };
 
     // Could have events and/or varargs.
@@ -6026,7 +6025,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::Value *Kernel =
           Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
       auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(4);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(4);
 
       // Create a vector of the arguments, as well as a constant value to
       // express to the runtime the number of variadic arguments.
@@ -6041,8 +6040,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     // Any calls now have event arguments passed.
@@ -6107,15 +6105,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       ArgTys.push_back(Int32Ty);
       Name = "__enqueue_kernel_events_varargs";
 
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(7);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(7);
       Args.push_back(ElemPtr);
       ArgTys.push_back(ElemPtr->getType());
 
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     llvm_unreachable("Unexpected enqueue_kernel signature");
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d9bd443455e0f..6e0c2c11a9f3b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4319,10 +4319,7 @@ static void emitWriteback(CodeGenFunction &CGF,
 
   if (writeback.WritebackExpr) {
     CGF.EmitIgnoredExpr(writeback.WritebackExpr);
-
-    if (writeback.LifetimeSz)
-      CGF.EmitLifetimeEnd(writeback.LifetimeSz,
-                          writeback.Temporary.getBasePointer());
+    CGF.EmitLifetimeEnd(writeback.Temporary.getBasePointer());
     return;
   }
 
@@ -5282,7 +5279,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  llvm::Value *UnusedReturnSizePtr = nullptr;
+  bool NeedSRetLifetimeEnd = false;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
     // For virtual function pointer thunks and musttail calls, we must always
     // forward an incoming SRet pointer to the callee, because a local alloca
@@ -5296,11 +5293,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       SRetPtr = ReturnValue.getAddress();
     } else {
       SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
-      if (HaveInsertPoint() && ReturnValue.isUnused()) {
-        llvm::TypeSize size =
-            CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-        UnusedReturnSizePtr = EmitLifetimeStart(size, SRetPtr.getBasePointer());
-      }
+      if (HaveInsertPoint() && ReturnValue.isUnused())
+        NeedSRetLifetimeEnd = EmitLifetimeStart(SRetPtr.getBasePointer());
     }
     if (IRFunctionArgs.hasSRetArg()) {
       // A mismatch between the allocated return value's AS and the target's
@@ -5484,15 +5478,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         Val = Builder.CreateFreeze(Val);
       IRCallArgs[FirstIRArg] = Val;
 
-      // Emit lifetime markers for the temporary alloca.
-      llvm::TypeSize ByvalTempElementSize =
-          CGM.getDataLayout().getTypeAllocSize(AI.getElementType());
-      llvm::Value *LifetimeSize =
-          EmitLifetimeStart(ByvalTempElementSize, AI.getPointer());
-
-      // Add cleanup code to emit the end lifetime marker after the call.
-      if (LifetimeSize) // In case we disabled lifetime markers.
-        CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
+      // Emit lifetime markers for the temporary alloca and add cleanup code to
+      // emit the end lifetime marker after the call.
+      if (EmitLifetimeStart(AI.getPointer()))
+        CallLifetimeEndAfterCall.emplace_back(AI);
 
       // Generate the copy.
       I->copyInto(*this, AI);
@@ -5653,9 +5642,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       auto unpaddedCoercionType = ArgInfo.getUnpaddedCoerceAndExpandType();
       auto *unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoercionType);
 
-      llvm::Value *tempSize = nullptr;
       Address addr = Address::invalid();
       RawAddress AllocaAddr = RawAddress::invalid();
+      bool NeedLifetimeEnd = false;
       if (I->isAggregate()) {
         addr = I->hasLValue() ? I->getKnownLValue().getAddress()
                               : I->getKnownRValue().getAggregateAddress();
@@ -5665,7 +5654,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         assert(RV.isScalar()); // complex should always just be direct
 
         llvm::Type *scalarType = RV.getScalarVal()->getType();
-        auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
         auto scalarAlign = CGM.getDataLayout().getPrefTypeAlign(scalarType);
 
         // Materialize to a temporary.
@@ -5674,7 +5662,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
                                     layout->getAlignment(), scalarAlign)),
                                 "tmp",
                                 /*ArraySize=*/nullptr, &AllocaAddr);
-        tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
+        NeedLifetimeEnd = EmitLifetimeStart(AllocaAddr.getPointer());
 
         Builder.CreateStore(RV.getScalarVal(), addr);
       }
@@ -5699,10 +5687,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       }
       assert(IRArgPos == FirstIRArg + NumIRArgs);
 
-      if (tempSize) {
-        EmitLifetimeEnd(tempSize, AllocaAddr.getPointer());
-      }
-
+      if (NeedLifetimeEnd)
+        EmitLifetimeEnd(AllocaAddr.getPointer());
       break;
     }
 
@@ -5871,9 +5857,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // can't depend on being inside of an ExprWithCleanups, so we need to manually
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
-  if (UnusedReturnSizePtr)
-    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr,
-                                         UnusedReturnSizePtr);
+  if (NeedSRetLifetimeEnd)
+    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
 
@@ -6007,7 +5992,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // insertion point; this allows the rest of IRGen to discard
   // unreachable code.
   if (CI->doesNotReturn()) {
-    if (UnusedReturnSizePtr)
+    if (NeedSRetLifetimeEnd)
       PopCleanupBlock();
 
     // Strip away the noreturn attribute to better diagnose unreachable UB.
@@ -6122,7 +6107,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       case ABIArgInfo::InAlloca:
       case ABIArgInfo::Indirect: {
         RValue ret = convertTempToRValue(SRetPtr, RetTy, SourceLocation());
-        if (UnusedReturnSizePtr)
+        if (NeedSRetLifetimeEnd)
           PopCleanupBlock();
         return ret;
       }
diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 0b4e3f9cb0365..3157b7f16f294 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -289,9 +289,6 @@ class CallArgList : public SmallVector<CallArg, 8> {
     /// An Expression (optional) that performs the writeback with any required
     /// casting.
     const Expr *WritebackExpr;
-
-    // Size for optional lifetime end on the temporary.
-    llvm::Value *LifetimeSz;
   };
 
   struct CallArgCleanup {
@@ -321,9 +318,8 @@ class CallArgList : public SmallVector<CallArg, 8> {
   }
 
   void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse,
-                    const Expr *writebackExpr = nullptr,
-                    llvm::Value *lifetimeSz = nullptr) {
-    Writeback writeback = {srcLV, temporary, toUse, writebackExpr, lifetimeSz};
+                    const Expr *writebackExpr = nullptr) {
+    Writeback writeback = {srcLV, temporary, toUse, writebackExpr};
     Writebacks.push_back(writeback);
   }
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 04f13c7d7a6a3..d224b09522d86 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1347,30 +1347,27 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) {
 }
 
 /// Emit a lifetime.begin marker if some criteria are satisfied.
-/// \return a pointer to the temporary size Value if a marker was emitted, null
-/// otherwise
-llvm::Value *CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
-                                                llvm::Value *Addr) {
+/// \return whether the marker was emitted.
+bool CodeGenFunction::EmitLifetimeStart(llvm::Value *Addr) {
   if (!ShouldEmitLifetimeMarkers)
-    return nullptr;
+    return false;
 
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::Value *SizeV = llvm::ConstantInt::get(
-      Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue());
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {Addr});
   C->setDoesNotThrow();
-  return SizeV;
+  return true;
 }
 
-void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
+void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Addr) {
+  if (!ShouldEmitLifetimeMarkers)
+    return;
+
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Addr});
   C->setDoesNotThrow();
 }
 
@@ -1628,9 +1625,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
         // is rare.
         if (!Bypasses.IsBypassed(&D) &&
             !(!getLangOpts().CPlusPlus && hasLabelBeenSeenInCurrentScope())) {
-          llvm::TypeSize Size = CGM.getDataLayout().getTypeAllocSize(allocaTy);
-          emission.SizeForLifetimeMarkers =
-              EmitLifetimeStart(Size, AllocaAddr.getPointer());
+          emission.UseLifetimeMarkers =
+              EmitLifetimeStart(AllocaAddr.getPointer());
         }
       } else {
         assert(!emission.useLifetimeMarkers());
@@ -1723,9 +1719,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
 
   // Make sure we call @llvm.lifetime.end.
   if (emission.useLifetimeMarkers())
-    EHStack.pushCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                         emission.getOriginalAllocatedAddress(),
-                                         emission.getSizeForLifetimeMarkers());
+    EHStack.pushCleanup<CallLifetimeEnd>(
+        NormalEHLifetimeMarker, emission.getOriginalAllocatedAddress());
 
   // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
   // calls for local variables. We are exempting volatile variables and
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 85c768807572f..576307d707b69 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -577,11 +577,9 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
   } else {
     switch (M->getStorageDuration()) {
     case SD_Automatic:
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
+      if (EmitLifetimeStart(Alloca.getPointer())) {
         pushCleanupAfterFullExpr<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                                  Alloca, Size);
+                                                  Alloca);
       }
       break;
 
@@ -612,11 +610,8 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
             Block, llvm::BasicBlock::iterator(Block->back())));
       }
 
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
-        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca,
-                                             Size);
+      if (EmitLifetimeStart(Alloca.getPointer())) {
+        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca);
       }
 
       if (OldConditional) {
@@ -5743,13 +5738,10 @@ LValue CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
   llvm::Value *Addr = TempLV.getAddress().getBasePointer();
   llvm::Type *ElTy = ConvertTypeForMem(TempLV.getType());
 
-  llvm::TypeSize Sz = CGM.getDataLayout().getTypeAllocSize(ElTy);
-
-  llvm::Value *LifetimeSize = EmitLifetimeStart(Sz, Addr);
+  EmitLifetimeStart(Addr);
 
   Address TmpAddr(Addr, ElTy, TempLV.getAlignment());
-  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast(),
-                    LifetimeSize);
+  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast());
   Args.add(RValue::get(TmpAddr, *this), Ty);
   return TempLV;
 }
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index cad6731173700..e2f11b86b2053 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -300,16 +300,12 @@ void AggExprEmitter::withReturnValueSlot(
   Address RetAddr = Address::invalid();
 
   EHScopeStack::stable_iterator LifetimeEndBlock;
-  llvm::Value *LifetimeSizePtr = nullptr;
   llvm::IntrinsicInst *LifetimeStartInst = nullptr;
   if (!UseTemp) {
     RetAddr = Dest.getAddress();
   } else {
     RetAddr = CGF.CreateMemTempWithoutCast(RetTy, "tmp");
-    llvm::TypeSize Size =
-        CGF.CGM.getDataLayout().getTypeAllocSize(CGF.ConvertTypeForMem(RetTy));
-    LifetimeSizePtr = CGF.EmitLifetimeStart(Size, RetAddr.getBasePointer());
-    if (LifetimeSizePtr) {
+    if (CGF.EmitLifetimeStart(RetAddr.getBasePointer())) {
       LifetimeStartInst =
           cast<llvm::IntrinsicInst>(std::prev(Builder.GetInsertPoint()));
       assert(LifetimeStartInst->getIntrinsicID() ==
@@ -317,7 +313,7 @@ void AggExprEmitter::withReturnValueSlot(
              "Last insertion wasn't a lifetime.start?");
 
       CGF.pushFullExprCleanup<CodeGenFunction::CallLifetimeEnd>(
-          NormalEHLifetimeMarker, RetAddr, LifetimeSizePtr);
+          NormalEHLifetimeMarker, RetAddr);
       LifetimeEndBlock = CGF.EHStack.stable_begin();
     }
   }
@@ -338,7 +334,7 @@ void AggExprEmitter::withReturnValueSlot(
     // Since we're not guaranteed to be in an ExprWithCleanups, clean up
     // eagerly.
     CGF.DeactivateCleanupBlock(LifetimeEndBlock, LifetimeStartInst);
-    CGF.EmitLifetimeEnd(LifetimeSizePtr, RetAddr.getBasePointer());
+    CGF.EmitLifetimeEnd(RetAddr.getBasePointer());
   }
 }
 
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 6c32c98cec011..272587f7fa4b5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -701,14 +701,12 @@ class CodeGenFunction : public CodeGenTypeCache {
     bool isRedundantBeforeReturn() override { return true; }
 
     llvm::Value *Addr;
-    llvm::Value *Size;
 
   public:
-    CallLifetimeEnd(RawAddress addr, llvm::Value *size)
-        : Addr(addr.getPointer()), Size(size) {}
+    CallLifetimeEnd(RawAddress addr) : Addr(addr.getPointer()) {}
 
     void Emit(CodeGenFunction &CGF, Flags flags) override {
-      CGF.EmitLifetimeEnd(Size, Addr);
+      CGF.EmitLifetimeEnd(Addr);
     }
   };
 
@@ -3233,8 +3231,8 @@ class CodeGenFunction : public CodeGenTypeCache {
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
 
-  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
-  void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
+  bool EmitLifetimeStart(llvm::Value *Addr);
+  void EmitLifetimeEnd(llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
@@ -3417,8 +3415,8 @@ class CodeGenFunction : public CodeGenTypeCache {
     /// initializer.
     bool IsConstantAggregate;
 
-    /// Non-null if we should use lifetime annotations.
-    llvm::Value *SizeForLifetimeMarkers;
+    /// True if lifetime markers should be used.
+    bool UseLifetimeMarkers;
 
     /// Address with original alloca instruction. Invalid if the variable was
     /// emitted as a global constant.
@@ -3432,20 +3430,14 @@ class CodeGenFunction : public CodeGenTypeCache {
     AutoVarEmission(const VarDecl &variable)
         : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
           IsEscapingByRef(false), IsConstantAggregate(false),
-          SizeForLifetimeMarkers(nullptr), AllocaAddr(RawAddress::invalid()) {}
+          UseLifetimeMarkers(false), AllocaAddr(RawAddress::invalid()) {}
 
     bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
 
   public:
     static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
 
-    bool useLifetimeMarkers() const {
-      return SizeForLifetimeMarkers != nullptr;
-    }
-    llvm::Value *getSizeForLifetimeMarkers() const {
-      assert(useLifetimeMarkers());
-      return SizeForLifetimeMarkers;
-    }
+    bool useLifetimeMarkers() const { return UseLifetimeMarkers; }
 
     /// Returns the raw, allocated address, which is not necessarily
     /// the address of the object itself. It is casted to default
diff --git a/clang/test/C/C11/n1285_1.c b/clang/test/C/C11/n1285_1.c
index 50100042e82fd..25b68e3145b04 100644
--- a/clang/test/C/C11/n1285_1.c
+++ b/clang/test/C/C11/n1285_1.c
@@ -26,16 +26,16 @@ struct X f(void);
 ...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2025

@llvm/pr-subscribers-coroutines

Author: Nikita Popov (nikic)

Changes

Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).


Patch is 1.54 MiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/150248.diff

479 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-11)
  • (modified) clang/lib/CodeGen/CGCall.cpp (+16-31)
  • (modified) clang/lib/CodeGen/CGCall.h (+2-6)
  • (modified) clang/lib/CodeGen/CGDecl.cpp (+14-19)
  • (modified) clang/lib/CodeGen/CGExpr.cpp (+6-14)
  • (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3-7)
  • (modified) clang/lib/CodeGen/CodeGenFunction.h (+8-16)
  • (modified) clang/test/C/C11/n1285_1.c (+22-22)
  • (modified) clang/test/CodeGen/AArch64/ABI-align-packed.c (+28-28)
  • (modified) clang/test/CodeGen/AArch64/byval-temp.c (+12-12)
  • (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+5-5)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+2-2)
  • (modified) clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp (+2-2)
  • (modified) clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp (+4-4)
  • (modified) clang/test/CodeGen/aggregate-assign-call.c (+11-11)
  • (modified) clang/test/CodeGen/attr-counted-by.c (+4-4)
  • (modified) clang/test/CodeGen/cleanup-destslot-simple.c (+12-12)
  • (modified) clang/test/CodeGen/dominating-store-to-return.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime-sanitizer.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime.c (+4-4)
  • (modified) clang/test/CodeGen/lifetime2.c (+9-9)
  • (modified) clang/test/CodeGen/lifetime3.cpp (+8-8)
  • (modified) clang/test/CodeGen/math-libcalls-tbaa.c (+6-6)
  • (modified) clang/test/CodeGen/nofpclass.c (+4-4)
  • (modified) clang/test/CodeGen/temporary-lifetime-exceptions.cpp (+6-6)
  • (modified) clang/test/CodeGen/temporary-lifetime.cpp (+24-24)
  • (modified) clang/test/CodeGen/union-tbaa1.c (+2-2)
  • (modified) clang/test/CodeGenCXX/amdgcn_declspec_get.cpp (+2-2)
  • (modified) clang/test/CodeGenCXX/attr-likelihood-iteration-stmt.cpp (+20-20)
  • (modified) clang/test/CodeGenCXX/destructors.cpp (+7-7)
  • (modified) clang/test/CodeGenCXX/microsoft-abi-eh-cleanups.cpp (+3-3)
  • (modified) clang/test/CodeGenCXX/stack-reuse-exceptions.cpp (+30-30)
  • (modified) clang/test/CodeGenCXX/stack-reuse-miscompile.cpp (+3-3)
  • (modified) clang/test/CodeGenObjC/arc-blocks.m (+9-9)
  • (modified) clang/test/CodeGenObjC/arc-precise-lifetime.m (+34-34)
  • (modified) clang/test/CodeGenObjC/arc-ternary-op.m (+6-6)
  • (modified) clang/test/CodeGenObjC/arc.m (+51-51)
  • (modified) clang/test/CodeGenObjC/exceptions.m (+2-2)
  • (modified) clang/test/CodeGenObjCXX/arc-move.mm (+4-4)
  • (modified) clang/test/CodeGenObjCXX/arc-references.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/arc.mm (+3-3)
  • (modified) clang/test/CodeGenObjCXX/literals.mm (+6-6)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl (+16-16)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-printf.cl (+2-2)
  • (modified) clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (+14-14)
  • (modified) clang/test/CodeGenOpenCL/implicit-addrspacecast-function-parameter.cl (+2-2)
  • (modified) clang/test/Headers/__clang_hip_cmath.hip (+8-8)
  • (modified) clang/test/Headers/__clang_hip_math.hip (+80-80)
  • (modified) clang/test/OpenMP/bug54082.c (+12-12)
  • (modified) clang/test/OpenMP/bug56913.c (+2-2)
  • (modified) clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp (+96-96)
  • (modified) flang/include/flang/Optimizer/Builder/FIRBuilder.h (+4-5)
  • (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+4-4)
  • (modified) flang/lib/Optimizer/Transforms/StackArrays.cpp (+2-2)
  • (modified) flang/test/Transforms/stack-arrays-lifetime.fir (+4-4)
  • (modified) llvm/docs/LangRef.rst (+4-8)
  • (modified) llvm/include/llvm/Analysis/StackLifetime.h (-2)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+2-3)
  • (modified) llvm/include/llvm/CodeGen/SelectionDAGNodes.h (+3-7)
  • (modified) llvm/include/llvm/IR/IRBuilder.h (+2-7)
  • (modified) llvm/include/llvm/IR/Intrinsics.td (+6-10)
  • (modified) llvm/lib/Analysis/MemoryDependenceAnalysis.cpp (+2-6)
  • (modified) llvm/lib/Analysis/MemoryLocation.cpp (+11-1)
  • (modified) llvm/lib/Analysis/StackLifetime.cpp (+1-41)
  • (modified) llvm/lib/CodeGen/AtomicExpandPass.cpp (+6-7)
  • (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+10-5)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+3-9)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-4)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp (-2)
  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+13-13)
  • (modified) llvm/lib/IR/IRBuilder.cpp (+4-16)
  • (modified) llvm/lib/IR/Verifier.cpp (+1-1)
  • (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+1-2)
  • (modified) llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp (+13-16)
  • (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+1-1)
  • (modified) llvm/lib/Transforms/IPO/ExpandVariadics.cpp (+6-15)
  • (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+8-12)
  • (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+3-6)
  • (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+2-2)
  • (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+13-40)
  • (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+4-23)
  • (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+2-4)
  • (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+5-25)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+1-1)
  • (modified) llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp (+1-1)
  • (modified) llvm/test/Analysis/BasicAA/modref.ll (+5-5)
  • (modified) llvm/test/Analysis/BasicAA/phi-values-usage.ll (+2-2)
  • (modified) llvm/test/Analysis/CallGraph/ignore-assumelike-calls.ll (+2-2)
  • (modified) llvm/test/Analysis/CostModel/SystemZ/intrinsic-cost-crash.ll (+1-2)
  • (modified) llvm/test/Analysis/CostModel/X86/free-intrinsics.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-datalayout.ll (+8-8)
  • (modified) llvm/test/Analysis/CostModel/free-intrinsics-no_info.ll (+8-8)
  • (modified) llvm/test/Analysis/KernelInfo/openmp/nvptx.ll (+9-9)
  • (modified) llvm/test/Analysis/LazyValueAnalysis/invalidation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Analysis/MemorySSA/phi-translation.ll (+4-4)
  • (modified) llvm/test/Analysis/MemorySSA/pr43044.ll (+1-1)
  • (modified) llvm/test/Analysis/MemorySSA/pr49859.ll (+11-11)
  • (modified) llvm/test/Analysis/MemorySSA/renamephis.ll (+1-1)
  • (modified) llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll (+2-2)
  • (modified) llvm/test/Analysis/ScalarEvolution/sdiv.ll (+4-4)
  • (modified) llvm/test/Analysis/ScalarEvolution/srem.ll (+4-4)
  • (modified) llvm/test/Analysis/ScopedNoAliasAA/alias-scope-merging.ll (+4-4)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll (+205-226)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/local.ll (+28-28)
  • (modified) llvm/test/Assembler/auto_upgrade_intrinsics.ll (+6-6)
  • (modified) llvm/test/Assembler/autoupgrade-lifetime-intrinsics.ll (+11-6)
  • (modified) llvm/test/CodeGen/AArch64/GlobalISel/vararg.mir (+1-1)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-initializer-merge.ll (+42-42)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-merge-past-memcpy.mir (+4-4)
  • (modified) llvm/test/CodeGen/AArch64/stack-tagging-untag-placement.ll (+7-7)
  • (modified) llvm/test/CodeGen/AMDGPU/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/BPF/loop-exit-cond.ll (+8-8)
  • (modified) llvm/test/CodeGen/BPF/vla.ll (+10-10)
  • (modified) llvm/test/CodeGen/NVPTX/frameindex-lifetime.ll (+2-2)
  • (modified) llvm/test/CodeGen/NVPTX/variadics-lowering.ll (+8-8)
  • (modified) llvm/test/CodeGen/SPIRV/llvm-intrinsics/lifetime.ll (+14-12)
  • (modified) llvm/test/CodeGen/WebAssembly/expand-variadic-call.ll (+58-58)
  • (modified) llvm/test/CodeGen/WebAssembly/returned.ll (+2-2)
  • (modified) llvm/test/CodeGen/X86/pr140491-sincos-lifetimes.ll (+6-6)
  • (modified) llvm/test/CodeGen/X86/select-optimize.ll (+3-3)
  • (modified) llvm/test/CodeGen/X86/swap.ll (+18-25)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll (+4-7)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/lifetime.ll (+12-75)
  • (modified) llvm/test/Instrumentation/AddressSanitizer/remove-memory-effects.ll (+2-2)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/RISCV/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/X86/alloca.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/exception-lifetime.ll (+8-8)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-coloring.ll (+6-6)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll (+28-70)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll (+4-4)
  • (modified) llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope.ll (+39-39)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg-kmsan.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/ARM32/vararg-arm32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/LoongArch/vararg-loongarch64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mips.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/Mips32/vararg-mipsel.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppc.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/PowerPC32/vararg-ppcle.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/RISCV32/vararg-riscv32.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg-kernel.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/SystemZ/vararg.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll (+4-4)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/X86/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/alloca.ll (+10-8)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_call.ll (+10-10)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/i386/vararg_shadow.ll (+50-50)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_debug_info.ll (+6-6)
  • (modified) llvm/test/Instrumentation/MemorySanitizer/msan_llvm_launder_invariant.ll (+4-4)
  • (modified) llvm/test/Transforms/AddDiscriminators/call.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/PowerPC/cmpxchg.ll (+2-2)
  • (modified) llvm/test/Transforms/AtomicExpand/RISCV/atomicrmw-fp.ll (+4-4)
  • (modified) llvm/test/Transforms/AtomicExpand/SPARC/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/AtomicExpand/X86/expand-atomic-libcall.ll (+4-4)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack.ll (+14-15)
  • (modified) llvm/test/Transforms/Attributor/heap_to_stack_gpu.ll (+16-17)
  • (modified) llvm/test/Transforms/Attributor/liveness.ll (+8-8)
  • (modified) llvm/test/Transforms/Attributor/noalias.ll (+14-10)
  • (modified) llvm/test/Transforms/Attributor/openmp_parallel.ll (+39-37)
  • (modified) llvm/test/Transforms/Attributor/reduced/register_benchmark_test.ll (+2-2)
  • (modified) llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll (+60-58)
  • (modified) llvm/test/Transforms/CodeExtractor/LoopExtractor_alloca.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca2.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca4.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineAlloca5.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/PartialInlineInvokeProducesOutVal.ll (+2-2)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_gep.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_hoist.ll (+5-5)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_multiple.ll (+6-6)
  • (modified) llvm/test/Transforms/CodeExtractor/live_shrink_unsafe.ll (+8-8)
  • (modified) llvm/test/Transforms/CodeGenPrepare/ARM/tailcall-dup.ll (+4-4)
  • (modified) llvm/test/Transforms/CodeGenPrepare/X86/tailcall-assume-xbb.ll (+4-4)
  • (modified) llvm/test/Transforms/ConstantHoisting/AArch64/const-hoist-intrinsics.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-06.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-07.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-08.ll (+6-6)
  • (removed) llvm/test/Transforms/Coroutines/coro-alloca-09.ll (-57)
  • (modified) llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-infinite-loop-bug.ll (+3-3)
  • (modified) llvm/test/Transforms/Coroutines/coro-async-addr-lifetime-start-bug.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-byval-param.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-elide-musttail.ll (+1-1)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-00.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-01.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-03.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-04.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-05.ll (+9-9)
  • (modified) llvm/test/Transforms/Coroutines/coro-lifetime-end.ll (+7-7)
  • (modified) llvm/test/Transforms/Coroutines/coro-only-destroy-when-complete.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-02.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-dbg.ll (+2-2)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail-chain-pgo-counter-promo.ll (+11-11)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail5.ll (+4-4)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail6.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-musttail7.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-no-lifetime.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-01.ll (+8-8)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-02.ll (+5-5)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-03.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-04.ll (+6-6)
  • (modified) llvm/test/Transforms/Coroutines/coro-transform-must-elide.ll (+2-2)
  • (modified) llvm/test/Transforms/CorrelatedValuePropagation/alloca.ll (+4-4)
  • (modified) llvm/test/Transforms/DCE/basic.ll (+4-4)
  • (modified) llvm/test/Transforms/DeadStoreElimination/batchaa-caching-new-pointers.ll (+18-18)
  • (modified) llvm/test/Transforms/DeadStoreElimination/captures-before-load.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/dominate.ll (+3-3)
  • (modified) llvm/test/Transforms/DeadStoreElimination/libcalls.ll (+22-22)
  • (modified) llvm/test/Transforms/DeadStoreElimination/lifetime.ll (+8-116)
  • (modified) llvm/test/Transforms/DeadStoreElimination/memcpy-lifetimes.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-loop-carried-dependence.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/multiblock-malloc-free.ll (+2-2)
  • (modified) llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll (+5-5)
  • (modified) llvm/test/Transforms/DeadStoreElimination/simple.ll (+6-6)
  • (modified) llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll (+10-10)
  • (modified) llvm/test/Transforms/EarlyCSE/memoryssa.ll (+20-20)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-linkage.ll (+8-8)
  • (modified) llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-simple.ll (+16-16)
  • (modified) llvm/test/Transforms/ExpandVariadics/indirect-calls.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/intrinsics.ll (+22-22)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-byval-byref.ll (+12-12)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-indirect.ll (+4-4)
  • (modified) llvm/test/Transforms/ExpandVariadics/pass-integers.ll (+30-30)
  • (modified) llvm/test/Transforms/GVN/cond_br2.ll (+4-4)
  • (modified) llvm/test/Transforms/GVN/lifetime-simple.ll (+6-6)
  • (modified) llvm/test/Transforms/GVN/opt-remarks.ll (+2-2)
  • (modified) llvm/test/Transforms/GVN/vscale.ll (+6-6)
  • (modified) llvm/test/Transforms/GVNHoist/pr29034.ll (+2-2)
  • (modified) llvm/test/Transforms/GVNSink/lifetime.ll (+13-13)
  • (modified) llvm/test/Transforms/GlobalOpt/dead-store-status.ll (+4-4)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-1.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-2.ll (+14-14)
  • (modified) llvm/test/Transforms/HotColdSplit/lifetime-markers-on-inputs-3.ll (+8-8)
  • (modified) llvm/test/Transforms/HotColdSplit/sink-multiple-bitcasts-of-allocas-pr42451.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace-1.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/alloca-addrspace.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/different-intrinsics.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/different-order-phi-merges.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/duplicate-merging-phis.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/exit-block-phi-node-value-attribution.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/exit-phi-nodes-incoming-value-constant-argument.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/extraction.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/gvn-output-set-overload.ll (+6-6)
  • (modified) llvm/test/Transforms/IROutliner/gvn-phi-debug.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/illegal-assumes.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memcpy.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-memmove.ll (+12-12)
  • (modified) llvm/test/Transforms/IROutliner/illegal-vaarg.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits-not-in-first-outlined.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-exits.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/mismatched-phi-outputs-ordering.ll (+10-10)
  • (modified) llvm/test/Transforms/IROutliner/must-capture-all-phi-nodes-begin.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/no-external-block-entries.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/one-external-incoming-block-phi-node.ll (+2-2)
  • (modified) llvm/test/Transforms/IROutliner/outline-memcpy.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-memmove.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outline-vaarg-intrinsic.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-bitcasts.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-branches-phi-nodes.ll (+4-4)
  • (modified) llvm/test/Transforms/IROutliner/outlining-cost-model.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-different-output-blocks.ll (+8-8)
  • (modified) llvm/test/Transforms/IROutliner/outlining-exits-to-phi-node.ll (+4-4)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3f784fc8e798f..1254b0f38966a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5981,8 +5981,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
 
     // Create a temporary array to hold the sizes of local pointer arguments
     // for the block. \p First is the position of the first size argument.
-    auto CreateArrayForSizeVar = [=](unsigned First)
-        -> std::tuple<llvm::Value *, llvm::Value *, llvm::Value *> {
+    auto CreateArrayForSizeVar =
+        [=](unsigned First) -> std::pair<llvm::Value *, llvm::Value *> {
       llvm::APInt ArraySize(32, NumArgs - First);
       QualType SizeArrayTy = getContext().getConstantArrayType(
           getContext().getSizeType(), ArraySize, nullptr,
@@ -5995,9 +5995,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       // actually the Alloca ascasted to the default AS, hence the
       // stripPointerCasts()
       llvm::Value *Alloca = TmpPtr->stripPointerCasts();
-      llvm::Value *TmpSize = EmitLifetimeStart(
-          CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), Alloca);
       llvm::Value *ElemPtr;
+      EmitLifetimeStart(Alloca);
       // Each of the following arguments specifies the size of the corresponding
       // argument passed to the enqueued block.
       auto *Zero = llvm::ConstantInt::get(IntTy, 0);
@@ -6014,7 +6013,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       }
       // Return the Alloca itself rather than a potential ascast as this is only
       // used by the paired EmitLifetimeEnd.
-      return {ElemPtr, TmpSize, Alloca};
+      return {ElemPtr, Alloca};
     };
 
     // Could have events and/or varargs.
@@ -6026,7 +6025,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::Value *Kernel =
           Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
       auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(4);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(4);
 
       // Create a vector of the arguments, as well as a constant value to
       // express to the runtime the number of variadic arguments.
@@ -6041,8 +6040,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     // Any calls now have event arguments passed.
@@ -6107,15 +6105,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
       ArgTys.push_back(Int32Ty);
       Name = "__enqueue_kernel_events_varargs";
 
-      auto [ElemPtr, TmpSize, TmpPtr] = CreateArrayForSizeVar(7);
+      auto [ElemPtr, TmpPtr] = CreateArrayForSizeVar(7);
       Args.push_back(ElemPtr);
       ArgTys.push_back(ElemPtr->getType());
 
       llvm::FunctionType *FTy = llvm::FunctionType::get(Int32Ty, ArgTys, false);
       auto Call = RValue::get(
           EmitRuntimeCall(CGM.CreateRuntimeFunction(FTy, Name), Args));
-      if (TmpSize)
-        EmitLifetimeEnd(TmpSize, TmpPtr);
+      EmitLifetimeEnd(TmpPtr);
       return Call;
     }
     llvm_unreachable("Unexpected enqueue_kernel signature");
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d9bd443455e0f..6e0c2c11a9f3b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4319,10 +4319,7 @@ static void emitWriteback(CodeGenFunction &CGF,
 
   if (writeback.WritebackExpr) {
     CGF.EmitIgnoredExpr(writeback.WritebackExpr);
-
-    if (writeback.LifetimeSz)
-      CGF.EmitLifetimeEnd(writeback.LifetimeSz,
-                          writeback.Temporary.getBasePointer());
+    CGF.EmitLifetimeEnd(writeback.Temporary.getBasePointer());
     return;
   }
 
@@ -5282,7 +5279,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // If the call returns a temporary with struct return, create a temporary
   // alloca to hold the result, unless one is given to us.
   Address SRetPtr = Address::invalid();
-  llvm::Value *UnusedReturnSizePtr = nullptr;
+  bool NeedSRetLifetimeEnd = false;
   if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) {
     // For virtual function pointer thunks and musttail calls, we must always
     // forward an incoming SRet pointer to the callee, because a local alloca
@@ -5296,11 +5293,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       SRetPtr = ReturnValue.getAddress();
     } else {
       SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp");
-      if (HaveInsertPoint() && ReturnValue.isUnused()) {
-        llvm::TypeSize size =
-            CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy));
-        UnusedReturnSizePtr = EmitLifetimeStart(size, SRetPtr.getBasePointer());
-      }
+      if (HaveInsertPoint() && ReturnValue.isUnused())
+        NeedSRetLifetimeEnd = EmitLifetimeStart(SRetPtr.getBasePointer());
     }
     if (IRFunctionArgs.hasSRetArg()) {
       // A mismatch between the allocated return value's AS and the target's
@@ -5484,15 +5478,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         Val = Builder.CreateFreeze(Val);
       IRCallArgs[FirstIRArg] = Val;
 
-      // Emit lifetime markers for the temporary alloca.
-      llvm::TypeSize ByvalTempElementSize =
-          CGM.getDataLayout().getTypeAllocSize(AI.getElementType());
-      llvm::Value *LifetimeSize =
-          EmitLifetimeStart(ByvalTempElementSize, AI.getPointer());
-
-      // Add cleanup code to emit the end lifetime marker after the call.
-      if (LifetimeSize) // In case we disabled lifetime markers.
-        CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
+      // Emit lifetime markers for the temporary alloca and add cleanup code to
+      // emit the end lifetime marker after the call.
+      if (EmitLifetimeStart(AI.getPointer()))
+        CallLifetimeEndAfterCall.emplace_back(AI);
 
       // Generate the copy.
       I->copyInto(*this, AI);
@@ -5653,9 +5642,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       auto unpaddedCoercionType = ArgInfo.getUnpaddedCoerceAndExpandType();
       auto *unpaddedStruct = dyn_cast<llvm::StructType>(unpaddedCoercionType);
 
-      llvm::Value *tempSize = nullptr;
       Address addr = Address::invalid();
       RawAddress AllocaAddr = RawAddress::invalid();
+      bool NeedLifetimeEnd = false;
       if (I->isAggregate()) {
         addr = I->hasLValue() ? I->getKnownLValue().getAddress()
                               : I->getKnownRValue().getAggregateAddress();
@@ -5665,7 +5654,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         assert(RV.isScalar()); // complex should always just be direct
 
         llvm::Type *scalarType = RV.getScalarVal()->getType();
-        auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
         auto scalarAlign = CGM.getDataLayout().getPrefTypeAlign(scalarType);
 
         // Materialize to a temporary.
@@ -5674,7 +5662,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
                                     layout->getAlignment(), scalarAlign)),
                                 "tmp",
                                 /*ArraySize=*/nullptr, &AllocaAddr);
-        tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer());
+        NeedLifetimeEnd = EmitLifetimeStart(AllocaAddr.getPointer());
 
         Builder.CreateStore(RV.getScalarVal(), addr);
       }
@@ -5699,10 +5687,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       }
       assert(IRArgPos == FirstIRArg + NumIRArgs);
 
-      if (tempSize) {
-        EmitLifetimeEnd(tempSize, AllocaAddr.getPointer());
-      }
-
+      if (NeedLifetimeEnd)
+        EmitLifetimeEnd(AllocaAddr.getPointer());
       break;
     }
 
@@ -5871,9 +5857,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // can't depend on being inside of an ExprWithCleanups, so we need to manually
   // pop this cleanup later on. Being eager about this is OK, since this
   // temporary is 'invisible' outside of the callee.
-  if (UnusedReturnSizePtr)
-    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr,
-                                         UnusedReturnSizePtr);
+  if (NeedSRetLifetimeEnd)
+    pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr);
 
   llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
 
@@ -6007,7 +5992,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   // insertion point; this allows the rest of IRGen to discard
   // unreachable code.
   if (CI->doesNotReturn()) {
-    if (UnusedReturnSizePtr)
+    if (NeedSRetLifetimeEnd)
       PopCleanupBlock();
 
     // Strip away the noreturn attribute to better diagnose unreachable UB.
@@ -6122,7 +6107,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
       case ABIArgInfo::InAlloca:
       case ABIArgInfo::Indirect: {
         RValue ret = convertTempToRValue(SRetPtr, RetTy, SourceLocation());
-        if (UnusedReturnSizePtr)
+        if (NeedSRetLifetimeEnd)
           PopCleanupBlock();
         return ret;
       }
diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 0b4e3f9cb0365..3157b7f16f294 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -289,9 +289,6 @@ class CallArgList : public SmallVector<CallArg, 8> {
     /// An Expression (optional) that performs the writeback with any required
     /// casting.
     const Expr *WritebackExpr;
-
-    // Size for optional lifetime end on the temporary.
-    llvm::Value *LifetimeSz;
   };
 
   struct CallArgCleanup {
@@ -321,9 +318,8 @@ class CallArgList : public SmallVector<CallArg, 8> {
   }
 
   void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse,
-                    const Expr *writebackExpr = nullptr,
-                    llvm::Value *lifetimeSz = nullptr) {
-    Writeback writeback = {srcLV, temporary, toUse, writebackExpr, lifetimeSz};
+                    const Expr *writebackExpr = nullptr) {
+    Writeback writeback = {srcLV, temporary, toUse, writebackExpr};
     Writebacks.push_back(writeback);
   }
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 04f13c7d7a6a3..d224b09522d86 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1347,30 +1347,27 @@ void CodeGenFunction::EmitAutoVarDecl(const VarDecl &D) {
 }
 
 /// Emit a lifetime.begin marker if some criteria are satisfied.
-/// \return a pointer to the temporary size Value if a marker was emitted, null
-/// otherwise
-llvm::Value *CodeGenFunction::EmitLifetimeStart(llvm::TypeSize Size,
-                                                llvm::Value *Addr) {
+/// \return whether the marker was emitted.
+bool CodeGenFunction::EmitLifetimeStart(llvm::Value *Addr) {
   if (!ShouldEmitLifetimeMarkers)
-    return nullptr;
+    return false;
 
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::Value *SizeV = llvm::ConstantInt::get(
-      Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue());
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {SizeV, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeStartFn(), {Addr});
   C->setDoesNotThrow();
-  return SizeV;
+  return true;
 }
 
-void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
+void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Addr) {
+  if (!ShouldEmitLifetimeMarkers)
+    return;
+
   assert(Addr->getType()->getPointerAddressSpace() ==
              CGM.getDataLayout().getAllocaAddrSpace() &&
          "Pointer should be in alloca address space");
-  llvm::CallInst *C =
-      Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Size, Addr});
+  llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMLifetimeEndFn(), {Addr});
   C->setDoesNotThrow();
 }
 
@@ -1628,9 +1625,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
         // is rare.
         if (!Bypasses.IsBypassed(&D) &&
             !(!getLangOpts().CPlusPlus && hasLabelBeenSeenInCurrentScope())) {
-          llvm::TypeSize Size = CGM.getDataLayout().getTypeAllocSize(allocaTy);
-          emission.SizeForLifetimeMarkers =
-              EmitLifetimeStart(Size, AllocaAddr.getPointer());
+          emission.UseLifetimeMarkers =
+              EmitLifetimeStart(AllocaAddr.getPointer());
         }
       } else {
         assert(!emission.useLifetimeMarkers());
@@ -1723,9 +1719,8 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
 
   // Make sure we call @llvm.lifetime.end.
   if (emission.useLifetimeMarkers())
-    EHStack.pushCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                         emission.getOriginalAllocatedAddress(),
-                                         emission.getSizeForLifetimeMarkers());
+    EHStack.pushCleanup<CallLifetimeEnd>(
+        NormalEHLifetimeMarker, emission.getOriginalAllocatedAddress());
 
   // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
   // calls for local variables. We are exempting volatile variables and
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 85c768807572f..576307d707b69 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -577,11 +577,9 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
   } else {
     switch (M->getStorageDuration()) {
     case SD_Automatic:
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
+      if (EmitLifetimeStart(Alloca.getPointer())) {
         pushCleanupAfterFullExpr<CallLifetimeEnd>(NormalEHLifetimeMarker,
-                                                  Alloca, Size);
+                                                  Alloca);
       }
       break;
 
@@ -612,11 +610,8 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
             Block, llvm::BasicBlock::iterator(Block->back())));
       }
 
-      if (auto *Size = EmitLifetimeStart(
-              CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
-              Alloca.getPointer())) {
-        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca,
-                                             Size);
+      if (EmitLifetimeStart(Alloca.getPointer())) {
+        pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, Alloca);
       }
 
       if (OldConditional) {
@@ -5743,13 +5738,10 @@ LValue CodeGenFunction::EmitHLSLOutArgExpr(const HLSLOutArgExpr *E,
   llvm::Value *Addr = TempLV.getAddress().getBasePointer();
   llvm::Type *ElTy = ConvertTypeForMem(TempLV.getType());
 
-  llvm::TypeSize Sz = CGM.getDataLayout().getTypeAllocSize(ElTy);
-
-  llvm::Value *LifetimeSize = EmitLifetimeStart(Sz, Addr);
+  EmitLifetimeStart(Addr);
 
   Address TmpAddr(Addr, ElTy, TempLV.getAlignment());
-  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast(),
-                    LifetimeSize);
+  Args.addWriteback(BaseLV, TmpAddr, nullptr, E->getWritebackCast());
   Args.add(RValue::get(TmpAddr, *this), Ty);
   return TempLV;
 }
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index cad6731173700..e2f11b86b2053 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -300,16 +300,12 @@ void AggExprEmitter::withReturnValueSlot(
   Address RetAddr = Address::invalid();
 
   EHScopeStack::stable_iterator LifetimeEndBlock;
-  llvm::Value *LifetimeSizePtr = nullptr;
   llvm::IntrinsicInst *LifetimeStartInst = nullptr;
   if (!UseTemp) {
     RetAddr = Dest.getAddress();
   } else {
     RetAddr = CGF.CreateMemTempWithoutCast(RetTy, "tmp");
-    llvm::TypeSize Size =
-        CGF.CGM.getDataLayout().getTypeAllocSize(CGF.ConvertTypeForMem(RetTy));
-    LifetimeSizePtr = CGF.EmitLifetimeStart(Size, RetAddr.getBasePointer());
-    if (LifetimeSizePtr) {
+    if (CGF.EmitLifetimeStart(RetAddr.getBasePointer())) {
       LifetimeStartInst =
           cast<llvm::IntrinsicInst>(std::prev(Builder.GetInsertPoint()));
       assert(LifetimeStartInst->getIntrinsicID() ==
@@ -317,7 +313,7 @@ void AggExprEmitter::withReturnValueSlot(
              "Last insertion wasn't a lifetime.start?");
 
       CGF.pushFullExprCleanup<CodeGenFunction::CallLifetimeEnd>(
-          NormalEHLifetimeMarker, RetAddr, LifetimeSizePtr);
+          NormalEHLifetimeMarker, RetAddr);
       LifetimeEndBlock = CGF.EHStack.stable_begin();
     }
   }
@@ -338,7 +334,7 @@ void AggExprEmitter::withReturnValueSlot(
     // Since we're not guaranteed to be in an ExprWithCleanups, clean up
     // eagerly.
     CGF.DeactivateCleanupBlock(LifetimeEndBlock, LifetimeStartInst);
-    CGF.EmitLifetimeEnd(LifetimeSizePtr, RetAddr.getBasePointer());
+    CGF.EmitLifetimeEnd(RetAddr.getBasePointer());
   }
 }
 
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 6c32c98cec011..272587f7fa4b5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -701,14 +701,12 @@ class CodeGenFunction : public CodeGenTypeCache {
     bool isRedundantBeforeReturn() override { return true; }
 
     llvm::Value *Addr;
-    llvm::Value *Size;
 
   public:
-    CallLifetimeEnd(RawAddress addr, llvm::Value *size)
-        : Addr(addr.getPointer()), Size(size) {}
+    CallLifetimeEnd(RawAddress addr) : Addr(addr.getPointer()) {}
 
     void Emit(CodeGenFunction &CGF, Flags flags) override {
-      CGF.EmitLifetimeEnd(Size, Addr);
+      CGF.EmitLifetimeEnd(Addr);
     }
   };
 
@@ -3233,8 +3231,8 @@ class CodeGenFunction : public CodeGenTypeCache {
   void EmitSehTryScopeBegin();
   void EmitSehTryScopeEnd();
 
-  llvm::Value *EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr);
-  void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
+  bool EmitLifetimeStart(llvm::Value *Addr);
+  void EmitLifetimeEnd(llvm::Value *Addr);
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
@@ -3417,8 +3415,8 @@ class CodeGenFunction : public CodeGenTypeCache {
     /// initializer.
     bool IsConstantAggregate;
 
-    /// Non-null if we should use lifetime annotations.
-    llvm::Value *SizeForLifetimeMarkers;
+    /// True if lifetime markers should be used.
+    bool UseLifetimeMarkers;
 
     /// Address with original alloca instruction. Invalid if the variable was
     /// emitted as a global constant.
@@ -3432,20 +3430,14 @@ class CodeGenFunction : public CodeGenTypeCache {
     AutoVarEmission(const VarDecl &variable)
         : Variable(&variable), Addr(Address::invalid()), NRVOFlag(nullptr),
           IsEscapingByRef(false), IsConstantAggregate(false),
-          SizeForLifetimeMarkers(nullptr), AllocaAddr(RawAddress::invalid()) {}
+          UseLifetimeMarkers(false), AllocaAddr(RawAddress::invalid()) {}
 
     bool wasEmittedAsGlobal() const { return !Addr.isValid(); }
 
   public:
     static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); }
 
-    bool useLifetimeMarkers() const {
-      return SizeForLifetimeMarkers != nullptr;
-    }
-    llvm::Value *getSizeForLifetimeMarkers() const {
-      assert(useLifetimeMarkers());
-      return SizeForLifetimeMarkers;
-    }
+    bool useLifetimeMarkers() const { return UseLifetimeMarkers; }
 
     /// Returns the raw, allocated address, which is not necessarily
     /// the address of the object itself. It is casted to default
diff --git a/clang/test/C/C11/n1285_1.c b/clang/test/C/C11/n1285_1.c
index 50100042e82fd..25b68e3145b04 100644
--- a/clang/test/C/C11/n1285_1.c
+++ b/clang/test/C/C11/n1285_1.c
@@ -26,16 +26,16 @@ struct X f(void);
 ...
[truncated]

Copy link
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efriedma-quic
Copy link
Collaborator

Probably should release note, yes.

Also, can we try to land some of the changes separately? I mean, some things can't land separately, or it would be a pain in the neck to land them separately because of test changes, but we can at least merge the SelectionDAG bits and the analysis changes first, so the remaining bits are easier to review.

@nikic
Copy link
Contributor Author

nikic commented Jul 25, 2025

I've added a release note.

Also, can we try to land some of the changes separately? I mean, some things can't land separately, or it would be a pain in the neck to land them separately because of test changes, but we can at least merge the SelectionDAG bits and the analysis changes first, so the remaining bits are easier to review.

I guess I could split this up into two changes:

  1. Specify that the size passed to lifetime.start / lifetime.end is ignored, and remove some of the code trying to actually do something with it (like SDAG).
  2. Actually remove the size argument.

Then the first one should have most of the interesting bits, and the second one be mostly mechanical...

@@ -1462,6 +1462,7 @@ void HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
Value *AICast = IRB.CreatePointerCast(AI, PtrTy);

auto HandleLifetime = [&](IntrinsicInst *II) {
// FIXME: Remove this code entirely.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just submitted #150510, so we can just remove the whole thing now.

nikic added a commit to nikic/llvm-project that referenced this pull request Jul 28, 2025
Split out from llvm#150248:

Specify that the argument of lifetime.start/lifetime.end is ignored
and will be removed in the future.

Remove lifetime size handling from SDAG. The size was previously
discarded during isel, so was always ignored for stack coloring.
Where necessary, obtain the size of the full frame index.
nikic added a commit to nikic/llvm-project that referenced this pull request Jul 28, 2025
Split out from llvm#150248:

Specify that the argument of lifetime.start/lifetime.end is ignored
and will be removed in the future.

Remove lifetime size handling from SDAG. The size was previously
discarded during isel, so was always ignored for stack coloring.
Where necessary, obtain the size of the full frame index.
nikic added a commit that referenced this pull request Jul 29, 2025
Split out from #150248:

Specify that the argument of lifetime.start/lifetime.end is ignored and
will be removed in the future.

Remove lifetime size handling from SDAG. The size was previously
discarded during isel, so was always ignored for stack coloring anyway.
Where necessary, obtain the size of the full frame index.
Now that llvm#149310 has restricted lifetime intrinsics to only work
on allocas, we can also drop the explicit size argument. Instead,
the size is implied by the alloca.

This removes the ability to only mark a prefix of an alloca
alive/dead. We never used that capability, so we should remove the
need to handle that possibility everywhere (many key places, including
stack coloring, did not actually respect this).
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 29, 2025
Split out from llvm/llvm-project#150248:

Specify that the argument of lifetime.start/lifetime.end is ignored and
will be removed in the future.

Remove lifetime size handling from SDAG. The size was previously
discarded during isel, so was always ignored for stack coloring anyway.
Where necessary, obtain the size of the full frame index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 backend:AMDGPU backend:MIPS backend:NVPTX backend:PowerPC backend:RISC-V backend:SPIR-V backend:SystemZ backend:WebAssembly backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category compiler-rt:sanitizer coroutines C++20 coroutines flang:fir-hlfir flang Flang issues not falling into any other category llvm:analysis Includes value tracking, cost tables and constant folding llvm:codegen llvm:globalisel llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:ir llvm:SelectionDAG SelectionDAGISel as well llvm:transforms mlir:llvm mlir PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants