diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -17607,11 +17607,16 @@ // TODO: Can relax for unordered atomics (see D66309) if (!ST->isSimple() || ST->isIndexed()) continue; + const TypeSize StoreSize = ST->getMemoryVT().getStoreSize(); + // The bounds of a scalable store are not known until runtime, so this + // store cannot be elided. + if (StoreSize.isScalable()) + continue; const BaseIndexOffset StoreBase = BaseIndexOffset::match(ST, DAG); // If we store purely within object bounds just before its lifetime ends, // we can remove the store. if (LifetimeEndBase.contains(DAG, LifetimeEnd->getSize() * 8, StoreBase, - ST->getMemoryVT().getStoreSizeInBits())) { + StoreSize.getFixedSize() * 8)) { LLVM_DEBUG(dbgs() << "\nRemoving store:"; StoreBase.dump(); dbgs() << "\nwithin LIFETIME_END of : "; LifetimeEndBase.dump(); dbgs() << "\n"); diff --git a/llvm/test/CodeGen/AArch64/dag-combine-lifetime-end-store-typesize.ll b/llvm/test/CodeGen/AArch64/dag-combine-lifetime-end-store-typesize.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AArch64/dag-combine-lifetime-end-store-typesize.ll @@ -0,0 +1,21 @@ +; RUN: llc -mtriple=aarch64-- < %s 2>&1 | FileCheck --allow-empty %s + +; This regression test is defending against a TypeSize warning 'assumption that TypeSize is not +; scalable'. This warning appeared in DAGCombiner::visitLIFETIME_END when visiting a LIFETIME_END +; node linked to a scalable store. + +; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it. +; CHECK-NOT: warning: {{.*}}TypeSize is not scalable + +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) + +define void @foo(* nocapture dereferenceable(16) %ptr) { +entry: + %tmp = alloca , align 8 + %tmp_ptr = bitcast * %tmp to i8* + call void @llvm.lifetime.start.p0i8(i64 32, i8* %tmp_ptr) + store undef, * %ptr + call void @llvm.lifetime.end.p0i8(i64 32, i8* %tmp_ptr) + ret void +}