[llvm] 7bc88cb - [OpenMP] Simplify `llvm.assume` operands in device code
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 22 01:28:33 PST 2023
Author: Johannes Doerfert
Date: 2023-01-22T01:27:41-08:00
New Revision: 7bc88cbe5c0365bba0873ed896a435e57402a5e0
URL: https://github.com/llvm/llvm-project/commit/7bc88cbe5c0365bba0873ed896a435e57402a5e0
DIFF: https://github.com/llvm/llvm-project/commit/7bc88cbe5c0365bba0873ed896a435e57402a5e0.diff
LOG: [OpenMP] Simplify `llvm.assume` operands in device code
Added:
Modified:
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 89723a3d6c0df..12202dd5335ce 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -4899,8 +4899,18 @@ void OpenMPOpt::registerAAsForFunction(Attributor &A, const Function &F) {
bool UsedAssumedInformation = false;
A.getAssumedSimplified(IRPosition::value(*LI), /* AA */ nullptr,
UsedAssumedInformation, AA::Interprocedural);
- } else if (auto *SI = dyn_cast<StoreInst>(&I)) {
+ continue;
+ }
+ if (auto *SI = dyn_cast<StoreInst>(&I)) {
A.getOrCreateAAFor<AAIsDead>(IRPosition::value(*SI));
+ continue;
+ }
+ if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
+ if (II->getIntrinsicID() == Intrinsic::assume) {
+ A.getOrCreateAAFor<AAPotentialValues>(
+ IRPosition::value(*II->getArgOperand(0)));
+ continue;
+ }
}
}
}
diff --git a/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll b/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
index 7a45eb5e8be01..5bc6704ffc67e 100644
--- a/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
+++ b/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
@@ -7,10 +7,16 @@ target triple = "amdgcn-amd-amdhsa"
%struct.ident_t = type { i32, i32, i32, i32, ptr }
@G = internal addrspace(3) global i32 undef, align 4
+ at str = private unnamed_addr addrspace(4) constant [1 x i8] c"\00", align 1
; Make sure we do not delete the stores to @G without also replacing the load with `1`.
;.
-; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal addrspace(3) global i32 undef, align 4
+; TUNIT: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal addrspace(3) global i32 undef, align 4
+; TUNIT: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr addrspace(4) constant [1 x i8] zeroinitializer, align 1
+; TUNIT: @[[KERNEL_NESTED_PARALLELISM:[a-zA-Z0-9_$"\\.-]+]] = weak constant i8 0
+;.
+; CGSCC: @[[G:[a-zA-Z0-9_$"\\.-]+]] = internal addrspace(3) global i32 undef, align 4
+; CGSCC: @[[STR:[a-zA-Z0-9_$"\\.-]+]] = private unnamed_addr addrspace(4) constant [1 x i8] zeroinitializer, align 1
;.
define void @kernel() "kernel" {
; TUNIT: Function Attrs: norecurse
@@ -23,15 +29,15 @@ define void @kernel() "kernel" {
; TUNIT-NEXT: store i32 1, ptr addrspace(3) @G, align 4
; TUNIT-NEXT: br label [[IF_MERGE:%.*]]
; TUNIT: if.else:
-; TUNIT-NEXT: call void @barrier() #[[ATTR4:[0-9]+]]
+; TUNIT-NEXT: call void @barrier() #[[ATTR5:[0-9]+]]
; TUNIT-NEXT: [[L:%.*]] = load i32, ptr addrspace(3) @G, align 4
-; TUNIT-NEXT: call void @use1(i32 [[L]]) #[[ATTR4]]
+; TUNIT-NEXT: call void @use1(i32 [[L]]) #[[ATTR5]]
; TUNIT-NEXT: br label [[IF_MERGE]]
; TUNIT: if.merge:
; TUNIT-NEXT: br i1 [[CMP]], label [[IF_THEN2:%.*]], label [[IF_END:%.*]]
; TUNIT: if.then2:
; TUNIT-NEXT: store i32 2, ptr addrspace(3) @G, align 4
-; TUNIT-NEXT: call void @barrier() #[[ATTR4]]
+; TUNIT-NEXT: call void @barrier() #[[ATTR5]]
; TUNIT-NEXT: br label [[IF_END]]
; TUNIT: if.end:
; TUNIT-NEXT: call void @__kmpc_target_deinit(ptr undef, i8 1)
@@ -83,10 +89,20 @@ if.end:
ret void
}
+define void @test_assume() {
+; CHECK-LABEL: define {{[^@]+}}@test_assume() {
+; CHECK-NEXT: call void @llvm.assume(i1 true)
+; CHECK-NEXT: ret void
+;
+ call void @llvm.assume(i1 icmp ne (ptr addrspacecast (ptr addrspace(4) @str to ptr), ptr null))
+ ret void
+}
+
declare void @barrier() norecurse nounwind nocallback
declare void @use1(i32) nosync norecurse nounwind nocallback
declare i32 @__kmpc_target_init(ptr, i8, i1) nocallback
declare void @__kmpc_target_deinit(ptr, i8) nocallback
+declare void @llvm.assume(i1)
!llvm.module.flags = !{!0, !1}
!nvvm.annotations = !{!2}
@@ -100,16 +116,16 @@ declare void @__kmpc_target_deinit(ptr, i8) nocallback
; TUNIT: attributes #[[ATTR1:[0-9]+]] = { nocallback norecurse nounwind }
; TUNIT: attributes #[[ATTR2:[0-9]+]] = { nocallback norecurse nosync nounwind }
; TUNIT: attributes #[[ATTR3:[0-9]+]] = { nocallback }
-; TUNIT: attributes #[[ATTR4]] = { nounwind }
+; TUNIT: attributes #[[ATTR4:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
+; TUNIT: attributes #[[ATTR5]] = { nounwind }
;.
; CGSCC: attributes #[[ATTR0]] = { norecurse "kernel" }
; CGSCC: attributes #[[ATTR1:[0-9]+]] = { nocallback norecurse nounwind }
; CGSCC: attributes #[[ATTR2:[0-9]+]] = { nocallback norecurse nosync nounwind }
; CGSCC: attributes #[[ATTR3:[0-9]+]] = { nocallback }
+; CGSCC: attributes #[[ATTR4:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
;.
; CHECK: [[META0:![0-9]+]] = !{i32 7, !"openmp", i32 50}
; CHECK: [[META1:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
; CHECK: [[META2:![0-9]+]] = !{ptr @kernel, !"kernel", i32 1}
;.
-;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
-; CHECK: {{.*}}
More information about the llvm-commits
mailing list