Skip to content

[InstCombiner] Remove trivially dead llvm.allow.{runtime,ubsan}.check() #84851

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
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
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ bool llvm::wouldInstructionBeTriviallyDead(const Instruction *I,
II->getIntrinsicID() == Intrinsic::launder_invariant_group)
return true;

// Intrinsics declare sideeffects to prevent them from moving, but they are
// nops without users.
if (II->getIntrinsicID() == Intrinsic::allow_runtime_check ||
II->getIntrinsicID() == Intrinsic::allow_ubsan_check)
return true;

if (II->isLifetimeStartOrEnd()) {
auto *Arg = II->getArgOperand(1);
// Lifetime intrinsics are dead when their right-hand is undef.
Expand Down
44 changes: 44 additions & 0 deletions llvm/test/Transforms/InstCombine/allow-checks.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s --implicit-check-not="call i1 @llvm.allow"

define i1 @test_runtime() {
; CHECK-LABEL: @test_runtime(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[HOT:%.*]] = call i1 @llvm.allow.runtime.check(metadata !"test")
; CHECK-NEXT: ret i1 [[HOT]]
;
entry:
%allow = call i1 @llvm.allow.runtime.check(metadata !"test")
ret i1 %allow
}

define void @test_runtime_void() {
; CHECK-LABEL: @test_runtime_void(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret void
;
entry:
%allow = call i1 @llvm.allow.runtime.check(metadata !"test")
ret void
}

define i1 @test_ubsan() {
; CHECK-LABEL: @test_ubsan(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[HOT:%.*]] = call i1 @llvm.allow.ubsan.check(i8 11)
; CHECK-NEXT: ret i1 [[HOT]]
;
entry:
%allow = call i1 @llvm.allow.ubsan.check(i8 11)
ret i1 %allow
}

define void @test_ubsan_void() {
; CHECK-LABEL: @test_ubsan_void(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret void
;
entry:
%allow = call i1 @llvm.allow.ubsan.check(i8 11)
ret void
}