[llvm] 6fa8244 - [IR] Mark `llvm.trap` as `memory(inaccessiblemem: write)`
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 31 13:45:35 PDT 2023
Author: Johannes Doerfert
Date: 2023-07-31T13:44:52-07:00
New Revision: 6fa8244eb6cc4d2a079c347f7c44d842fc83a913
URL: https://github.com/llvm/llvm-project/commit/6fa8244eb6cc4d2a079c347f7c44d842fc83a913
DIFF: https://github.com/llvm/llvm-project/commit/6fa8244eb6cc4d2a079c347f7c44d842fc83a913.diff
LOG: [IR] Mark `llvm.trap` as `memory(inaccessiblemem: write)`
Traps will not read/write the program state but they need an effect for
preservation, similar to `llvm.assume`. We really want a new memory kind
for that (see TODO), but for now `inaccessiblemem: write` is better than
any possible effect.
Differential Revision: https://reviews.llvm.org/D156476
Added:
Modified:
llvm/include/llvm/IR/Intrinsics.td
llvm/test/Feature/intrinsics.ll
llvm/test/Transforms/Attributor/cgscc_bugs.ll
llvm/test/Transforms/LowerGlobalDestructors/non-literal-type.ll
llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.expected
llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index e51c04fbad2f42..2c9cdf49f44e3c 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1670,8 +1670,10 @@ def int_coro_subfn_addr : DefaultAttrsIntrinsic<
///===-------------------------- Other Intrinsics --------------------------===//
//
-def int_trap : Intrinsic<[], [], [IntrNoReturn, IntrCold]>,
- ClangBuiltin<"__builtin_trap">;
+// TODO: We should introduce a new memory kind fo traps (and other side effects
+// we only model to keep things alive).
+def int_trap : Intrinsic<[], [], [IntrNoReturn, IntrCold, IntrInaccessibleMemOnly,
+ IntrWriteMem]>, ClangBuiltin<"__builtin_trap">;
def int_debugtrap : Intrinsic<[]>,
ClangBuiltin<"__builtin_debugtrap">;
def int_ubsantrap : Intrinsic<[], [llvm_i8_ty],
diff --git a/llvm/test/Feature/intrinsics.ll b/llvm/test/Feature/intrinsics.ll
index bd2c469395ae3e..49fed0981bd766 100644
--- a/llvm/test/Feature/intrinsics.ll
+++ b/llvm/test/Feature/intrinsics.ll
@@ -70,4 +70,4 @@ define void @trap() {
}
; CHECK: attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
-; CHECK: attributes #1 = { cold noreturn nounwind }
+; CHECK: attributes #1 = { cold noreturn nounwind memory(inaccessiblemem: write) }
diff --git a/llvm/test/Transforms/Attributor/cgscc_bugs.ll b/llvm/test/Transforms/Attributor/cgscc_bugs.ll
index 368be59c200c26..c2cb458c0ecba8 100644
--- a/llvm/test/Transforms/Attributor/cgscc_bugs.ll
+++ b/llvm/test/Transforms/Attributor/cgscc_bugs.ll
@@ -23,7 +23,7 @@ define linkonce_odr hidden { ptr, i64 } @f3(i64 %0) align 2 {
; CHECK-SAME: (i64 [[TMP0:%.*]]) align 2 {
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @f4()
; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64
-; CHECK-NEXT: call void @f5(i64 [[TMP3]], i64 [[TMP0]]) #[[ATTR0:[0-9]+]]
+; CHECK-NEXT: call void @f5(i64 [[TMP3]], i64 [[TMP0]]) #[[ATTR2:[0-9]+]]
; CHECK-NEXT: ret { ptr, i64 } undef
;
%2 = call i32 @f4()
@@ -40,18 +40,18 @@ define linkonce_odr hidden i32 @f4() align 2 {
}
define internal void @f5(i64 %0, i64 %1) {
-; CHECK: Function Attrs: nounwind
+; CHECK: Function Attrs: nounwind memory(inaccessiblemem: write)
; CHECK-LABEL: define {{[^@]+}}@f5
-; CHECK-SAME: (i64 [[TMP0:%.*]], i64 [[TMP1:%.*]]) #[[ATTR0]] {
+; CHECK-SAME: (i64 [[TMP0:%.*]], i64 [[TMP1:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: br label [[TMP3:%.*]]
; CHECK: 3:
-; CHECK-NEXT: call void @f6(i64 [[TMP0]]) #[[ATTR0]]
+; CHECK-NEXT: call void @f6(i64 [[TMP0]]) #[[ATTR2]]
; CHECK-NEXT: [[TMP4:%.*]] = icmp sgt i64 [[TMP1]], [[TMP0]]
; CHECK-NEXT: br i1 [[TMP4]], label [[TMP5:%.*]], label [[TMP6:%.*]]
; CHECK: 5:
; CHECK-NEXT: ret void
; CHECK: 6:
-; CHECK-NEXT: call void @f5(i64 [[TMP0]], i64 [[TMP1]]) #[[ATTR0]]
+; CHECK-NEXT: call void @f5(i64 [[TMP0]], i64 [[TMP1]]) #[[ATTR2]]
; CHECK-NEXT: br label [[TMP3]]
;
br label %3
@@ -70,13 +70,13 @@ define internal void @f5(i64 %0, i64 %1) {
}
define internal void @f6(i64 %0) {
-; CHECK: Function Attrs: nounwind
+; CHECK: Function Attrs: nounwind memory(inaccessiblemem: write)
; CHECK-LABEL: define {{[^@]+}}@f6
; CHECK-SAME: (i64 [[TMP0:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i64 [[TMP0]], 0
; CHECK-NEXT: br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP4:%.*]]
; CHECK: 3:
-; CHECK-NEXT: call void @llvm.trap() #[[ATTR2:[0-9]+]]
+; CHECK-NEXT: call void @llvm.trap() #[[ATTR3:[0-9]+]]
; CHECK-NEXT: unreachable
; CHECK: 4:
; CHECK-NEXT: ret void
@@ -98,9 +98,10 @@ declare void @llvm.trap() #0
attributes #0 = { cold noreturn nounwind }
;.
-; CHECK: attributes #[[ATTR0]] = { nounwind }
-; CHECK: attributes #[[ATTR1:[0-9]+]] = { cold noreturn nounwind }
-; CHECK: attributes #[[ATTR2]] = { noreturn }
+; CHECK: attributes #[[ATTR0]] = { nounwind memory(inaccessiblemem: write) }
+; CHECK: attributes #[[ATTR1:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
+; CHECK: attributes #[[ATTR2]] = { nounwind memory(write) }
+; CHECK: attributes #[[ATTR3]] = { noreturn memory(write) }
;.
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CGSCC: {{.*}}
diff --git a/llvm/test/Transforms/LowerGlobalDestructors/non-literal-type.ll b/llvm/test/Transforms/LowerGlobalDestructors/non-literal-type.ll
index 38f72e7ac70e50..c7fb6266cf96a8 100644
--- a/llvm/test/Transforms/LowerGlobalDestructors/non-literal-type.ll
+++ b/llvm/test/Transforms/LowerGlobalDestructors/non-literal-type.ll
@@ -32,5 +32,5 @@ declare void @dtor()
; CHECK-NEXT: ret void
;
;.
-; CHECK: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind }
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
;.
diff --git a/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll b/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll
index c48fbb512276f5..e8b58639c13dde 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-on-const-select.ll
@@ -158,4 +158,4 @@ declare void @llvm.trap() nounwind noreturn
declare void @bees.a() nounwind
declare void @bees.b() nounwind
-; CHECK: attributes #1 = { cold noreturn nounwind }
+; CHECK: attributes #1 = { cold noreturn nounwind memory(inaccessiblemem: write) }
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll
index 0f0322873a2754..37017857ae5abd 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll
@@ -32,5 +32,5 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected
index 905a79fdff4055..02d8870c61365c 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.expected
@@ -33,7 +33,7 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
; CHECK-LABEL: @foo(
; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP0:%.*]], 0
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
index 1fee1aa8dfc582..3b86c36fd39f5d 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.generated.globals.expected
@@ -33,7 +33,7 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
;.
; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = external dso_local global i32, align 4
@@ -78,7 +78,7 @@ declare void @_Z10sideeffectv()
; CHECK-NEXT: unreachable
;
;.
-; CHECK: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind }
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
; CHECK: attributes #[[ATTR1:[0-9]+]] = { cold minsize noreturn }
; CHECK: attributes #[[ATTR2]] = { noinline }
;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
index 37e98df641aecc..36bcbe32e03634 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.expected
@@ -53,5 +53,5 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
index 417fe2ac5cb4c9..30e1a683aac98a 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs.ll.nogenerated.globals.expected
@@ -56,10 +56,10 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
;.
-; CHECK: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind }
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
; CHECK: attributes #[[ATTR1:[0-9]+]] = { cold minsize noreturn }
; CHECK: attributes #[[ATTR2]] = { noinline }
;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll
index ada0603ca8c08e..eee7f9291ceefb 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll
@@ -33,5 +33,5 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.expected
index e37caf215c45eb..10399951e7fbcd 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.expected
@@ -34,7 +34,7 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
; REUSE-LABEL: @foo(
; REUSE-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP0:%.*]], 0
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
index 7bc04792948805..e6698db5fbee8d 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.generated.globals.expected
@@ -34,7 +34,7 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
;.
; REUSE: @[[G:[a-zA-Z0-9_$"\\.-]+]] = external dso_local global i32, align 4
@@ -79,7 +79,7 @@ declare void @_Z10sideeffectv()
; REUSE-NEXT: unreachable
;
;.
-; REUSE: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind }
+; REUSE: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
; REUSE: attributes #[[ATTR1:[0-9]+]] = { cold minsize noreturn }
; REUSE: attributes #[[ATTR2]] = { noinline }
;.
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.expected
index 50dbb8324acc61..e05a57d06413b9 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.expected
@@ -54,5 +54,5 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
diff --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
index 0049c2ab6149f8..87f588d1de6400 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/generated_funcs_prefix_reuse.ll.nogenerated.globals.expected
@@ -57,10 +57,10 @@ exit:
ret void
}
-declare void @llvm.trap() noreturn cold
+declare void @llvm.trap() noreturn cold memory(inaccessiblemem: write)
declare void @_Z10sideeffectv()
;.
-; REUSE: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind }
+; REUSE: attributes #[[ATTR0:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
; REUSE: attributes #[[ATTR1:[0-9]+]] = { cold minsize noreturn }
; REUSE: attributes #[[ATTR2]] = { noinline }
;.
More information about the llvm-commits
mailing list