Skip to content

Commit c0cabfb

Browse files
authored
[InstCombiner] Remove trivially dead llvm.allow.{runtime,ubsan}.check() (#84851)
Intrinsic declared to have sideeffects, but it's done only to prevent moving it. Removing unused ones is OK. Exacted from #84850 for easier review.
1 parent 8b135a7 commit c0cabfb

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ bool llvm::wouldInstructionBeTriviallyDead(const Instruction *I,
475475
II->getIntrinsicID() == Intrinsic::launder_invariant_group)
476476
return true;
477477

478+
// Intrinsics declare sideeffects to prevent them from moving, but they are
479+
// nops without users.
480+
if (II->getIntrinsicID() == Intrinsic::allow_runtime_check ||
481+
II->getIntrinsicID() == Intrinsic::allow_ubsan_check)
482+
return true;
483+
478484
if (II->isLifetimeStartOrEnd()) {
479485
auto *Arg = II->getArgOperand(1);
480486
// Lifetime intrinsics are dead when their right-hand is undef.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=instcombine -S | FileCheck %s --implicit-check-not="call i1 @llvm.allow"
3+
4+
define i1 @test_runtime() {
5+
; CHECK-LABEL: @test_runtime(
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[HOT:%.*]] = call i1 @llvm.allow.runtime.check(metadata !"test")
8+
; CHECK-NEXT: ret i1 [[HOT]]
9+
;
10+
entry:
11+
%allow = call i1 @llvm.allow.runtime.check(metadata !"test")
12+
ret i1 %allow
13+
}
14+
15+
define void @test_runtime_void() {
16+
; CHECK-LABEL: @test_runtime_void(
17+
; CHECK-NEXT: entry:
18+
; CHECK-NEXT: ret void
19+
;
20+
entry:
21+
%allow = call i1 @llvm.allow.runtime.check(metadata !"test")
22+
ret void
23+
}
24+
25+
define i1 @test_ubsan() {
26+
; CHECK-LABEL: @test_ubsan(
27+
; CHECK-NEXT: entry:
28+
; CHECK-NEXT: [[HOT:%.*]] = call i1 @llvm.allow.ubsan.check(i8 11)
29+
; CHECK-NEXT: ret i1 [[HOT]]
30+
;
31+
entry:
32+
%allow = call i1 @llvm.allow.ubsan.check(i8 11)
33+
ret i1 %allow
34+
}
35+
36+
define void @test_ubsan_void() {
37+
; CHECK-LABEL: @test_ubsan_void(
38+
; CHECK-NEXT: entry:
39+
; CHECK-NEXT: ret void
40+
;
41+
entry:
42+
%allow = call i1 @llvm.allow.ubsan.check(i8 11)
43+
ret void
44+
}

0 commit comments

Comments
 (0)