Skip to content

[NewGVN] Check intrinsic ID before accessing operands #141571

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions llvm/lib/Transforms/Scalar/NewGVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,11 +1530,12 @@ NewGVN::performSymbolicLoadCoercion(Type *LoadType, Value *LoadPtr,
}

if (auto *II = dyn_cast<IntrinsicInst>(DepInst)) {
auto *LifetimePtr = II->getOperand(1);
if (II->getIntrinsicID() == Intrinsic::lifetime_start &&
(LoadPtr == lookupOperandLeader(LifetimePtr) ||
AA->isMustAlias(LoadPtr, LifetimePtr)))
return createConstantExpression(UndefValue::get(LoadType));
if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
auto *LifetimePtr = II->getOperand(1);
if (LoadPtr == lookupOperandLeader(LifetimePtr) ||
AA->isMustAlias(LoadPtr, LifetimePtr))
return createConstantExpression(UndefValue::get(LoadType));
}
}

// All of the below are only true if the loaded pointer is produced
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/Transforms/NewGVN/s-barrier-compile-issue.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=newgvn < %s | FileCheck %s

; Test created to verify compilation without crashing.

@mem = addrspace(3) global i32 poison, align 4

define i32 @foo() {
; CHECK-LABEL: define i32 @foo() {
; CHECK-NEXT: call void @llvm.amdgcn.s.barrier()
; CHECK-NEXT: [[OUT:%.*]] = load i32, ptr addrspace(3) @mem, align 4
; CHECK-NEXT: ret i32 [[OUT]]
;
call void @llvm.amdgcn.s.barrier()
%out = load i32, ptr addrspace(3) @mem, align 4
ret i32 %out
}