[llvm] ab323eb - [SCCP][PredicateInfo] Do not predicate argument of lifetime intrinsic
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 12 03:56:25 PDT 2025
Author: Nikita Popov
Date: 2025-08-12T12:56:08+02:00
New Revision: ab323eb0c6b2ed8814c4516d4bce179d55372a5a
URL: https://github.com/llvm/llvm-project/commit/ab323eb0c6b2ed8814c4516d4bce179d55372a5a
DIFF: https://github.com/llvm/llvm-project/commit/ab323eb0c6b2ed8814c4516d4bce179d55372a5a.diff
LOG: [SCCP][PredicateInfo] Do not predicate argument of lifetime intrinsic
Replacing the argument with a no-op bitcast violates a verifier
constraint, even if only temporarily. Any replacement based on it
would result in a violation even after the copy has been removed.
Fixes https://github.com/llvm/llvm-project/issues/153013.
Added:
llvm/test/Transforms/SCCP/lifetime.ll
Modified:
llvm/lib/Transforms/Utils/PredicateInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
index 38a312a3715c9..13c7ad2927d1c 100644
--- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp
+++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
@@ -291,6 +291,11 @@ void PredicateInfoBuilder::convertUsesToDFSOrdered(
Value *Op, SmallVectorImpl<ValueDFS> &DFSOrderedSet) {
for (auto &U : Op->uses()) {
if (auto *I = dyn_cast<Instruction>(U.getUser())) {
+ // Lifetime intrinsics must work directly on alloca, do not replace them
+ // with a predicated copy.
+ if (I->isLifetimeStartOrEnd())
+ continue;
+
ValueDFS VD;
// Put the phi node uses in the incoming block.
BasicBlock *IBlock;
diff --git a/llvm/test/Transforms/SCCP/lifetime.ll b/llvm/test/Transforms/SCCP/lifetime.ll
new file mode 100644
index 0000000000000..2956157725c5f
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/lifetime.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=ipsccp < %s | FileCheck %s
+
+define void @test() {
+; CHECK-LABEL: define void @test() {
+; CHECK-NEXT: [[A:%.*]] = alloca [4 x i16], align 2
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[A]], inttoptr (i64 -1 to ptr)
+; CHECK-NEXT: br i1 [[CMP]], label %[[IF:.*]], label %[[EXIT:.*]]
+; CHECK: [[IF]]:
+; CHECK-NEXT: call void @llvm.lifetime.start.p0(ptr [[A]])
+; CHECK-NEXT: br label %[[EXIT]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret void
+;
+ %a = alloca [4 x i16]
+ %cmp = icmp eq ptr %a, inttoptr (i64 -1 to ptr)
+ br i1 %cmp, label %if, label %exit
+
+if:
+ call void @llvm.lifetime.start.p0(ptr %a)
+ br label %exit
+
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list