Skip to content

Commit 33be70a

Browse files
[NewGVN] Check intrinsic ID before accessing operands (llvm#141571)
This patch is fixing assertions in downstream tests
1 parent a227b26 commit 33be70a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,11 +1530,12 @@ NewGVN::performSymbolicLoadCoercion(Type *LoadType, Value *LoadPtr,
15301530
}
15311531

15321532
if (auto *II = dyn_cast<IntrinsicInst>(DepInst)) {
1533-
auto *LifetimePtr = II->getOperand(1);
1534-
if (II->getIntrinsicID() == Intrinsic::lifetime_start &&
1535-
(LoadPtr == lookupOperandLeader(LifetimePtr) ||
1536-
AA->isMustAlias(LoadPtr, LifetimePtr)))
1537-
return createConstantExpression(UndefValue::get(LoadType));
1533+
if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
1534+
auto *LifetimePtr = II->getOperand(1);
1535+
if (LoadPtr == lookupOperandLeader(LifetimePtr) ||
1536+
AA->isMustAlias(LoadPtr, LifetimePtr))
1537+
return createConstantExpression(UndefValue::get(LoadType));
1538+
}
15381539
}
15391540

15401541
// All of the below are only true if the loaded pointer is produced
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -passes=newgvn < %s | FileCheck %s
3+
4+
; Test created to verify compilation without crashing.
5+
6+
@mem = addrspace(3) global i32 poison, align 4
7+
8+
define i32 @foo() {
9+
; CHECK-LABEL: define i32 @foo() {
10+
; CHECK-NEXT: call void @llvm.amdgcn.s.barrier()
11+
; CHECK-NEXT: [[OUT:%.*]] = load i32, ptr addrspace(3) @mem, align 4
12+
; CHECK-NEXT: ret i32 [[OUT]]
13+
;
14+
call void @llvm.amdgcn.s.barrier()
15+
%out = load i32, ptr addrspace(3) @mem, align 4
16+
ret i32 %out
17+
}

0 commit comments

Comments
 (0)