Skip to content

Commit b4bb2f8

Browse files
authored
[LoopDeletion] Unblock loop deletion with llvm.experimental.noalias.scope.decl (#108144)
Since `llvm.experimental.noalias.scope.decl` is marked as `memory(inaccessiblemem: readwrite)`, we cannot treat this annotation intrinsic as having no side effects. It will block loop deletion when this intrinsic exists inside a dead loop: https://github.com/llvm/llvm-project/blob/3dad29b677e427bf69c035605a16efd065576829/llvm/lib/Transforms/Scalar/LoopDeletion.cpp#L103-L110 This patch marks `llvm.experimental.noalias.scope.decl` as droppable to address the issue. Fixes #108052.
1 parent 3001617 commit b4bb2f8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

llvm/lib/IR/User.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,17 @@ MutableArrayRef<uint8_t> User::getDescriptor() {
113113
}
114114

115115
bool User::isDroppable() const {
116-
return isa<AssumeInst>(this) || isa<PseudoProbeInst>(this);
116+
if (auto *II = dyn_cast<IntrinsicInst>(this)) {
117+
switch (II->getIntrinsicID()) {
118+
default:
119+
return false;
120+
case Intrinsic::assume:
121+
case Intrinsic::pseudoprobe:
122+
case Intrinsic::experimental_noalias_scope_decl:
123+
return true;
124+
}
125+
}
126+
return false;
117127
}
118128

119129
//===----------------------------------------------------------------------===//
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=loop-deletion -S | FileCheck %s
3+
4+
define void @pr108052(i64 %n) {
5+
; CHECK-LABEL: define void @pr108052(
6+
; CHECK-SAME: i64 [[N:%.*]]) {
7+
; CHECK-NEXT: [[ENTRY:.*:]]
8+
; CHECK-NEXT: br label %[[FOR_EXIT:.*]]
9+
; CHECK: [[FOR_EXIT]]:
10+
; CHECK-NEXT: ret void
11+
;
12+
entry:
13+
br label %for.body
14+
15+
for.exit:
16+
ret void
17+
18+
for.body:
19+
%indvar = phi i64 [ 0, %entry ], [ %inc, %for.body ]
20+
call void @llvm.experimental.noalias.scope.decl(metadata !0)
21+
%inc = add nuw i64 %indvar, 1
22+
%exitcond.not = icmp eq i64 %inc, %n
23+
br i1 %exitcond.not, label %for.exit, label %for.body
24+
}
25+
26+
!0 = !{!1}
27+
!1 = distinct !{!1, !2, !"x: %a"}
28+
!2 = distinct !{!2, !"x"}

0 commit comments

Comments
 (0)