Skip to content

Commit ab323eb

Browse files
committed
[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 llvm/llvm-project#153013.
1 parent 52f7cfb commit ab323eb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/Transforms/Utils/PredicateInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ void PredicateInfoBuilder::convertUsesToDFSOrdered(
291291
Value *Op, SmallVectorImpl<ValueDFS> &DFSOrderedSet) {
292292
for (auto &U : Op->uses()) {
293293
if (auto *I = dyn_cast<Instruction>(U.getUser())) {
294+
// Lifetime intrinsics must work directly on alloca, do not replace them
295+
// with a predicated copy.
296+
if (I->isLifetimeStartOrEnd())
297+
continue;
298+
294299
ValueDFS VD;
295300
// Put the phi node uses in the incoming block.
296301
BasicBlock *IBlock;

llvm/test/Transforms/SCCP/lifetime.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -passes=ipsccp < %s | FileCheck %s
3+
4+
define void @test() {
5+
; CHECK-LABEL: define void @test() {
6+
; CHECK-NEXT: [[A:%.*]] = alloca [4 x i16], align 2
7+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[A]], inttoptr (i64 -1 to ptr)
8+
; CHECK-NEXT: br i1 [[CMP]], label %[[IF:.*]], label %[[EXIT:.*]]
9+
; CHECK: [[IF]]:
10+
; CHECK-NEXT: call void @llvm.lifetime.start.p0(ptr [[A]])
11+
; CHECK-NEXT: br label %[[EXIT]]
12+
; CHECK: [[EXIT]]:
13+
; CHECK-NEXT: ret void
14+
;
15+
%a = alloca [4 x i16]
16+
%cmp = icmp eq ptr %a, inttoptr (i64 -1 to ptr)
17+
br i1 %cmp, label %if, label %exit
18+
19+
if:
20+
call void @llvm.lifetime.start.p0(ptr %a)
21+
br label %exit
22+
23+
exit:
24+
ret void
25+
}

0 commit comments

Comments
 (0)